sinicum 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +7 -0
  2. data/.cane +19 -0
  3. data/.gitignore +14 -0
  4. data/.rubocop.yml +30 -0
  5. data/.travis.yml +14 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE +24 -0
  8. data/README.md +327 -0
  9. data/Rakefile +37 -0
  10. data/app/assets/javascripts/sinicum/magnolia_client.js.coffee +233 -0
  11. data/app/controllers/sinicum/controller_base.rb +173 -0
  12. data/app/controllers/sinicum/controllers/cache_aware.rb +16 -0
  13. data/app/controllers/sinicum/controllers/global_state_cache.rb +83 -0
  14. data/app/helpers/sinicum/helper_utils.rb +152 -0
  15. data/app/helpers/sinicum/mgnl_helper.rb +145 -0
  16. data/app/helpers/sinicum/mgnl_helper5.rb +7 -0
  17. data/app/helpers/sinicum/mgnl_image_helper.rb +26 -0
  18. data/app/helpers/sinicum/taglib_helper5.rb +166 -0
  19. data/gemfiles/Gemfile-3.2 +6 -0
  20. data/gemfiles/Gemfile-4.0 +6 -0
  21. data/lib/generators/sinicum/install_generator.rb +162 -0
  22. data/lib/generators/sinicum/templates/VersionHandler.java +18 -0
  23. data/lib/generators/sinicum/templates/config/default/log4j-development.xml +203 -0
  24. data/lib/generators/sinicum/templates/config/default/log4j.xml +200 -0
  25. data/lib/generators/sinicum/templates/config/default/magnolia-author.properties +63 -0
  26. data/lib/generators/sinicum/templates/config/default/magnolia-public01.properties +63 -0
  27. data/lib/generators/sinicum/templates/config/default/magnolia.properties +63 -0
  28. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-author.xml +73 -0
  29. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-public01.xml +73 -0
  30. data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search.xml +70 -0
  31. data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.dialogs.xml +1625 -0
  32. data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.templates.xml +247 -0
  33. data/lib/generators/sinicum/templates/module-config.xml +13 -0
  34. data/lib/generators/sinicum/templates/module-pom.xml +67 -0
  35. data/lib/generators/sinicum/templates/project-pom.xml +104 -0
  36. data/lib/generators/sinicum/templates/rails/_article.html.haml +15 -0
  37. data/lib/generators/sinicum/templates/rails/_content.html.haml +2 -0
  38. data/lib/generators/sinicum/templates/rails/_meta.html.haml +9 -0
  39. data/lib/generators/sinicum/templates/rails/application.html.haml +11 -0
  40. data/lib/generators/sinicum/templates/rails/content_controller.rb +5 -0
  41. data/lib/generators/sinicum/templates/rails/imaging.yml +8 -0
  42. data/lib/generators/sinicum/templates/rails/sinicum_server.yml +15 -0
  43. data/lib/sinicum.rb +53 -0
  44. data/lib/sinicum/content/aggregator.rb +173 -0
  45. data/lib/sinicum/content/website_content_resolver.rb +10 -0
  46. data/lib/sinicum/engine.rb +23 -0
  47. data/lib/sinicum/imaging.rb +29 -0
  48. data/lib/sinicum/imaging/config.rb +133 -0
  49. data/lib/sinicum/imaging/converter.rb +81 -0
  50. data/lib/sinicum/imaging/default_converter.rb +20 -0
  51. data/lib/sinicum/imaging/image_size_converter.rb +52 -0
  52. data/lib/sinicum/imaging/imaging.rb +171 -0
  53. data/lib/sinicum/imaging/imaging_file.rb +115 -0
  54. data/lib/sinicum/imaging/imaging_middleware.rb +56 -0
  55. data/lib/sinicum/imaging/max_size_converter.rb +39 -0
  56. data/lib/sinicum/imaging/resize_crop_converter.rb +35 -0
  57. data/lib/sinicum/jcr/api_client.rb +50 -0
  58. data/lib/sinicum/jcr/api_queries.rb +37 -0
  59. data/lib/sinicum/jcr/cache/global_cache.rb +26 -0
  60. data/lib/sinicum/jcr/dam/document.rb +57 -0
  61. data/lib/sinicum/jcr/dam/image.rb +40 -0
  62. data/lib/sinicum/jcr/jcr_configuration.rb +67 -0
  63. data/lib/sinicum/jcr/mgnl4_compatibility.rb +11 -0
  64. data/lib/sinicum/jcr/node.rb +268 -0
  65. data/lib/sinicum/jcr/node_initializer.rb +16 -0
  66. data/lib/sinicum/jcr/node_queries.rb +101 -0
  67. data/lib/sinicum/jcr/query_sanitizer.rb +24 -0
  68. data/lib/sinicum/jcr/type_translator.rb +38 -0
  69. data/lib/sinicum/jcr/type_translators/component_translator.rb +28 -0
  70. data/lib/sinicum/jcr/type_translators/dam_translator.rb +33 -0
  71. data/lib/sinicum/jcr/type_translators/data_translator.rb +31 -0
  72. data/lib/sinicum/jcr/type_translators/default_translator.rb +13 -0
  73. data/lib/sinicum/jcr/type_translators/translator_base.rb +40 -0
  74. data/lib/sinicum/logger.rb +28 -0
  75. data/lib/sinicum/navigation/default_navigation_element.rb +30 -0
  76. data/lib/sinicum/navigation/navigation_element.rb +39 -0
  77. data/lib/sinicum/navigation/navigation_element_list.rb +33 -0
  78. data/lib/sinicum/navigation/navigation_handler.rb +95 -0
  79. data/lib/sinicum/navigation/navigation_status.rb +27 -0
  80. data/lib/sinicum/templating/area_handler.rb +33 -0
  81. data/lib/sinicum/templating/dialog_resolver.rb +26 -0
  82. data/lib/sinicum/templating/templating_utils.rb +24 -0
  83. data/lib/sinicum/util.rb +12 -0
  84. data/lib/sinicum/version.rb +3 -0
  85. data/script/cibuild +31 -0
  86. data/sinicum.gemspec +29 -0
  87. data/spec/controllers/sinicum/controller_base_spec.rb +53 -0
  88. data/spec/controllers/sinicum/controllers/global_state_cache_spec.rb +35 -0
  89. data/spec/dummy/REVISION +1 -0
  90. data/spec/dummy/Rakefile +7 -0
  91. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  92. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  93. data/spec/dummy/app/views/application/index.html.erb +1 -0
  94. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  95. data/spec/dummy/app/views/layouts/layout_name.html.erb +0 -0
  96. data/spec/dummy/app/views/layouts/my-module/test.html.erb +0 -0
  97. data/spec/dummy/app/views/layouts/my_module/test.html.erb +0 -0
  98. data/spec/dummy/config.ru +4 -0
  99. data/spec/dummy/config/application.rb +45 -0
  100. data/spec/dummy/config/boot.rb +10 -0
  101. data/spec/dummy/config/database.yml +22 -0
  102. data/spec/dummy/config/environment.rb +5 -0
  103. data/spec/dummy/config/environments/development.rb +24 -0
  104. data/spec/dummy/config/environments/production.rb +51 -0
  105. data/spec/dummy/config/environments/test.rb +34 -0
  106. data/spec/dummy/config/imaging.yml +7 -0
  107. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  108. data/spec/dummy/config/initializers/inflections.rb +10 -0
  109. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  110. data/spec/dummy/config/initializers/secret_token.rb +11 -0
  111. data/spec/dummy/config/initializers/session_store.rb +8 -0
  112. data/spec/dummy/config/locales/en.yml +5 -0
  113. data/spec/dummy/config/routes.rb +59 -0
  114. data/spec/dummy/config/sinicum_server.yml +13 -0
  115. data/spec/dummy/public/404.html +26 -0
  116. data/spec/dummy/public/422.html +26 -0
  117. data/spec/dummy/public/500.html +26 -0
  118. data/spec/dummy/public/favicon.ico +0 -0
  119. data/spec/dummy/public/javascripts/application.js +2 -0
  120. data/spec/dummy/public/javascripts/controls.js +965 -0
  121. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  122. data/spec/dummy/public/javascripts/effects.js +1123 -0
  123. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  124. data/spec/dummy/public/javascripts/rails.js +191 -0
  125. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  126. data/spec/dummy/script/rails +6 -0
  127. data/spec/fixtures/api/cache_global.json +3 -0
  128. data/spec/fixtures/api/content_mgnl5.json +22 -0
  129. data/spec/fixtures/api/default_json.json.erb +47 -0
  130. data/spec/fixtures/api/default_json_mgnl5.json.erb +27 -0
  131. data/spec/fixtures/api/file.json +73 -0
  132. data/spec/fixtures/api/file_mgnl5.json +51 -0
  133. data/spec/fixtures/api/homepage.json +1497 -0
  134. data/spec/fixtures/api/homepage_parent.json +483 -0
  135. data/spec/fixtures/api/image.json +73 -0
  136. data/spec/fixtures/api/image_mgnl5.json +50 -0
  137. data/spec/fixtures/api/navigation_children.json +3107 -0
  138. data/spec/fixtures/api/navigation_parents.json +25 -0
  139. data/spec/fixtures/api/product.json +2084 -0
  140. data/spec/fixtures/api/query_result.json +61 -0
  141. data/spec/fixtures/mock_content.rb +6 -0
  142. data/spec/fixtures/mock_image.gif +0 -0
  143. data/spec/helpers/sinicum/helper_utils_spec.rb +55 -0
  144. data/spec/helpers/sinicum/mgnl_helper_spec.rb +315 -0
  145. data/spec/helpers/sinicum/mgnl_image_helper_spec.rb +103 -0
  146. data/spec/sinicum/content/aggregator_spec.rb +91 -0
  147. data/spec/sinicum/content/website_content_resolver_spec.rb +14 -0
  148. data/spec/sinicum/imaging/config_spec.rb +50 -0
  149. data/spec/sinicum/imaging/converter_spec.rb +41 -0
  150. data/spec/sinicum/imaging/image_size_converter_spec.rb +27 -0
  151. data/spec/sinicum/imaging/imaging.yml +15 -0
  152. data/spec/sinicum/imaging/imaging_file_spec.rb +125 -0
  153. data/spec/sinicum/imaging/imaging_middleware_spec.rb +79 -0
  154. data/spec/sinicum/imaging/max_size_converter_spec.rb +52 -0
  155. data/spec/sinicum/imaging/resize_crop_converter_spec.rb +18 -0
  156. data/spec/sinicum/imaging_spec.rb +13 -0
  157. data/spec/sinicum/jcr/api_client_spec.rb +69 -0
  158. data/spec/sinicum/jcr/cache/global_cache_spec.rb +29 -0
  159. data/spec/sinicum/jcr/dam/document_spec.rb +81 -0
  160. data/spec/sinicum/jcr/dam/image_spec.rb +46 -0
  161. data/spec/sinicum/jcr/jcr_configuration_spec.rb +57 -0
  162. data/spec/sinicum/jcr/mgnl4_compatibility_spec.rb +10 -0
  163. data/spec/sinicum/jcr/node_queries_spec.rb +113 -0
  164. data/spec/sinicum/jcr/node_spec.rb +261 -0
  165. data/spec/sinicum/jcr/query_sanitizer_spec.rb +26 -0
  166. data/spec/sinicum/jcr/type_translator_spec.rb +42 -0
  167. data/spec/sinicum/jcr/type_translators/component_translator_spec.rb +71 -0
  168. data/spec/sinicum/jcr/type_translators/data_translator_spec.rb +38 -0
  169. data/spec/sinicum/jcr/type_translators/default_translator_spec.rb +19 -0
  170. data/spec/sinicum/navigation/default_navigation_element_spec.rb +45 -0
  171. data/spec/sinicum/navigation/navigation_handler_spec.rb +71 -0
  172. data/spec/sinicum/templating/dialog_resolver_spec.rb +13 -0
  173. data/spec/sinicum/util_spec.rb +34 -0
  174. data/spec/spec_helper.rb +42 -0
  175. data/spec/support/default_node_reader.rb +40 -0
  176. metadata +434 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 456a2c59d11a8ab1665d6ba696aac14483dec0aa
4
+ data.tar.gz: b7b32d4f85004c178b9fb25afafe6e5efe26c9b2
5
+ SHA512:
6
+ metadata.gz: e85576d6b9475a2eeecb786f4d22e1fea2c685b166d7ff222814b4dc543c6f3273f8812645f9029afebc01eb90390e06342e318f5ad38c404957ceb95a30b9a2
7
+ data.tar.gz: 5ac226ceddfb17e42e1cb2c55eaaaa0fe7fe781d8167c0be2180441257e7ca7ec4eb320934ba31f90764abfa370327bb7f293c4508a6954082c9bcb8e5b4ed52
data/.cane ADDED
@@ -0,0 +1,19 @@
1
+ --style-measure 100
2
+ --style-exclude spec/dummy/**/*.*
3
+ --abc-max 23
4
+
5
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_meta
6
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_img
7
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_out
8
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_navigation
9
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_link
10
+ --abc-exclude Sinicum::Helper::CmsHelper#cms_link_2_uri
11
+ --abc-exclude Sinicum::Helper::CmsHelperJava#edit_bar
12
+ --abc-exclude Sinicum::Helper::CmsHelperJava#new_bar
13
+ --abc-exclude Sinicum::Helper::CmsHelperJava#iterator_resolve_node
14
+ --abc-exclude Sinicum::Helper::CmsHelperJava#main_bar
15
+ --abc-exclude Sinicum::Helper::CmsHelperJava#main_bar
16
+ --abc-exclude Sinicum::Jcr::Content.wrap_jcr_content
17
+ --abc-exclude Sinicum::Jcr::Base.find
18
+ --abc-exclude Sinicum::Jcr::Base#handle_nested_content
19
+ --abc-exclude Sinicum::Jcr::Base#write_attribute
@@ -0,0 +1,14 @@
1
+ # bundle gem
2
+ *.gem
3
+ .bundle
4
+ Gemfile*.lock
5
+ pkg/*
6
+
7
+ # Enginex
8
+ spec/dummy/db/*.sqlite3
9
+ spec/dummy/log/*.log
10
+ spec/dummy/tmp/
11
+
12
+ /.yardoc
13
+ /doc
14
+ /vendor
@@ -0,0 +1,30 @@
1
+ AllCops:
2
+ Exclude:
3
+ - spec/dummy/**
4
+ - lib/generators/**
5
+ RunRailsCops: true
6
+
7
+ ClassLength:
8
+ Max: 125
9
+
10
+ HandleExceptions:
11
+ Enabled: False
12
+
13
+ LineLength:
14
+ Max: 100
15
+
16
+ CyclomaticComplexity:
17
+ Max: 10
18
+
19
+ DoubleNegation:
20
+ Enabled: False
21
+
22
+ MethodLength:
23
+ Max: 15
24
+
25
+ Documentation:
26
+ Enabled: false
27
+
28
+ StringLiterals:
29
+ Enabled: false
30
+
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ - "2.1.0"
6
+ - "jruby-19mode"
7
+ script: bundle exec rake
8
+ gemfile:
9
+ - Gemfile
10
+ - gemfiles/Gemfile-3.2
11
+ - gemfiles/Gemfile-4.0
12
+ addons:
13
+ code_climate:
14
+ repo_token: 97304c6d5e6017ffcf39bb7220a40d37062205ae6b8989a712ac0631b9122111
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinicum.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ == Sinicum
2
+
3
+ The MIT License
4
+
5
+ Copyright (c) 2008-2014 Jon Yurek and thoughtbot, inc.
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE.
24
+
@@ -0,0 +1,327 @@
1
+ Sinicum
2
+ =======
3
+
4
+ [![Build Status](https://magnum.travis-ci.com/dievision/sinicum.svg?token=gTyheAYAFCcFbV9J8ryk&branch=master)](https://magnum.travis-ci.com/dievision/sinicum) [![Code Climate](https://codeclimate.com/repos/5346b82ce30ba06c4100ea18/badges/e2f48b8dc18965b6ef06/gpa.png)](https://codeclimate.com/repos/5346b82ce30ba06c4100ea18/feed) [![Coverage](https://codeclimate.com/repos/5346b82ce30ba06c4100ea18/badges/e2f48b8dc18965b6ef06/coverage.png)](https://codeclimate.com/repos/5346b82ce30ba06c4100ea18/feed)
5
+
6
+ Use content created in Magnolia CMS in your Ruby/Rails application. Sinicum works as a Ruby Client for the REST API provided by [Sinicum Server](http://github.com/dievision/sinicum-server). Basically it is an "Object-Document-Mapper" mapping the JSON-responses to Ruby objects. It is fully integrated into Rails and lets Controller handle the requests to Magnolia CMS.
7
+
8
+ Sinicum has been used internally at [Dievision](http://www.dievision.de) for quite some time and has only recently been open sourced. We think it’s a great way to build Rails Applications in concert with a really advanced Content Management System. If you are interested in the concept but have trouble getting started, [please let us know](mailto: sinicum@dievision.de). We are happy to help and interested in your pain points.
9
+
10
+ We plan to expand the documentation and add more examples until mid-May 2014.
11
+
12
+ So dive in and get started!
13
+
14
+ # Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ gem 'sinicum'
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install sinicum
27
+
28
+
29
+ # Installation for Rails
30
+
31
+ ### Requirements
32
+ Please make sure to have [Maven 3.x](http://maven.apache.org) and PostgreSQL installed
33
+ on your system. If you are using OS X and Homebrew, run
34
+
35
+ $ brew install maven
36
+ $ brew install postgresql
37
+
38
+ By default, we will prepare Magnolia CMS with a postgres database. Please create the database you have entered in the installation step following.
39
+
40
+ Please note that all template files installed in the installation step are using haml. You can install this Gem by adding
41
+
42
+ gem 'haml-rails'
43
+
44
+ to your Gemfile.
45
+
46
+ In order to use the Sinicum Imaging functionality, you will need to install [Imagemagick](http://www.imagemagick.org/) on your machine. If you are using OS X and Homebrew you can do this with
47
+
48
+ $ brew install imagemagick
49
+
50
+ ##### Please note: Sinicum works with Rails >= 3.2, but we recommend Rails 4.
51
+
52
+ ### Installation
53
+ In order to set up Sinicum in a Rails project, you need to add `sinicum-runner` to your Gemfile:
54
+
55
+ gem 'sinicum-runner'
56
+
57
+ Then set up the necessary files by running
58
+
59
+ $ rails generate sinicum:install
60
+
61
+ You will be asked a few questions. After this all necessary files for a
62
+ Magnolia Maven Project will be generated and your Rails project will
63
+ be configured. The generator will ask you, if you would like to have some sample templates installed. We highly recommend you to answer with `yes`.
64
+
65
+ At this point, please remember to create your database, you specifed before. (as a quick reminder: `createdb` and `createuser` for psql).
66
+
67
+ Then start up Magnolia CMS with
68
+
69
+ $ bundle exec sinicum-runner
70
+
71
+ and Rails with
72
+
73
+ $ rails server
74
+
75
+ You can visit the Magnolia installation at http://localhost:8080. Rails is accessible as usual at http://localhost:3000.
76
+
77
+ #### Important Note:
78
+
79
+ The first thing you should do after logging into Magnolia CMS with the credentials `superuser`:`superuser` is to go to `Security` and edit the `superuser` in the `System Users` tab. You need to add the role sinicum-server manually, to be able to access Sinicum Server from rails.
80
+
81
+ # Getting Started
82
+
83
+ ## Basic Magnolia CMS knowledge is highly recommended
84
+
85
+ If you want to use Sinicum with all its features you will need to learn some basics of Magnolia CMS.
86
+ It is always a good idea to have a look at the [Magnolia CMS Documentation](http://documentation.magnolia-cms.com/display/DOCS/Magnolia+5+Documentation).
87
+
88
+ To just use it as a CMS with Rails we provide you with all information you'll need.
89
+
90
+ ## Templating
91
+
92
+ Magnolia CMS provides three types of templates:
93
+
94
+ - `Page` is the highest level template. It renders a page. Pages are the building blocks of a site hierarchy. They create a tree hierarchy of parent pages and child pages that you can see in Magnolia AdminCentral and visualize to site visitors in a sitemap and in navigation. Each part of a URI is also a page. For example, example.com/products/bicycles would have at least three pages: home page, products section page, and a bicycles page.
95
+
96
+ - `Area` is the next level down. Pages consist of areas which can consist of further areas or components. Areas have two purposes: they structure the page and control what components editors can place inside the area. This makes area the most powerful template. It ensures consistency across the site. Areas also provide repeatability. An area template typically loops through the components inside it, rendering the components one by one. Most areas are rendered with containing div elements in the generated HTML so you can control their layout on the page with CSS.
97
+
98
+ - `Component` is the smallest block of content that editors can edit, delete and move as a single unit. Think of a component as content that belongs together. At its simplest, a component may be a heading and some text that belong together. However, it can contain almost anything: text and a related image, list of links, teased content from another page and so on.
99
+
100
+ (Taken from [Magnolia CMS Documentation](http://documentation.magnolia-cms.com/display/DOCS/My+first+template))
101
+
102
+ ## Nodes
103
+
104
+ As Magnolia CMS uses the [Apache Jackrabbit](https://jackrabbit.apache.org/) implementation of the [Java Content Repository](https://en.wikipedia.org/wiki/Content_repository_API_for_Java) standard as its internal data format. JCR-Nodes are exposed in Sincium as instances of the class `Sinicum::Jcr::Node`.
105
+
106
+ ### Sinicum::Jcr::Node
107
+ This class follows common Ruby/ActiveRecord semantics.
108
+
109
+ #### Finders and queries
110
+
111
+ Finders are included with the `NodeQueries` module.
112
+
113
+ ##### find_by_path(workspace, path)
114
+ Sinicum::Jcr::Node.find_by_path(:website, '/en/page/subpage')
115
+
116
+ ##### find_by_uuid(workspace, uuid)
117
+ Sinicum::Jcr::Node.find_by_uuid(:website, 'dd793410-89d7-41f3-8cc2-7654c9e8e72b')
118
+
119
+ ##### query(workspace, language, query, parameters = nil, options = {})
120
+ Sinicum::Jcr::Node.query(:website, :xpath, '//en/page/subpage')
121
+ Valid options are:
122
+ - limit
123
+ - offset
124
+
125
+ Valid languages are:
126
+ - xpath
127
+ - jcr-sql2
128
+ - sql
129
+
130
+ You can get a quick overview at the [JCR-Query cheat sheet](http://wiki.magnolia-cms.com/display/WIKI/JCR+Query+Cheat+Sheet)
131
+
132
+ #### Properties
133
+
134
+ Once a node is retrieved you can access various parameters defined by Magnolia CMS:
135
+
136
+ - jcr_path
137
+ - jcr_name
138
+ - jcr_primary_type
139
+ - jcr_workspace
140
+
141
+ You can use [] to access all custom defined parameters (defined by you in the Magnolia CMS Template definition). So it would be possible to retrieve a press_date with
142
+
143
+ node = Sinicum::Jcr::Node.find_by_path(:website, '/en/page/press/article01')
144
+ node[:press_date]
145
+
146
+ Since JCR Nodes are stored in a tree structure, you can also access the children and the parent.
147
+
148
+ node.children
149
+ node.parent
150
+
151
+ #### Mapping JCR objects to Ruby classes
152
+
153
+ All JCR nodes in Magnolia are mapped to `Sinicum::Jcr::Node` objects with the help of `TypeTranslators`. This is somewhat of an analogy to ActiveRecord::Base. But depending on various factors, Sinicum tries to find a better matching subclass of Node. The rules are quite flexible and can be modified (the default rules can be found in the `Sinicum::Jcr::TypeTranslators` module) and are probably best explained in an example.
154
+
155
+ Templates are configured in Magnolia CMS and then mapped to Rails.
156
+ This is done . (A good example is the [ComponentTranslator](https://github.com/dievision/sinicum/blob/master/lib/sinicum/jcr/type_translators/component_translator.rb). It checks the template of a component and tries to initialise a matching class.
157
+
158
+ ##### Example:
159
+
160
+ A component `article` has the template 'my_project:components/article' (generated in the example templates).
161
+ It is now accessed in a content area and a the ComponentTranslator tries to constantize the templatename. The resulting class would be `MyProject::Components::Article`.
162
+
163
+ module MyProject
164
+ module Components
165
+ class Article < Sinicum::Jcr::Node
166
+
167
+ end
168
+ end
169
+ end
170
+
171
+ ## Controllers
172
+
173
+ Sinicum provides convenience functionality to let Rails Controller handle requests to Magnolia CMS and to map Magnolia CMS template definitions to Rails layout files. This is done by including the `Sinicum::ControllerBase`
174
+
175
+ class ContentController < ApplicationController
176
+ include Sinicum::ControllerBase
177
+ end
178
+
179
+ Best practice would be to use the generated `ContentController` as the base Controller for all Controllers, that should have access to Magnolia CMS data.
180
+ ControllerBase adds a few filters to the controller and overrides the render method so that by default the content from the Magnolia CMS page matching the path of the Rails request is fetched and pushed upon a node stack.
181
+
182
+ ##### Example:
183
+ Let's say we have a basic blog with posts and we want to handle the different posts in Magnolia CMS. They should be located under the path `/blog/posts` and have the mgnl:template `myProject:pages/blog_entry`
184
+ We need two things first.
185
+
186
+ class BlogController < ContentController
187
+
188
+ def posts
189
+ @posts = Sinicum::Jcr::Node.query(:website, :sql, 'select * from mgnl:page where jcr:path like '/blog/posts/%'
190
+ render
191
+ end
192
+ end
193
+ and a matching route
194
+
195
+ get '/blog/posts', to: 'blog#posts'
196
+
197
+ The call to render will now try to find a matching view in `views/blog` (e.g. `posts.html.haml`) and use the layout in `views/layouts/my_project/blog_entry.html.haml`.
198
+
199
+ ### Redirect Template
200
+
201
+ Sometimes you want to redirect from a specific page in Magnolia CMS to another page. Normally you would need to set up a route and a redirect action. Since this can lead to errors (e.g. when the page name is changed in magnolia, or the page is moved), Sinicum handles redirects on a template base with the `redirect` template. It is already generated for you with `rails g sinicum:install`.
202
+
203
+ If you select the `redirect` template in Magnolia CMS for a page, you can set its `redirect_link` in the page preferences. It will be saved as a `uuid-string` so you can change the location of the target page or rename it and the redirect will still work.
204
+
205
+ ## Imaging
206
+
207
+ Sinicum makes image handling very easy. You can define several styles for your images you want to render by adding them to `config/imaging.yml` (a default one will be generated during ` rails g sinicum:install`).
208
+
209
+ renderer:
210
+ default:
211
+ render_type: resize_crop
212
+ format: jpeg
213
+ x: 307
214
+ y: 202
215
+ hires_factor: 2
216
+
217
+ The render_type can be
218
+
219
+ - resize_crop - Resizes an image to an exact given size and crops anything else
220
+ - resize_max - Resizes an image to a predefined maximum size
221
+ - default - Simple converter that simply serves a copy of the original file
222
+
223
+ This is all you need to know for a quick start. More details will be added soon.
224
+
225
+ ## Helpers
226
+
227
+ To make it as easy as possible for you to navigate your way around the Magnolia CMS content wrapped in `Sinicum::Jcr::Node`, Sinicum provides you with some neat helper methods. They are split up in two helper modules: `MgnlHelper` and `MgnlImageHelper`. Both are included in `MgnlHelper5` which is automatically included in your ´ApplicationHelper`.
228
+
229
+ ### MgnlHelper
230
+
231
+ #### mgnl_content_data
232
+
233
+ You can always access the current node pushed by the Controller by calling `mgnl_content_data`.
234
+
235
+ #### mgnl_value(key)
236
+
237
+ This method will access a property of the node that sits on top of the node stack.
238
+
239
+ mgnl_value :title
240
+
241
+ #### mgnl_push(key_or_object, options = {})
242
+
243
+ This method is best explained by an example:
244
+
245
+ mgnl_value :title
246
+ mgnl_push :contact_link, workspace: 'contacts' do
247
+ "#{mgnl_value :firstName} #{mgnl_value :lastName}"
248
+
249
+ In the first line of the example, we print out the property title of the node that was pushed on top of the stack by the controller. Then we have a property called `contact_link` which is a uuid-string. We want to access `firstName` and `lastName` of this linked node with the mgnl_value helper method.
250
+ In order to do this, we need to push the linked node onto the node stack. This done by this function. At the end of the block the node will be removed and the previous node is on top of the node stack again.
251
+
252
+ #### mgnl_path(key_or_object, options = {})
253
+
254
+ This method returns the path for an object. If the object is a Sinicum::Jcr::Node it will return its path. If the object is a uuid-string, it will be resolved to the matching node and then its path will be returned.
255
+
256
+ link_to 'Redirect', mgnl_path(:redirect_link)
257
+
258
+ You can pass :workspace as an option, which will tell Sinicum where to look for your node (`website` is the default workspace).
259
+
260
+ #### mgnl_link(key_or_object, options = {}, &block)
261
+
262
+ `mgnl_link` does basically the same as `mgnl_path` except that it renders a `link_to` for you and that you can pass a normal string as `key_or_object`.
263
+
264
+ mgnl_link :link, class: "big-link" do
265
+ 'Click me'
266
+
267
+ #### mgnl_exists?(key_or_object, options = {})
268
+
269
+ `mgnl_exists?` is a good method to check for the existence of a Magnolia CMS object. It returns true or false.
270
+
271
+ #### mgnl_meta(options = {})
272
+
273
+ Displays the `<title>` tag and the `<meta>` tags for a page. The attributes must follow the default naming conventions.
274
+ * title
275
+ * meta_title
276
+ * meta_description
277
+ * meta_keywords
278
+ * meta_noindex
279
+ * meta_search_weight
280
+ * meta_search_boost
281
+
282
+ Returns a String with all necessary `<meta>` tags and the `<title>` tag.
283
+
284
+ #### mgnl_navigation(base_node_or_path, type, options = {}, &block)
285
+
286
+ `mgnl_navigation` iterates over an array with `NavigationElement` instances. You can pass a base node and then select the type of navigation you want (currently only `:children` or`:parents` are supported though). For the options, you can pass on a hash with `{ depth: 2 }`. If you pass on a block, you will get a `NavigationElement` and the corresponding `NavigationStatus`.
287
+
288
+ Let's show you with an example:
289
+
290
+ mgnl_navigation( '/blog', :children, depth: 1).each do |e,s|
291
+ link_to e.title, e.path
292
+
293
+ `NavigationStatus` provides meta-information about the status of a `NavigationElement` in the iteration.
294
+
295
+ - `first?`
296
+ - `last?`
297
+ - `size`
298
+ - `count`
299
+
300
+ ### MgnlImageHelper
301
+
302
+ #### mgnl_asset_path(key_or_object = nil, options = {})
303
+
304
+ Basically a call to `mgnl_path` with the default workspace `:dam`.
305
+
306
+ #### mgnl_img(key_or_object, options = {})
307
+
308
+ `mgnl_img` queries the Magnolia CMS DAM for the given link or uuid and returns it wrapped in ready-to-use `<img>` tag. It takes several options:
309
+
310
+ - `:renderer` - this is the renderer from the imaging.yml file
311
+ - `:width`
312
+ - `:height`
313
+ - `:src`
314
+ - `:alt`
315
+
316
+ An example would be:
317
+
318
+ mgnl_img :image, renderer: "big_image"
319
+
320
+ ## Questions or problems?
321
+
322
+ If you have any issues with Sinicum which you cannot solve by reading the readme, please add an issue on GitHub or write us an email at [sinicum@dievision.de](mailto:sinicum@dievision.de).
323
+ We will be happy to get you started!
324
+
325
+ ## Contributing
326
+
327
+ Contributions are more than welcome! Feel free to fork Sinicum and submit a new feature-branch as pull request. If you encounter any bugs or non expected behaviour, please open a GitHub issue or write an email.