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,16 @@
1
+ module Sinicum
2
+ module Jcr
3
+ # Responsible for Initializing a node based on the nodes' JSON data with the
4
+ # correct class.
5
+ class NodeInitializer
6
+ def self.initialize_node_from_json(json)
7
+ node = nil
8
+ TypeTranslator.list.each do |translator|
9
+ node = translator.initialize_node(json)
10
+ break if node
11
+ end
12
+ node
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,101 @@
1
+ require 'multi_json'
2
+
3
+ module Sinicum
4
+ module Jcr
5
+ module NodeQueries
6
+ PATH_DELIMITER = '/'
7
+ UUID_PREFIX = "_uuid"
8
+ BINARY_PREFIX = "_binary"
9
+ extend ActiveSupport::Concern
10
+
11
+ module ClassMethods
12
+ include Sinicum::Logger
13
+ include ApiClient
14
+ include QuerySanitizer
15
+
16
+ def find_by_path(workspace, path)
17
+ url = construct_url(workspace, nil, path)
18
+ return_first_item(url)
19
+ end
20
+
21
+ def find_by_uuid(workspace, uuid)
22
+ url = construct_url(workspace, UUID_PREFIX, uuid)
23
+ return_first_item(url)
24
+ end
25
+
26
+ def query(workspace, language, query, parameters = nil, options = {})
27
+ url = "/#{workspace}/_query"
28
+ sanitized = sanitize_query(language, query, parameters)
29
+ api_hash = { "query" => sanitized, "language" => language.to_s }
30
+ api_hash["limit"] = options[:limit] if options[:limit]
31
+ api_hash["offset"] = options[:offset] if options[:offset]
32
+ response = api_get(url, api_hash)
33
+ from_rest_response(response)
34
+ end
35
+
36
+ def stream_attribute(workspace, path, property_name, output)
37
+ connection = ApiQueries.http_client.get_async(
38
+ ApiQueries.jcr_configuration.base_url + construct_url(workspace, BINARY_PREFIX, path),
39
+ "property" => property_name)
40
+ response = connection.pop
41
+ while result = response.content.read(256)
42
+ output.write(result)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def return_first_item(url)
49
+ response = api_get(url)
50
+ nodes = from_rest_response(response)
51
+ result = nodes
52
+ result = nodes.first if nodes && nodes.is_a?(Array)
53
+ result
54
+ end
55
+
56
+ def from_rest_response(result)
57
+ if result.status == 200
58
+ instances = create_instances(result.body)
59
+ return instances
60
+ elsif result.status == 404
61
+ return
62
+ elsif result.status == 500
63
+ message = "Error fetching content"
64
+ begin
65
+ if result.headers["Content-Type"] =~ /application\/json/
66
+ message << ": #{MultiJson.load(result.body)["message"]}"
67
+ end
68
+ rescue
69
+ # nothing
70
+ end
71
+ fail message
72
+ end
73
+ the_status = result ? result.status : "undefined"
74
+ fail "Error fetching JCR content object. Server status: #{the_status}"
75
+ end
76
+
77
+ def create_instances(body)
78
+ instances = []
79
+ json = MultiJson.load(body)
80
+ if json.is_a?(Array)
81
+ json.each do |node|
82
+ instance = NodeInitializer.initialize_node_from_json(node)
83
+ instances << instance if instance
84
+ end
85
+ else
86
+ instance = NodeInitializer.initialize_node_from_json(json)
87
+ instances << instance if instance
88
+ end
89
+ instances
90
+ end
91
+
92
+ def construct_url(workspace, action, path)
93
+ fail "JCR access is not configured" unless ApiQueries.jcr_configuration
94
+ action = PATH_DELIMITER + action if action && action[0] && action[0] != PATH_DELIMITER
95
+ path = PATH_DELIMITER + path if path && path[0] && path[0] != PATH_DELIMITER
96
+ "/#{workspace}#{action}#{path}"
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,24 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module QuerySanitizer
4
+ private
5
+
6
+ def sanitize_query(language, query, parameters = nil)
7
+ return query unless parameters && parameters.size > 0
8
+
9
+ base_query = query.to_s.dup
10
+ parameters.each_key do |key|
11
+ original_value = parameters[key]
12
+ san_value = escape_for_query(original_value)
13
+ key_pattern = ":#{key}"
14
+ base_query.gsub!(key_pattern, san_value)
15
+ end
16
+ base_query
17
+ end
18
+
19
+ def escape_for_query(unsafe_string)
20
+ unsafe_string.gsub('\'', '\'\'')
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,38 @@
1
+ module Sinicum
2
+ module Jcr
3
+ # Public: Manages TypeTranslators in a Rails Middleware inspired way.
4
+ #
5
+ # A TypeTranslator is a class that translates the information on a node
6
+ # given by the node's JSON representation in a class that will be
7
+ # initialized with the node's data.
8
+ # Please note, that DefaultTranslator should always be the last translator in
9
+ # the array.
10
+ class TypeTranslator
11
+ DEFAULT_TRANSLATORS = [
12
+ Sinicum::Jcr::TypeTranslators::DataTranslator,
13
+ Sinicum::Jcr::TypeTranslators::DamTranslator,
14
+ Sinicum::Jcr::TypeTranslators::ComponentTranslator,
15
+ Sinicum::Jcr::TypeTranslators::DefaultTranslator]
16
+
17
+ def self.use(clazz)
18
+ translators.insert(0, clazz)
19
+ end
20
+
21
+ def self.list
22
+ translators
23
+ end
24
+
25
+ def self.clear
26
+ @translators = []
27
+ end
28
+
29
+ def self.reset
30
+ @translators = DEFAULT_TRANSLATORS.dup
31
+ end
32
+
33
+ def self.translators
34
+ @translators ||= DEFAULT_TRANSLATORS.dup
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module TypeTranslators
4
+ # Public: Identifies a node as a `mgnl:page` or `mgnl:component` and finds
5
+ # the class based on the node's template information.
6
+ class ComponentTranslator
7
+ include TranslatorBase
8
+
9
+ PAGE_TYPE = "mgnl:page"
10
+ COMPONENT_TYPE = "mgnl:component"
11
+
12
+ def self.initialize_node(json)
13
+ if valid_json?(json) &&
14
+ (jcr_primary_type(json) == PAGE_TYPE || jcr_primary_type(json) == COMPONENT_TYPE)
15
+ instance_from_template_name(json)
16
+ end
17
+ end
18
+
19
+ def self.instance_from_template_name(json)
20
+ class_name = split_template_parts(json).join("/").classify
21
+ class_name.constantize.new(json_response: json)
22
+ rescue NameError
23
+ nil
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module TypeTranslators
4
+ # Public: Identifies files stored in Magnolia's DAM workspace as Dam::Document
5
+ # or Dam::Image types.
6
+ class DamTranslator
7
+ include TranslatorBase
8
+
9
+ DOCUMENT_NODE = "jcr:content"
10
+ IMAGE_TYPE_PREFIX = "image/"
11
+ MIME_TYPE = "jcr:mimeType"
12
+
13
+ WORKSPACE = "dam"
14
+ NODE_TYPE = "mgnl:asset"
15
+
16
+ def self.initialize_node(json)
17
+ if jcr_primary_type(json) && workspace(json) == WORKSPACE &&
18
+ jcr_primary_type(json) == NODE_TYPE
19
+ if json[NODES][DOCUMENT_NODE]
20
+ if json[NODES][DOCUMENT_NODE][PROPERTIES] &&
21
+ json[NODES][DOCUMENT_NODE][PROPERTIES][MIME_TYPE] &&
22
+ json[NODES][DOCUMENT_NODE][PROPERTIES][MIME_TYPE].index(IMAGE_TYPE_PREFIX) == 0
23
+ ::Sinicum::Jcr::Dam::Image.new(json_response: json)
24
+ else
25
+ ::Sinicum::Jcr::Dam::Document.new(json_response: json)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module TypeTranslators
4
+ # Public: Identifies nodes in the data module and assigns the matching
5
+ # classes to them.
6
+ class DataTranslator
7
+ include TranslatorBase
8
+ DEFAULT_TYPES = ["mgnl:content", "mgnl:contentNode"]
9
+
10
+ WORKSPACE = "data"
11
+
12
+ def self.initialize_node(json)
13
+ if workspace(json) == WORKSPACE && jcr_primary_type(json) && no_default_type?(json)
14
+ instance_from_primary_type(json)
15
+ end
16
+ end
17
+
18
+ def self.no_default_type?(json)
19
+ !DEFAULT_TYPES.include?(jcr_primary_type(json))
20
+ end
21
+
22
+ def self.instance_from_primary_type(json)
23
+ clazz = jcr_primary_type(json).classify
24
+ clazz.constantize.new(json_response: json)
25
+ rescue NameError
26
+ nil
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module TypeTranslators
4
+ # Public: Identifies all nodes as belonging to the `Node` class. Should be
5
+ # used as the last TypeTranslator in a chain.
6
+ class DefaultTranslator
7
+ def self.initialize_node(json)
8
+ ::Sinicum::Jcr::Node.new(json_response: json)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,40 @@
1
+ module Sinicum
2
+ module Jcr
3
+ module TypeTranslators
4
+ module TranslatorBase
5
+ extend ActiveSupport::Concern
6
+
7
+ META_NODE = "meta"
8
+ NODES = "nodes"
9
+ PROPERTIES = "properties"
10
+ PRIMARY_TYPE = "jcr:primaryType"
11
+ MGNL_TEMPLATE = "mgnl:template"
12
+ WORKSPACE = "workspace"
13
+
14
+ protected
15
+
16
+ module ClassMethods
17
+ def split_template_parts(json)
18
+ mgnl_template(json).gsub('-', '_').split(":")
19
+ end
20
+
21
+ def jcr_primary_type(json)
22
+ json[META_NODE][PRIMARY_TYPE] if json[META_NODE]
23
+ end
24
+
25
+ def workspace(json)
26
+ json[META_NODE][WORKSPACE]
27
+ end
28
+
29
+ def mgnl_template(json)
30
+ json[META_NODE][MGNL_TEMPLATE] if json[META_NODE] && json[META_NODE][MGNL_TEMPLATE]
31
+ end
32
+
33
+ def valid_json?(json)
34
+ jcr_primary_type(json) && mgnl_template(json)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,28 @@
1
+ module Sinicum
2
+ module Logger
3
+ require 'logger'
4
+ @@logger = ::Logger.new(STDOUT)
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ def logger
11
+ if defined?(Rails) && Rails.logger
12
+ return Rails.logger
13
+ else
14
+ return @@logger
15
+ end
16
+ end
17
+
18
+ module ClassMethods
19
+ def logger
20
+ if defined?(Rails) && Rails.logger
21
+ return Rails.logger
22
+ else
23
+ return @@logger
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Sinicum
2
+ module Navigation
3
+ # Public: Standard implementation for the navigation.
4
+ #
5
+ # Expects the pages in the repository to provide the following attributes:
6
+ #
7
+ # nav_title - The title of the page that should be used specifically
8
+ # for the navigation.
9
+ # title - The normal title of the page. Used for the navigation as
10
+ # well if `nav_title` is not present.
11
+ # nav_hidden - Checkbox-based attribute that indicates if the page
12
+ # should not show up in the navigation.
13
+ class DefaultNavigationElement
14
+ include NavigationElement
15
+ DEFAULT_PROPERTIES = %w(title nav_title nav_hidden)
16
+
17
+ def title
18
+ @properties["nav_title"].presence || @properties["title"]
19
+ end
20
+
21
+ def self.navigation_properties
22
+ DEFAULT_PROPERTIES
23
+ end
24
+
25
+ def self.filter_node(json_element)
26
+ !!(json_element["properties"] && json_element["properties"]["nav_hidden"] == true)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ module Sinicum
2
+ module Navigation
3
+ module NavigationElement
4
+ extend ActiveSupport::Concern
5
+
6
+ attr_reader :uuid, :path, :depth, :properties, :children
7
+
8
+ def initialize(uuid, path, depth, properties, children)
9
+ @uuid = uuid
10
+ @path = path
11
+ @depth = depth
12
+ @properties = properties
13
+ @children = children
14
+ end
15
+
16
+ def title
17
+ end
18
+
19
+ def has_children?
20
+ warn "[DEPRECATION] `has_children?` is deprecated. Please use `children?` instead."
21
+ @children && @children.size > 0
22
+ end
23
+
24
+ def children?
25
+ @children && @children.size > 0
26
+ end
27
+
28
+ def children
29
+ NavigationElementList.new(@children)
30
+ end
31
+
32
+ module ClassMethods
33
+ def navigation_properties
34
+ []
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,33 @@
1
+ module Sinicum
2
+ module Navigation
3
+ # Public: Wrapper around the navigation element array that exposes a
4
+ # NavigationStatus in the #each iteration.
5
+ class NavigationElementList
6
+ include Enumerable
7
+
8
+ def initialize(navigation_elements)
9
+ @navigation_elements = navigation_elements
10
+ end
11
+
12
+ def each(&block)
13
+ count = 0
14
+ @navigation_elements.each do |el|
15
+ block.call(el, NavigationStatus.new(@navigation_elements.size, count))
16
+ count += 1
17
+ end
18
+ end
19
+
20
+ def size
21
+ @navigation_elements.size
22
+ end
23
+
24
+ def first
25
+ @navigation_elements.first
26
+ end
27
+
28
+ def last
29
+ @navigation_elements.last
30
+ end
31
+ end
32
+ end
33
+ end