magnolia cms and rails
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
®
@MAGNOLIA_CMS 2
Magnolia and Rails
Patrik Metzmacher, Daniel Trierweiler, Dievision GmbH
@MAGNOLIA_CMS 3
Who we are
We build web-based software
@MAGNOLIA_CMS 6
The Problem
@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.
@MAGNOLIA_CMS 8
@MAGNOLIA_CMS 9
Your Framework of Choice
@MAGNOLIA_CMS 10
Who are you?
@MAGNOLIA_CMS 11
Agenda
@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
@MAGNOLIA_CMS 13
Sinicumgithub.com/dievision/
sinicum
@MAGNOLIA_CMS 14
Just another Magnolia CMS
integration
@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
@MAGNOLIA_CMS 16
“Content as a Service”
@MAGNOLIA_CMS 17
@MAGNOLIA_CMS 18
@MAGNOLIA_CMS 19
@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
@MAGNOLIA_CMS 21
Demo
@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
@MAGNOLIA_CMS 23
Demo
@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
@MAGNOLIA_CMS
Internet
ApplicationEditors
“Sinicum Server” (Magnolia Module)
“Sinicum” (Ruby Gem, Rails Engine)
@MAGNOLIA_CMS 26
Sinicum Servergithub.com/dievision/sinicum-
server
@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
@MAGNOLIA_CMS 28
@MAGNOLIA_CMS 29
@MAGNOLIA_CMS 30
The REST Part
@MAGNOLIA_CMS 31
curl --user superuser:superuser \ 'http://localhost:8080/sinicum-rest/:workspace/:path'
@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" : { } } } } } } ]
@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 }, !!! } } }
@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 } } } }
@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
@MAGNOLIA_CMS 36
Central Goal:
Minimize the number of API requests per page
@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
@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
@MAGNOLIA_CMS 39
The Proxy Part
@MAGNOLIA_CMS 40
@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
@MAGNOLIA_CMS 42
@MAGNOLIA_CMS 43
Sinicumgithub.com/dievision/
sinicum
@MAGNOLIA_CMS 44
Demo
@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
@MAGNOLIA_CMS 46
Project Status
@MAGNOLIA_CMS 47
Stable and used in production
Follows Dievision’s conventions and can only benefit from
exposure to the outside world
@MAGNOLIA_CMS 48
We are happy to help you get started:
Follow the project atgithub.com/dievision/sinicumgithub.com/dievision/sinicum-
server
Fork it, create Issues and send
@MAGNOLIA_CMS 49
Thank you
@MAGNOLIA_CMS 50
Any Questions?