sinicum 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.cane +19 -0
- data/.gitignore +14 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE +24 -0
- data/README.md +327 -0
- data/Rakefile +37 -0
- data/app/assets/javascripts/sinicum/magnolia_client.js.coffee +233 -0
- data/app/controllers/sinicum/controller_base.rb +173 -0
- data/app/controllers/sinicum/controllers/cache_aware.rb +16 -0
- data/app/controllers/sinicum/controllers/global_state_cache.rb +83 -0
- data/app/helpers/sinicum/helper_utils.rb +152 -0
- data/app/helpers/sinicum/mgnl_helper.rb +145 -0
- data/app/helpers/sinicum/mgnl_helper5.rb +7 -0
- data/app/helpers/sinicum/mgnl_image_helper.rb +26 -0
- data/app/helpers/sinicum/taglib_helper5.rb +166 -0
- data/gemfiles/Gemfile-3.2 +6 -0
- data/gemfiles/Gemfile-4.0 +6 -0
- data/lib/generators/sinicum/install_generator.rb +162 -0
- data/lib/generators/sinicum/templates/VersionHandler.java +18 -0
- data/lib/generators/sinicum/templates/config/default/log4j-development.xml +203 -0
- data/lib/generators/sinicum/templates/config/default/log4j.xml +200 -0
- data/lib/generators/sinicum/templates/config/default/magnolia-author.properties +63 -0
- data/lib/generators/sinicum/templates/config/default/magnolia-public01.properties +63 -0
- data/lib/generators/sinicum/templates/config/default/magnolia.properties +63 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-author.xml +73 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search-public01.xml +73 -0
- data/lib/generators/sinicum/templates/config/repo-conf/jackrabbit-bundle-postgres-search.xml +70 -0
- data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.dialogs.xml +1625 -0
- data/lib/generators/sinicum/templates/magnolia/config.modules.myproject.templates.xml +247 -0
- data/lib/generators/sinicum/templates/module-config.xml +13 -0
- data/lib/generators/sinicum/templates/module-pom.xml +67 -0
- data/lib/generators/sinicum/templates/project-pom.xml +104 -0
- data/lib/generators/sinicum/templates/rails/_article.html.haml +15 -0
- data/lib/generators/sinicum/templates/rails/_content.html.haml +2 -0
- data/lib/generators/sinicum/templates/rails/_meta.html.haml +9 -0
- data/lib/generators/sinicum/templates/rails/application.html.haml +11 -0
- data/lib/generators/sinicum/templates/rails/content_controller.rb +5 -0
- data/lib/generators/sinicum/templates/rails/imaging.yml +8 -0
- data/lib/generators/sinicum/templates/rails/sinicum_server.yml +15 -0
- data/lib/sinicum.rb +53 -0
- data/lib/sinicum/content/aggregator.rb +173 -0
- data/lib/sinicum/content/website_content_resolver.rb +10 -0
- data/lib/sinicum/engine.rb +23 -0
- data/lib/sinicum/imaging.rb +29 -0
- data/lib/sinicum/imaging/config.rb +133 -0
- data/lib/sinicum/imaging/converter.rb +81 -0
- data/lib/sinicum/imaging/default_converter.rb +20 -0
- data/lib/sinicum/imaging/image_size_converter.rb +52 -0
- data/lib/sinicum/imaging/imaging.rb +171 -0
- data/lib/sinicum/imaging/imaging_file.rb +115 -0
- data/lib/sinicum/imaging/imaging_middleware.rb +56 -0
- data/lib/sinicum/imaging/max_size_converter.rb +39 -0
- data/lib/sinicum/imaging/resize_crop_converter.rb +35 -0
- data/lib/sinicum/jcr/api_client.rb +50 -0
- data/lib/sinicum/jcr/api_queries.rb +37 -0
- data/lib/sinicum/jcr/cache/global_cache.rb +26 -0
- data/lib/sinicum/jcr/dam/document.rb +57 -0
- data/lib/sinicum/jcr/dam/image.rb +40 -0
- data/lib/sinicum/jcr/jcr_configuration.rb +67 -0
- data/lib/sinicum/jcr/mgnl4_compatibility.rb +11 -0
- data/lib/sinicum/jcr/node.rb +268 -0
- data/lib/sinicum/jcr/node_initializer.rb +16 -0
- data/lib/sinicum/jcr/node_queries.rb +101 -0
- data/lib/sinicum/jcr/query_sanitizer.rb +24 -0
- data/lib/sinicum/jcr/type_translator.rb +38 -0
- data/lib/sinicum/jcr/type_translators/component_translator.rb +28 -0
- data/lib/sinicum/jcr/type_translators/dam_translator.rb +33 -0
- data/lib/sinicum/jcr/type_translators/data_translator.rb +31 -0
- data/lib/sinicum/jcr/type_translators/default_translator.rb +13 -0
- data/lib/sinicum/jcr/type_translators/translator_base.rb +40 -0
- data/lib/sinicum/logger.rb +28 -0
- data/lib/sinicum/navigation/default_navigation_element.rb +30 -0
- data/lib/sinicum/navigation/navigation_element.rb +39 -0
- data/lib/sinicum/navigation/navigation_element_list.rb +33 -0
- data/lib/sinicum/navigation/navigation_handler.rb +95 -0
- data/lib/sinicum/navigation/navigation_status.rb +27 -0
- data/lib/sinicum/templating/area_handler.rb +33 -0
- data/lib/sinicum/templating/dialog_resolver.rb +26 -0
- data/lib/sinicum/templating/templating_utils.rb +24 -0
- data/lib/sinicum/util.rb +12 -0
- data/lib/sinicum/version.rb +3 -0
- data/script/cibuild +31 -0
- data/sinicum.gemspec +29 -0
- data/spec/controllers/sinicum/controller_base_spec.rb +53 -0
- data/spec/controllers/sinicum/controllers/global_state_cache_spec.rb +35 -0
- data/spec/dummy/REVISION +1 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/application/index.html.erb +1 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/layout_name.html.erb +0 -0
- data/spec/dummy/app/views/layouts/my-module/test.html.erb +0 -0
- data/spec/dummy/app/views/layouts/my_module/test.html.erb +0 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +24 -0
- data/spec/dummy/config/environments/production.rb +51 -0
- data/spec/dummy/config/environments/test.rb +34 -0
- data/spec/dummy/config/imaging.yml +7 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +11 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/config/sinicum_server.yml +13 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +191 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fixtures/api/cache_global.json +3 -0
- data/spec/fixtures/api/content_mgnl5.json +22 -0
- data/spec/fixtures/api/default_json.json.erb +47 -0
- data/spec/fixtures/api/default_json_mgnl5.json.erb +27 -0
- data/spec/fixtures/api/file.json +73 -0
- data/spec/fixtures/api/file_mgnl5.json +51 -0
- data/spec/fixtures/api/homepage.json +1497 -0
- data/spec/fixtures/api/homepage_parent.json +483 -0
- data/spec/fixtures/api/image.json +73 -0
- data/spec/fixtures/api/image_mgnl5.json +50 -0
- data/spec/fixtures/api/navigation_children.json +3107 -0
- data/spec/fixtures/api/navigation_parents.json +25 -0
- data/spec/fixtures/api/product.json +2084 -0
- data/spec/fixtures/api/query_result.json +61 -0
- data/spec/fixtures/mock_content.rb +6 -0
- data/spec/fixtures/mock_image.gif +0 -0
- data/spec/helpers/sinicum/helper_utils_spec.rb +55 -0
- data/spec/helpers/sinicum/mgnl_helper_spec.rb +315 -0
- data/spec/helpers/sinicum/mgnl_image_helper_spec.rb +103 -0
- data/spec/sinicum/content/aggregator_spec.rb +91 -0
- data/spec/sinicum/content/website_content_resolver_spec.rb +14 -0
- data/spec/sinicum/imaging/config_spec.rb +50 -0
- data/spec/sinicum/imaging/converter_spec.rb +41 -0
- data/spec/sinicum/imaging/image_size_converter_spec.rb +27 -0
- data/spec/sinicum/imaging/imaging.yml +15 -0
- data/spec/sinicum/imaging/imaging_file_spec.rb +125 -0
- data/spec/sinicum/imaging/imaging_middleware_spec.rb +79 -0
- data/spec/sinicum/imaging/max_size_converter_spec.rb +52 -0
- data/spec/sinicum/imaging/resize_crop_converter_spec.rb +18 -0
- data/spec/sinicum/imaging_spec.rb +13 -0
- data/spec/sinicum/jcr/api_client_spec.rb +69 -0
- data/spec/sinicum/jcr/cache/global_cache_spec.rb +29 -0
- data/spec/sinicum/jcr/dam/document_spec.rb +81 -0
- data/spec/sinicum/jcr/dam/image_spec.rb +46 -0
- data/spec/sinicum/jcr/jcr_configuration_spec.rb +57 -0
- data/spec/sinicum/jcr/mgnl4_compatibility_spec.rb +10 -0
- data/spec/sinicum/jcr/node_queries_spec.rb +113 -0
- data/spec/sinicum/jcr/node_spec.rb +261 -0
- data/spec/sinicum/jcr/query_sanitizer_spec.rb +26 -0
- data/spec/sinicum/jcr/type_translator_spec.rb +42 -0
- data/spec/sinicum/jcr/type_translators/component_translator_spec.rb +71 -0
- data/spec/sinicum/jcr/type_translators/data_translator_spec.rb +38 -0
- data/spec/sinicum/jcr/type_translators/default_translator_spec.rb +19 -0
- data/spec/sinicum/navigation/default_navigation_element_spec.rb +45 -0
- data/spec/sinicum/navigation/navigation_handler_spec.rb +71 -0
- data/spec/sinicum/templating/dialog_resolver_spec.rb +13 -0
- data/spec/sinicum/util_spec.rb +34 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/default_node_reader.rb +40 -0
- metadata +434 -0
@@ -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")
|
data/lib/sinicum.rb
ADDED
@@ -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,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
|