Magnolia CMS and Rails

50
®

description

Reusing website content in Web or mobile applications is a common developer challenge. Join this webinar to find out how to integrate Magnolia CMS with external frameworks using an HTTP API and create new content-driven applications. This webinar will be most useful to CMS and Rails developers as well as system integrators. Join us with special guest presenters Patrik Metzmacher and Daniel Trierweiler from German digital advertising agency, Dievision. Find out how to use Magnolia CMS content in third-party applications while still preserving Magnolia's WYSIWYG editing experience for content authors. It will demonstrate how to create a custom API to access Magnolia CMS content from a Rails project, and highlight common challenges and best practices for the integration.

Transcript of Magnolia CMS and Rails

Page 1: Magnolia CMS and Rails

®

Page 2: Magnolia CMS and Rails

@MAGNOLIA_CMS 2

Magnolia and Rails

Patrik Metzmacher, Daniel Trierweiler, Dievision GmbH

Page 3: Magnolia CMS and Rails

@MAGNOLIA_CMS 3

Who we are

Page 4: Magnolia CMS and Rails
Page 5: Magnolia CMS and Rails

We build web-based software

Page 6: Magnolia CMS and Rails

@MAGNOLIA_CMS 6

The Problem

Page 7: Magnolia CMS and Rails

@MAGNOLIA_CMS 7

We need to provide a first-class CMS to our clients.

We want to have freedom in the choice of our application

development environment.

Page 8: Magnolia CMS and Rails

@MAGNOLIA_CMS 8

Page 9: Magnolia CMS and Rails

@MAGNOLIA_CMS 9

Your Framework of Choice

Page 10: Magnolia CMS and Rails

@MAGNOLIA_CMS 10

Who are you?

Page 11: Magnolia CMS and Rails

@MAGNOLIA_CMS 11

Agenda

Page 12: Magnolia CMS and Rails

@MAGNOLIA_CMS 12

The Problem:Using Content in an(y) Application

The Solution, Magnolia Part:REST Server and UI Integration

The Solution, (Rails-) Application Part:

REST Client and Application Integration

Page 13: Magnolia CMS and Rails

@MAGNOLIA_CMS 13

Sinicumgithub.com/dievision/

sinicum

Page 14: Magnolia CMS and Rails

@MAGNOLIA_CMS 14

Just another Magnolia CMS

integration

Page 15: Magnolia CMS and Rails

@MAGNOLIA_CMS 15

Integrates with a different process

All content-related work should be done within Magnolia CMS

(Almost) all development should take place outside of Magnolia

CMS

Page 16: Magnolia CMS and Rails

@MAGNOLIA_CMS 16

“Content as a Service”

Page 17: Magnolia CMS and Rails

@MAGNOLIA_CMS 17

Page 18: Magnolia CMS and Rails

@MAGNOLIA_CMS 18

Page 19: Magnolia CMS and Rails

@MAGNOLIA_CMS 19

Page 20: Magnolia CMS and Rails

@MAGNOLIA_CMS 20

Use Case Example

Use content in an external application

Add content to a web shop

Provide a consistent content creation experience among multiple websites

Add content to a web shop

Develop application-driven and content-driven sites in a consistent way

Same tech stack and increased efficiency for a dev team over multiple projects

Decouple components ofan application –e.g. to gain development and deployment flexibility

Mobile application that re-uses existing content in a different way

Page 21: Magnolia CMS and Rails

@MAGNOLIA_CMS 21

Demo

Page 22: Magnolia CMS and Rails

@MAGNOLIA_CMS

Internet

Application

Provide Content Data

Fetch Content Data Assemble Response Render Templates

Web-facing component

JSON Response

HTTP Request

HTTP Request

HTTP (HTML) Request

Page 23: Magnolia CMS and Rails

@MAGNOLIA_CMS 23

Demo

Page 24: Magnolia CMS and Rails

@MAGNOLIA_CMS

Internet

ApplicationEditors

Provide Editing Interface Access Application

Provide Content Data Return Response

Fetch Content Data Assemble Response Render Templates (with “Green Bars”)

HTTP Request

Proxy Request

JSON Response

HTTP Request

Proxy Response

HTTP (HTML) Response

Page 25: Magnolia CMS and Rails

@MAGNOLIA_CMS

Internet

ApplicationEditors

“Sinicum Server” (Magnolia Module)

“Sinicum” (Ruby Gem, Rails Engine)

Page 26: Magnolia CMS and Rails

@MAGNOLIA_CMS 26

Sinicum Servergithub.com/dievision/sinicum-

server

Page 27: Magnolia CMS and Rails

@MAGNOLIA_CMS 27

Magnolia Module Plain Java, no Ruby dependencies

Jersey/JAX-RS JSON REST API (does not use the Magnolia 5.2 REST framework for historical

reasons) Exposes content, CMS functionality

Proxies requests from the Pages App

to the external application

Page 28: Magnolia CMS and Rails

@MAGNOLIA_CMS 28

Page 29: Magnolia CMS and Rails

@MAGNOLIA_CMS 29

Page 30: Magnolia CMS and Rails

@MAGNOLIA_CMS 30

The REST Part

Page 31: Magnolia CMS and Rails

@MAGNOLIA_CMS 31

curl --user superuser:superuser \ 'http://localhost:8080/sinicum-rest/:workspace/:path'

Page 32: Magnolia CMS and Rails

@MAGNOLIA_CMS 32

curl --user superuser:superuser \ 'http://localhost:8080/sinicum-rest/website/de?pretty=true'[ { "meta" : { "name" : "de", "path" : "/de", "superTypes" : [ "mix:created", „mix:referenceable", "nt:base", "nt:hierarchyNode", "mgnl:activatable", „mgnl:content", "mgnl:created", "mgnl:lastModified", „mgnl:renderable", "mgnl:versionable" ], "mixinNodeTypes" : [ ], "depth" : 1, "workspace" : "website", "mgnl:template" : "mymodule:pages/application", "mgnl:created" : "2014-03-22T09:26:36.382+01:00", "mgnl:createdBy" : "superuser", "mgnl:lastModified" : "2014-03-22T15:52:07.547+01:00", "mgnl:lastModifiedBy" : "superuser", "jcr:created" : "2014-03-22T09:53:36.693+01:00", "jcr:uuid" : "1ba90c51-a0c2-405b-8c36-764f60e5fb90", "jcr:primaryType" : "mgnl:page" }, "properties" : { "title" : "A Headline" }, "nodes" : { "main" : { "meta" : { "name" : "main", "path" : "/de/main", "superTypes" : [ "mix:created", „mix:referenceable", "nt:base", "nt:hierarchyNode", "mgnl:activatable", „mgnl:contentNode", "mgnl:created", "mgnl:lastModified", "mgnl:renderable" ], "mixinNodeTypes" : [ ], "depth" : 2, "workspace" : "website", "mgnl:created" : "2014-03-22T15:49:48.678+01:00", "mgnl:createdBy" : "superuser", "mgnl:lastModified" : "2014-03-22T15:49:48.678+01:00", "mgnl:lastModifiedBy" : "superuser", "jcr:created" : "2014-03-22T15:49:48.678+01:00", "jcr:uuid" : "734b6fee-0eb8-4d2a-a8c2-151f730b23b3", "jcr:primaryType" : "mgnl:area" }, "properties" : { }, "nodes" : { "0" : { "meta" : { "name" : "0",

"path" : "/de/main/0", "superTypes" : [ "mix:created", "mix:referenceable", „nt:base", "nt:hierarchyNode", "mgnl:activatable", „mgnl:contentNode", "mgnl:created", "mgnl:lastModified", "mgnl:renderable" ], "mixinNodeTypes" : [ ], "depth" : 3, "workspace" : "website", "mgnl:template" : "mymodule:components/textBlock", "mgnl:created" : "2014-03-22T15:52:07.548+01:00", "mgnl:createdBy" : "superuser", "mgnl:lastModified" : "2014-03-22T15:52:07.548+01:00", "mgnl:lastModifiedBy" : "superuser", "jcr:created" : "2014-03-22T15:52:07.547+01:00", "jcr:uuid" : "42333112-f48f-4646-8b0c-12d4cb8beefa", "jcr:primaryType" : "mgnl:component" }, "properties" : { "text" : "A text" }, "nodes" : { } } } } } } ]

Page 33: Magnolia CMS and Rails

@MAGNOLIA_CMS 33

curl --user superuser:superuser \ 'http://localhost:8080/sinicum-rest/website/de?pretty=true'

{ "meta" : { // JCR/Magnolia meta information on a node }, "properties" : { // The node’s properties }, "nodes" : { ! // The child nodes relevant for the document "child_node" : { "meta" : { // JCR/Magnolia meta information on the child node }, "properties" : { // The child node’s properties }, !!! } } }

Page 34: Magnolia CMS and Rails

@MAGNOLIA_CMS 34

curl --user superuser:superuser \ 'http://localhost:8080/sinicum-rest/website/de?pretty=true'

{ "meta" : { // JCR/Magnolia meta information on a node }, "properties" : { // The node’s properties }, "nodes" : { ! // The child nodes relevant for the document "child_node" : { "meta" : { // JCR/Magnolia meta information on the child node }, "properties" : { // The child node’s properties }, "nodes" : { // All relevant nodes are resolved recursively } } } }

Page 35: Magnolia CMS and Rails

@MAGNOLIA_CMS 35

„Documents“, not JCR Nodes

Returns a Node including its relevant children in a single

request(e.g. Page + Area + Components)

Optionally, UUID References are resolved as well

Page 36: Magnolia CMS and Rails

@MAGNOLIA_CMS 36

Central Goal:

Minimize the number of API requests per page

Page 37: Magnolia CMS and Rails

@MAGNOLIA_CMS 37

Get a single node (and it’s children) via its path GET /sinicum-server/:workspace/:path

Get a single node (and it’s children) via its UUID GET /sinicum-server/:workspace/_uuid/:uuid

Perform a JCR query GET /sinicum-server/:workspace/_query

Parameter Name Description

query The JCR query to perform

language The JCR query language (xpath, sql, jcr_sql2)

limit The maximum number of results

offset The offset for the results

Page 38: Magnolia CMS and Rails

@MAGNOLIA_CMS 38

Get all valid components for an area GET /sinicum-server/_templating/components/ :module_name/:page_name/:area_name

Create and initialize an Area on a Page POST /sinicum-server/_templating/areas/initialize

Parameter Name Description

workspace The name of the workspace

baseNodeUuid The UUID of the node to create the Area in

areaName The name of the Area to create

Get the dialog for a component GET /sinicum-server/_templating/dialogs/ :component_type/:module_name/:component_name

Page 39: Magnolia CMS and Rails

@MAGNOLIA_CMS 39

The Proxy Part

Page 40: Magnolia CMS and Rails

@MAGNOLIA_CMS 40

Page 41: Magnolia CMS and Rails

@MAGNOLIA_CMS 41

% rails server => Booting WEBrick => Rails 4.0.4 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Ctrl-C to shutdown server [2014-03-24 18:10:25] INFO WEBrick 1.3.1 [2014-03-24 18:10:25] INFO ruby 2.1.1 (2014-02-24) [x86_64-darwin12.4.0] [2014-03-24 18:10:25] INFO WEBrick::HTTPServer#start: pid=68886 port=3000

Page 42: Magnolia CMS and Rails

@MAGNOLIA_CMS 42

Page 43: Magnolia CMS and Rails

@MAGNOLIA_CMS 43

Sinicumgithub.com/dievision/

sinicum

Page 44: Magnolia CMS and Rails

@MAGNOLIA_CMS 44

Demo

Page 45: Magnolia CMS and Rails

@MAGNOLIA_CMS 45

Ruby client for the REST API

“Object-Document-Mapper” mappingthe JSON responses to Ruby objects that follow

Ruby/ActiveRecord semantics

Conventions for Template/Area/Component files

Implementation of Magnolia CMS’Tag Libraries as Rails Helpers

Convenience functionality to let Rails Controllers handle requests to Magnolia CMS

Page 46: Magnolia CMS and Rails

@MAGNOLIA_CMS 46

Project Status

Page 47: Magnolia CMS and Rails

@MAGNOLIA_CMS 47

Stable and used in production

Follows Dievision’s conventions and can only benefit from

exposure to the outside world

Page 48: Magnolia CMS and Rails

@MAGNOLIA_CMS 48

We are happy to help you get started:

[email protected]

Follow the project atgithub.com/dievision/sinicumgithub.com/dievision/sinicum-

server

Fork it, create Issues and send

Page 49: Magnolia CMS and Rails

@MAGNOLIA_CMS 49

Thank you

Page 50: Magnolia CMS and Rails

@MAGNOLIA_CMS 50

Any Questions?