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,2 @@
1
+ - mgnl_components.each do |component|
2
+ = mgnl_render_component(component)
@@ -0,0 +1,9 @@
1
+ <!--[if lt IE 9]>
2
+ <script>'article aside footer header nav section time'.replace(/\w+/g,function(n){document.createElement(n)})</script>
3
+ <![endif]-->
4
+ = mgnl_meta
5
+ = mgnl_init
6
+ = csrf_meta_tags
7
+ %meta(charset="utf-8")
8
+ %meta(http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1")
9
+ %meta(name="viewport" content="width=device-width, initial-scale=1.0")
@@ -0,0 +1,11 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ = render partial: "shared/meta"
5
+ = stylesheet_link_tag "application"
6
+ = javascript_include_tag "application"
7
+
8
+ %body
9
+
10
+ = yield
11
+ = mgnl_area :content
@@ -0,0 +1,5 @@
1
+ # Base Controller all Magnolia-related controllers should inherit
2
+ # from.
3
+ class ContentController < ApplicationController
4
+ include Sinicum::ControllerBase
5
+ end
@@ -0,0 +1,8 @@
1
+ renderer:
2
+
3
+ default:
4
+ render_type: resize_crop
5
+ format: jpeg
6
+ x: 307
7
+ y: 202
8
+ hires_factor: 2
@@ -0,0 +1,15 @@
1
+ development: &sinicumconnect
2
+ host: localhost
3
+ port: 8080
4
+ username: superuser
5
+ password: superuser
6
+
7
+ test:
8
+ <<: *sinicumconnect
9
+ port: 8081
10
+
11
+ author:
12
+ <<: *sinicumconnect
13
+
14
+ production:
15
+ <<: *sinicumconnect
@@ -0,0 +1,53 @@
1
+ require 'active_support/core_ext'
2
+ require 'sinicum/engine'
3
+
4
+ module Sinicum
5
+ require 'sinicum/logger'
6
+
7
+ require 'sinicum/content/aggregator'
8
+ require 'sinicum/content/website_content_resolver'
9
+
10
+ require 'sinicum/util'
11
+
12
+ require 'sinicum/imaging'
13
+ require 'sinicum/imaging/config'
14
+ require 'sinicum/imaging/converter'
15
+ require 'sinicum/imaging/imaging'
16
+ require 'sinicum/imaging/max_size_converter'
17
+ require 'sinicum/imaging/resize_crop_converter'
18
+ require 'sinicum/imaging/default_converter'
19
+ require 'sinicum/imaging/image_size_converter'
20
+ require 'sinicum/imaging/imaging_middleware'
21
+ require 'sinicum/imaging/imaging_file'
22
+
23
+ require 'sinicum/jcr/jcr_configuration'
24
+ require 'sinicum/jcr/api_queries'
25
+ require 'sinicum/jcr/api_client'
26
+ require 'sinicum/jcr/query_sanitizer'
27
+ require 'sinicum/jcr/node_queries'
28
+ require 'sinicum/jcr/mgnl4_compatibility'
29
+ require 'sinicum/jcr/node'
30
+ require 'sinicum/jcr/node_initializer'
31
+
32
+ require 'sinicum/jcr/dam/document'
33
+ require 'sinicum/jcr/dam/image'
34
+
35
+ require 'sinicum/jcr/type_translators/translator_base'
36
+ require 'sinicum/jcr/type_translators/default_translator'
37
+ require 'sinicum/jcr/type_translators/component_translator'
38
+ require 'sinicum/jcr/type_translators/dam_translator'
39
+ require 'sinicum/jcr/type_translators/data_translator'
40
+ require 'sinicum/jcr/type_translator'
41
+
42
+ require 'sinicum/jcr/cache/global_cache'
43
+
44
+ require 'sinicum/templating/templating_utils'
45
+ require 'sinicum/templating/dialog_resolver'
46
+ require 'sinicum/templating/area_handler'
47
+
48
+ require 'sinicum/navigation/navigation_element'
49
+ require 'sinicum/navigation/navigation_status'
50
+ require 'sinicum/navigation/default_navigation_element'
51
+ require 'sinicum/navigation/navigation_handler'
52
+ require 'sinicum/navigation/navigation_element_list'
53
+ end
@@ -0,0 +1,173 @@
1
+ # encoding: utf-8
2
+ module Sinicum
3
+ module Content
4
+ # Public: Handles the content and provides access to it during a request
5
+ class Aggregator
6
+ include Sinicum::Logger
7
+ class << self
8
+ # Public: Set the "original content" of a request, i.e. the content object
9
+ # that represents the "base" of the request, before any other object is
10
+ # subsequently pushed. Usually the content object of the node corresponding
11
+ # to the URI called.
12
+ #
13
+ # Usually, this method should only be called once during a request.
14
+ #
15
+ # When this method is called, all other stacks (`content_data`,
16
+ # `content_node`) are being reset.
17
+ #
18
+ # node - The Node with the original content object.
19
+ #
20
+ # Returns nothing.
21
+ def original_content=(node)
22
+ clean
23
+ Thread.current[:__cms_original_content] = node
24
+ end
25
+
26
+ # Retrieves the `original_content` object.
27
+ #
28
+ # Returns a Node with the original content object.
29
+ def original_content
30
+ Thread.current[:__cms_original_content]
31
+ end
32
+
33
+ # Retrieves the current "active page", comparable to the Magnolia property
34
+ # "actpage".
35
+ #
36
+ # Returns the Node with the current "active page" or the `original_content`
37
+ # if no active page has explicitly been set.
38
+ def active_page
39
+ stack(:__cms_active_page).first || original_content
40
+ end
41
+
42
+ # Sets a new "active page", makes it the new `cms_content_data` and executes
43
+ # the given block in this context. Resets all changes afterwards.
44
+ #
45
+ # node - The node with the active active page.
46
+ def push_active_page(node, &block)
47
+ stack(:__cms_active_page).push(node)
48
+ begin
49
+ push(node) do
50
+ yield
51
+ end
52
+ ensure
53
+ pop(:__cms_active_page)
54
+ end
55
+ end
56
+
57
+ # Retrieves the `content_data` object currently on top of the stack.
58
+ #
59
+ # Returns the current Node.
60
+ def content_data
61
+ if stack && stack.length > 0
62
+ stack.last
63
+ else
64
+ original_content
65
+ end
66
+ end
67
+
68
+ # Push a new `content_data` object on top of the stack and pop it after
69
+ # returning from the block
70
+ #
71
+ # node - The Node to push on top of the stack
72
+ def push(node, &block)
73
+ stack.push(node)
74
+ begin
75
+ yield
76
+ ensure
77
+ pop
78
+ end
79
+ end
80
+
81
+ # Push a new `Content` object on top of the stack and update Magnolia's
82
+ # `current_content`.
83
+ #
84
+ # node - The object to push, must wrap a Magnolia `Content` object.
85
+ def push_current_content(node, &block)
86
+ stack.push(node)
87
+ begin
88
+ yield
89
+ ensure
90
+ pop
91
+ end
92
+ end
93
+
94
+ def push_node_iterator(node, key)
95
+ stack(:__content_iterator_stack).push(node)
96
+ stack(:__content_iterator_stack_key).push(key)
97
+ begin
98
+ yield
99
+ ensure
100
+ pop(:__content_iterator_stack)
101
+ pop(:__content_iterator_stack_key)
102
+ end
103
+ end
104
+
105
+ def node_iterator_key
106
+ stack(:__content_iterator_stack_key).last
107
+ end
108
+
109
+ def node_iterator
110
+ stack(:__content_iterator_stack).last
111
+ end
112
+
113
+ # Convenience method for pushing the _contents_ of a `ContentNode` with the _name_
114
+ # `content_node_name`, based on the current `content_data` object, on top of the stack
115
+ # and popping it afterwards. If no node with the name exists, an empty `Hash` is pushed.
116
+ #
117
+ # Primarily intended to be used with the `cms_content_node` helper
118
+ #
119
+ # @param [String] content_node_name the name of the `content_node` as it is stored in the
120
+ # current `content_data` object
121
+ def push_content_node(content_node_name, &block)
122
+ node_data = nil
123
+ if content_data && content_data.key?(content_node_name)
124
+ node_data = content_data[content_node_name]
125
+ else
126
+ node_data = {}
127
+ end
128
+ stack(:__content_node_stack).push(content_node_name)
129
+ stack.push(node_data)
130
+ begin
131
+ yield
132
+ ensure
133
+ pop
134
+ pop(:__content_node_stack)
135
+ end
136
+ end
137
+
138
+ # Retrieves the current `content_node` or `nil` if none is set
139
+ #
140
+ # @return [Content, nil] _Usually_ a `Content`-like object, `nil` if no `content_node`
141
+ # has been set
142
+ def content_node
143
+ if stack(:__content_node_stack) && stack(:__content_node_stack).length > 0
144
+ stack(:__content_node_stack).last
145
+ else
146
+ nil
147
+ end
148
+ end
149
+
150
+ # Resets all stacks. Should always be called at the end of a request
151
+ def clean
152
+ Thread.current[:__cms_original_content] = nil
153
+ Thread.current[:__cms_active_page] = nil
154
+ Thread.current[:__cms_stack] = nil
155
+ Thread.current[:__content_node_stack] = nil
156
+ Thread.current[:__content_iterator_stack] = nil
157
+ Thread.current[:__content_iterator_stack_key] = nil
158
+ end
159
+
160
+ private
161
+
162
+ def pop(stack_name = :__cms_stack)
163
+ stack(stack_name).pop
164
+ end
165
+
166
+ def stack(stack_name = :__cms_stack)
167
+ Thread.current[stack_name] ||= []
168
+ Thread.current[stack_name]
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,10 @@
1
+ module Sinicum
2
+ module Content
3
+ # Public: Fetches the content from Magnolia based on the path of the request.
4
+ class WebsiteContentResolver
5
+ def self.find_for_path(path)
6
+ ::Sinicum::Jcr::Node.find_by_path(:website, path) if path
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ require 'yaml'
2
+
3
+ module Sinicum
4
+ # Internal: Initialize the Gem in a Rails environment
5
+ class Engine < Rails::Engine
6
+ SINICUM_SERVER_CONFIG_FILE = File.join("config", "sinicum_server.yml")
7
+
8
+ initializer "configure_jcr" do |app|
9
+ config_file = File.join(Rails.root, SINICUM_SERVER_CONFIG_FILE)
10
+ if File.exist?(config_file)
11
+ jcr_config_file = File.read(config_file)
12
+ config = YAML.load(jcr_config_file)[Rails.env]
13
+ ::Sinicum::Jcr::ApiQueries.configure_jcr = config
14
+ else
15
+ Rails.logger.warn("Sinicum configuration file not found, Sinicum is not configured.")
16
+ end
17
+ end
18
+
19
+ initializer "sinicum.add_middleware" do |app|
20
+ app.middleware.insert_after ActionDispatch::Callbacks, Sinicum::Imaging::ImagingMiddleware
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module Sinicum
2
+ module Imaging
3
+ DEFAULT_CONVERTER_NAME = "default"
4
+ DEFAULT_IMAGING_PREFIX = "/damfiles"
5
+ DEFAULT_IMAGING_DMS_PREFIX = "/dmsfiles"
6
+ DEFAULT_DAM_PREFIX = "/dam"
7
+ DEFAULT_DMS_PREFIX = "/dms"
8
+
9
+ def self.default_converter_name
10
+ DEFAULT_CONVERTER_NAME
11
+ end
12
+
13
+ def self.path_prefix_mgnl4
14
+ DEFAULT_IMAGING_DMS_PREFIX
15
+ end
16
+
17
+ def self.path_prefix
18
+ DEFAULT_IMAGING_PREFIX
19
+ end
20
+
21
+ def self.dam_path_prefix
22
+ DEFAULT_DAM_PREFIX
23
+ end
24
+
25
+ def self.dms_path_prefix
26
+ DEFAULT_DMS_PREFIX
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,133 @@
1
+ module Sinicum
2
+ module Imaging
3
+ # Represents the configuraiton of the imaging module and its renderers
4
+ class Config
5
+ IMAGING_CONFIG_FILE = "config/imaging.yml"
6
+
7
+ require 'fileutils'
8
+
9
+ include Sinicum::Logger
10
+
11
+ # The version number of the imaging directory format. Stored in the file `VERSION`.
12
+ VERSION = "1.0"
13
+
14
+ # Default Root directory
15
+ DEFAULT_ROOT_DIR = File.join("tmp", "imaging")
16
+
17
+ # If the directory sturcture is already set up
18
+ @@dir_setup = false
19
+
20
+ # The root directory under which all files are stored
21
+ attr_reader :root_dir
22
+
23
+ # The directory to store all rendered files in
24
+ #
25
+ # @return [String]
26
+ def file_dir
27
+ File.join(@root_dir, "files")
28
+ end
29
+
30
+ # The directory to store temporary files in
31
+ #
32
+ # @return [String]
33
+ def tmp_dir
34
+ File.join(@root_dir, "tmp")
35
+ end
36
+
37
+ # Path of the file that stores the version of the directory format.
38
+ #
39
+ # @return [String]
40
+ def version_file
41
+ File.join(@root_dir, "VERSION")
42
+ end
43
+
44
+ # Initialize and setup the configuration
45
+ #
46
+ # @param [String, nil] configfile Path of the configuration file. If `nil`,
47
+ # `Rails.root/config/imaging.yml` will be used.
48
+ def self.configure(configfile)
49
+ config = Config.send(:new, configfile)
50
+ @@__instance__ = config
51
+ @@config = true
52
+ config
53
+ end
54
+
55
+ # Obtain an instance of the imaging configuration.
56
+ def self.instance
57
+ @@__instance__ ||= false
58
+ fail "Class is not yet configured" unless @@__instance__
59
+ @@__instance__
60
+ end
61
+
62
+ # Returns the converter class for a given renderer
63
+ #
64
+ # @param [Symbol] the renderer to use
65
+ # @return [Sinicum::Imaging::Converter] the converter to use for this renderer
66
+ def converter(renderer)
67
+ result = nil
68
+ renderer_config = read_config[renderer.to_s]
69
+ result = render_type(renderer_config) if renderer_config
70
+ result ||= DefaultConverter.new(nil)
71
+ result
72
+ end
73
+
74
+ def self.read_configuration
75
+ config_file = File.join(Rails.root, IMAGING_CONFIG_FILE)
76
+ if Rails.env.production?
77
+ @@conf ||= configure(config_file)
78
+ else
79
+ configure(config_file)
80
+ end
81
+ end
82
+
83
+ private
84
+
85
+ attr_reader :config_file
86
+
87
+ def render_type(renderer_config)
88
+ case renderer_config["render_type"]
89
+ when "default" then
90
+ Sinicum::Imaging::DefaultConverter.new(renderer_config)
91
+ when "resize_crop" then
92
+ Sinicum::Imaging::ResizeCropConverter.new(renderer_config)
93
+ when "resize_max" then
94
+ Sinicum::Imaging::MaxSizeConverter.new(renderer_config)
95
+ else nil
96
+ end
97
+ end
98
+
99
+ def read_config
100
+ config = YAML.load_file(config_file)
101
+ @root_dir = config['root_dir'] || File.join(Rails.root, DEFAULT_ROOT_DIR)
102
+ setup_directory_structure(@root_dir)
103
+ config['renderer']
104
+ end
105
+
106
+ def setup_directory_structure(dir)
107
+ unless @@dir_setup
108
+ @@dir_setup = true
109
+ FileUtils.mkdir_p(root_dir) unless File.exist?(root_dir)
110
+ unless File.exist?(version_file)
111
+ File.open(version_file, "w") { |f| f.write(VERSION + "\n") }
112
+ end
113
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
114
+ FileUtils.mkdir_p(tmp_dir) unless File.exist?(tmp_dir)
115
+ FileUtils.mkdir_p(file_dir) unless File.exist?(file_dir)
116
+ end
117
+ end
118
+
119
+ def initialize(configfile)
120
+ @config_file = configfile
121
+ read_config
122
+ end
123
+
124
+ def self.new(*args)
125
+ super
126
+ end
127
+
128
+ def self.allocate
129
+ super
130
+ end
131
+ end
132
+ end
133
+ end