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,83 @@
|
|
1
|
+
module Sinicum
|
2
|
+
module Controllers
|
3
|
+
# Public: Filter to cache the result of a page if no changes in Magnolia
|
4
|
+
# occured.
|
5
|
+
class GlobalStateCache
|
6
|
+
DEPLOY_REVISION_FILE = "REVISION"
|
7
|
+
THREAD_LOCAL_VAR_NAME = "__sinicum_global_state_cache"
|
8
|
+
|
9
|
+
def initialize(controller)
|
10
|
+
@controller = controller
|
11
|
+
@global_jcr_cache_key = Sinicum::Jcr::Cache::GlobalCache.new.current_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.before(controller)
|
15
|
+
if do_cache?
|
16
|
+
instance = new(controller)
|
17
|
+
Thread.current[THREAD_LOCAL_VAR_NAME] = instance
|
18
|
+
instance.render_or_proceed
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.after(controller)
|
23
|
+
if do_cache?
|
24
|
+
begin
|
25
|
+
instance = Thread.current[THREAD_LOCAL_VAR_NAME]
|
26
|
+
instance.cache_response if instance
|
27
|
+
ensure
|
28
|
+
Thread.current[THREAD_LOCAL_VAR_NAME] = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def render_or_proceed
|
34
|
+
cached = Rails.cache.fetch(cache_key)
|
35
|
+
if cached
|
36
|
+
@controller.response.cache_control.merge!(cached[:cache_control])
|
37
|
+
@controller.response.status = cached[:status]
|
38
|
+
@controller.response.headers["X-SCache"] = "true"
|
39
|
+
@controller.render text: cached[:body]
|
40
|
+
else
|
41
|
+
@controller.response.headers["X-SCache"] = "false"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def cache_response
|
46
|
+
response = @controller.response
|
47
|
+
if @controller.request.get? && response.cache_control[:public] &&
|
48
|
+
response.cache_control[:max_age] && response.cache_control[:max_age] > 0
|
49
|
+
cache_content = {
|
50
|
+
body: response.body,
|
51
|
+
cache_control: response.cache_control,
|
52
|
+
status: response.status
|
53
|
+
}
|
54
|
+
Rails.cache.write(cache_key, cache_content)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def cache_key
|
61
|
+
@cache_key ||= [
|
62
|
+
@controller.request.base_url + @controller.request.fullpath,
|
63
|
+
@global_jcr_cache_key, self.class.deploy_revision
|
64
|
+
]
|
65
|
+
@cache_key
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.deploy_revision
|
69
|
+
unless @deploy_revision
|
70
|
+
revision_file = File.join(Rails.root, DEPLOY_REVISION_FILE)
|
71
|
+
if File.exist?(revision_file)
|
72
|
+
@deploy_revision = File.read(revision_file).chomp
|
73
|
+
end
|
74
|
+
end
|
75
|
+
@deploy_revision
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.do_cache?
|
79
|
+
Rails.application.config.action_controller.perform_caching
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Sinicum
|
3
|
+
module HelperUtils
|
4
|
+
DEFAULT_DOCUMENT_WORKSPACE = "dam"
|
5
|
+
FINGERPRINT_REGEX = /.*-[0-9a-f]{32}(\..+)?$/
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def object_from_key_or_object(key_or_object, workspace = nil)
|
10
|
+
mgnl_object_instance_cache(key_or_object, workspace) do
|
11
|
+
object = nil
|
12
|
+
if key_or_object.is_a?(Sinicum::Jcr::Node)
|
13
|
+
object = key_or_object
|
14
|
+
elsif key_or_object.is_a?(Symbol)
|
15
|
+
object = value_from_content(Content::Aggregator.content_data, key_or_object)
|
16
|
+
if Util.is_a_uuid?(object) && workspace
|
17
|
+
object = Jcr::Node.find_by_uuid(workspace, object)
|
18
|
+
end
|
19
|
+
elsif Util.is_a_uuid?(key_or_object)
|
20
|
+
node = Jcr::Node.find_by_uuid(workspace, key_or_object)
|
21
|
+
object = node if node
|
22
|
+
end
|
23
|
+
object
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def mgnl_object_instance_cache(key_or_object, workspace, &block)
|
28
|
+
cache_key = [mgnl_content_data, key_or_object, workspace]
|
29
|
+
@__instance_cache ||= {}
|
30
|
+
unless @__instance_cache.key?(cache_key)
|
31
|
+
result = block.call
|
32
|
+
@__instance_cache[cache_key] = result
|
33
|
+
end
|
34
|
+
@__instance_cache[cache_key]
|
35
|
+
end
|
36
|
+
|
37
|
+
def value_from_content(content_data, key)
|
38
|
+
value = nil
|
39
|
+
if content_data && content_data.respond_to?(key)
|
40
|
+
value = content_data.send(key)
|
41
|
+
elsif content_data && content_data.respond_to?(:[])
|
42
|
+
value = content_data[key]
|
43
|
+
end
|
44
|
+
value
|
45
|
+
end
|
46
|
+
|
47
|
+
def meta_tag_value(key)
|
48
|
+
if key && instance_variable_defined?("@#{key}")
|
49
|
+
meta_value = instance_variable_get("@#{key}")
|
50
|
+
if meta_value.is_a?(String)
|
51
|
+
strip_tags(meta_value)
|
52
|
+
else
|
53
|
+
meta_value
|
54
|
+
end
|
55
|
+
elsif key && value_from_content(mgnl_content_data, key)
|
56
|
+
mgnl_out(key, format: :strip_tags)
|
57
|
+
else
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def meta_content_tag(options)
|
63
|
+
content_tag(:title) do
|
64
|
+
cms_title = nil
|
65
|
+
if defined?(@meta_title) && @meta_title
|
66
|
+
cms_title = @meta_title
|
67
|
+
elsif defined?(@page_title) && @page_title
|
68
|
+
cms_title = @page_title
|
69
|
+
else
|
70
|
+
cms_title = mgnl_out(:meta_title, format: :strip_tags).presence ||
|
71
|
+
mgnl_out(:title, format: :strip_tags)
|
72
|
+
end
|
73
|
+
aggregated_title(cms_title, options)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def aggregated_title(cms_title, options)
|
78
|
+
title = ""
|
79
|
+
title_delimiter = options[:title_delimiter] || " – "
|
80
|
+
title << options[:title_prefix] if options[:title_prefix].present?
|
81
|
+
if cms_title.present?
|
82
|
+
title << title_delimiter if options[:title_prefix].present?
|
83
|
+
title << cms_title
|
84
|
+
title << title_delimiter if options[:title_suffix].present?
|
85
|
+
end
|
86
|
+
title << options[:title_suffix] if options[:title_suffix].present?
|
87
|
+
title
|
88
|
+
end
|
89
|
+
|
90
|
+
def meta_simple_meta_tag(attribute_name, key)
|
91
|
+
result = nil
|
92
|
+
meta_value = key
|
93
|
+
meta_value = meta_tag_value(key) if key.is_a?(Symbol)
|
94
|
+
if meta_value.present?
|
95
|
+
result = tag(:meta, name: attribute_name, content: meta_value)
|
96
|
+
result << "\n"
|
97
|
+
end
|
98
|
+
result
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_missing_attributes(attributes, options)
|
102
|
+
options.each do |key, value|
|
103
|
+
attributes[key.to_sym] = value unless attributes.key?(key.to_sym)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def image_attributes(image, options)
|
108
|
+
attributes = {}
|
109
|
+
attributes[:src] = adjust_to_asset_host(image.path(converter: options[:renderer]))
|
110
|
+
attributes[:alt] = image[:subject].present? ? image[:subject] : ""
|
111
|
+
[:width, :height].each do |key|
|
112
|
+
if options[key]
|
113
|
+
attributes[key] = options[key]
|
114
|
+
elsif options[key] != false && image.respond_to?(key)
|
115
|
+
attributes[key] = image.send key, options[:renderer].presence || nil
|
116
|
+
end
|
117
|
+
end
|
118
|
+
attributes
|
119
|
+
end
|
120
|
+
|
121
|
+
def link_tag_params(object, options)
|
122
|
+
if object.respond_to?(:path)
|
123
|
+
uri = object.path.gsub(%r{^/website/}, "/")
|
124
|
+
else
|
125
|
+
uri = object
|
126
|
+
end
|
127
|
+
uri = options[:prefix] + uri if options[:prefix]
|
128
|
+
tag_params = { href: uri }
|
129
|
+
tag_params[:class] = options[:class] if options[:class]
|
130
|
+
tag_params[:style] = options[:style] if options[:style]
|
131
|
+
tag_params[:target] = options[:target] if options[:target]
|
132
|
+
tag_params
|
133
|
+
end
|
134
|
+
|
135
|
+
def adjust_to_asset_host(path)
|
136
|
+
asset_host = defined?(compute_asset_host) ? compute_asset_host(path) : nil
|
137
|
+
if asset_host.nil? || !fingerprint_in_asset_path(path)
|
138
|
+
path
|
139
|
+
else
|
140
|
+
"#{asset_host}#{path}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def fingerprint_in_asset_path(path)
|
145
|
+
!!(path && path =~ FINGERPRINT_REGEX)
|
146
|
+
end
|
147
|
+
|
148
|
+
def workspace(options)
|
149
|
+
options[:workspace] || DEFAULT_DOCUMENT_WORKSPACE
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Sinicum
|
3
|
+
module MgnlHelper
|
4
|
+
include HelperUtils
|
5
|
+
|
6
|
+
# Public: Returns the path for an object:
|
7
|
+
#
|
8
|
+
# - If the object is a Node, it returns the path of the node
|
9
|
+
# - If the object is a UUID-String, it is resolved to the Node and the node's path
|
10
|
+
# is returned
|
11
|
+
def mgnl_path(key_or_object, options = {})
|
12
|
+
path = nil
|
13
|
+
object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
|
14
|
+
if object
|
15
|
+
if object.respond_to?(:path)
|
16
|
+
path = object.path
|
17
|
+
path = object.path(converter: options[:renderer]) if options.key?(:renderer)
|
18
|
+
elsif object.is_a?(String)
|
19
|
+
path = object.dup
|
20
|
+
end
|
21
|
+
elsif key_or_object.is_a?(String)
|
22
|
+
path = key_or_object.dup
|
23
|
+
end
|
24
|
+
path
|
25
|
+
end
|
26
|
+
|
27
|
+
def mgnl_link(key_or_object, options = {}, &block)
|
28
|
+
options = options.dup
|
29
|
+
object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
|
30
|
+
object = key_or_object if object.nil? && key_or_object.is_a?(String)
|
31
|
+
if object
|
32
|
+
tag_params = link_tag_params(object, options)
|
33
|
+
if block_given?
|
34
|
+
content_tag(:a, tag_params) do
|
35
|
+
capture(&block)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
content_tag(:a, nil, tag_params)
|
39
|
+
end
|
40
|
+
elsif block && options[:show_content]
|
41
|
+
capture(&block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def mgnl_exists?(key_or_object, options = {})
|
46
|
+
object = object_from_key_or_object(key_or_object, options[:workspace] || "website")
|
47
|
+
!object.nil?
|
48
|
+
end
|
49
|
+
|
50
|
+
def mgnl_push(key_or_object, options = {})
|
51
|
+
workspace = options[:workspace]
|
52
|
+
pushed_content = object_from_key_or_object(key_or_object, workspace)
|
53
|
+
if pushed_content
|
54
|
+
Content::Aggregator.push(pushed_content) do
|
55
|
+
yield
|
56
|
+
end
|
57
|
+
end
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
def mgnl_content_data
|
62
|
+
Content::Aggregator.content_data
|
63
|
+
end
|
64
|
+
|
65
|
+
def mgnl_original_content
|
66
|
+
Content::Aggregator.original_content
|
67
|
+
end
|
68
|
+
|
69
|
+
def mgnl_value(key)
|
70
|
+
value_from_content(Content::Aggregator.content_data, key)
|
71
|
+
end
|
72
|
+
|
73
|
+
def mgnl_out(key, options = {})
|
74
|
+
value = mgnl_value(key)
|
75
|
+
value = "" if value.nil?
|
76
|
+
value = value.to_s
|
77
|
+
if options[:format] == :sanitize
|
78
|
+
value = sanitize(value)
|
79
|
+
elsif options[:format] == :strip_tags
|
80
|
+
value = strip_tags(value)
|
81
|
+
end
|
82
|
+
value.html_safe
|
83
|
+
end
|
84
|
+
|
85
|
+
# Public: Displays the `<title>` tag and the `<meta>` tags for a page. The attributes
|
86
|
+
# must follow the default naming conventions.
|
87
|
+
#
|
88
|
+
# Currently used attributes:
|
89
|
+
#
|
90
|
+
# * title
|
91
|
+
# * meta_title
|
92
|
+
# * meta_description
|
93
|
+
# * meta_keywords
|
94
|
+
# * meta_noindex
|
95
|
+
# * meta_search_weight
|
96
|
+
# * meta_search_boost
|
97
|
+
#
|
98
|
+
# Returns a String with all necessary `<meta>` tags and the `<title>` tag.
|
99
|
+
def mgnl_meta(options = {})
|
100
|
+
result = tag(
|
101
|
+
:meta, :'http-equiv' => 'content-type', 'content' => 'text/html; charset=utf-8')
|
102
|
+
result << "\n"
|
103
|
+
result << meta_content_tag(options)
|
104
|
+
result << "\n"
|
105
|
+
result << meta_simple_meta_tag(:description, :meta_description)
|
106
|
+
result << meta_simple_meta_tag(:keywords, :meta_keywords)
|
107
|
+
result << meta_simple_meta_tag(:'X-Search-Weight', :meta_keywords)
|
108
|
+
result << meta_simple_meta_tag(:'X-Search-Boost', :meta_search_boost)
|
109
|
+
if meta_tag_value(:meta_noindex) || meta_tag_value(:robots) == 'false'
|
110
|
+
result << meta_simple_meta_tag(:robots, 'noindex, nofollow')
|
111
|
+
end
|
112
|
+
result << meta_simple_meta_tag(:language, I18n.locale.to_s)
|
113
|
+
result << meta_simple_meta_tag(:'DC.language', I18n.locale.to_s)
|
114
|
+
result.html_safe
|
115
|
+
end
|
116
|
+
|
117
|
+
# Public: Iterates over an array with NavigationElement instances.
|
118
|
+
#
|
119
|
+
# base_node_or_path - The node or the path that should be the base of the
|
120
|
+
# navigation
|
121
|
+
# type - Type of the navigation. Currently supports only
|
122
|
+
# `:children`.
|
123
|
+
# options - Options for the navigation:
|
124
|
+
# :depth - The depth of a `children` based navigation.
|
125
|
+
# block - The block with the content of the navigation. It
|
126
|
+
# yields with an instance of a NavigationElement.
|
127
|
+
def mgnl_navigation(base_node_or_path, type, options = {}, &block)
|
128
|
+
elements = []
|
129
|
+
if type == :children
|
130
|
+
handler = Navigation::NavigationHandler.children(base_node_or_path, options[:depth])
|
131
|
+
elements = handler.elements
|
132
|
+
elsif type == :parents
|
133
|
+
handler = Navigation::NavigationHandler.parents(base_node_or_path)
|
134
|
+
elements = handler.elements
|
135
|
+
end
|
136
|
+
if block_given?
|
137
|
+
elements.each do |element, status|
|
138
|
+
block.call(element, status)
|
139
|
+
end
|
140
|
+
else
|
141
|
+
elements
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Sinicum
|
3
|
+
module MgnlImageHelper
|
4
|
+
include HelperUtils
|
5
|
+
|
6
|
+
def mgnl_asset_path(key_or_object = nil, options = {})
|
7
|
+
options[:workspace] = "dam"
|
8
|
+
mgnl_path(key_or_object, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def mgnl_img(key_or_object, options = {})
|
12
|
+
image = object_from_key_or_object(key_or_object, workspace(options))
|
13
|
+
result = nil
|
14
|
+
if image
|
15
|
+
options = options.dup
|
16
|
+
attributes = image_attributes(image, options)
|
17
|
+
[:workspace, :renderer, :width, :height, :src, :alt].each do |attribute|
|
18
|
+
options.delete(attribute)
|
19
|
+
end
|
20
|
+
add_missing_attributes(attributes, options)
|
21
|
+
result = tag("img", attributes)
|
22
|
+
end
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
module Sinicum
|
2
|
+
module TaglibHelper5
|
3
|
+
include Templating::TemplatingUtils
|
4
|
+
|
5
|
+
def mgnl_init
|
6
|
+
return unless mgnl_render_bars
|
7
|
+
result = "<!-- begin js and css added by @cms.init -->\n"
|
8
|
+
result << content_tag(:meta, nil, name: "gwt:property", content: "locale=en") + "\n"
|
9
|
+
result << comment_tag(
|
10
|
+
:'cms:page',
|
11
|
+
nil,
|
12
|
+
content: component_path(mgnl_original_content.jcr_workspace, mgnl_original_content.path),
|
13
|
+
dialog: dialog_for_node(mgnl_original_content),
|
14
|
+
preview: mgnl_preview_mode)
|
15
|
+
result << "\n"
|
16
|
+
|
17
|
+
result << "<!-- end js and css added by @cms.init -->"
|
18
|
+
|
19
|
+
result.html_safe
|
20
|
+
end
|
21
|
+
|
22
|
+
def mgnl_area(name, options = {})
|
23
|
+
area_name = name
|
24
|
+
result = nil
|
25
|
+
if area_name.present?
|
26
|
+
available_components = initialize_area(mgnl_content_data, area_name)
|
27
|
+
if available_components
|
28
|
+
result = mgnl_comment_tag(
|
29
|
+
:'cms:area',
|
30
|
+
content: "#{mgnl_content_data.jcr_workspace}:#{mgnl_content_data.jcr_path}/" \
|
31
|
+
"#{area_name}",
|
32
|
+
name: area_name,
|
33
|
+
availableComponents: available_components.join(","),
|
34
|
+
type: "list",
|
35
|
+
label: area_name,
|
36
|
+
inherit: "false",
|
37
|
+
optional: "false",
|
38
|
+
showAddButton: "true",
|
39
|
+
showNewComponentArea: "true",
|
40
|
+
description: area_name) do
|
41
|
+
mgnl_render_component(area_name.to_sym, options)
|
42
|
+
end
|
43
|
+
result = result.html_safe if result
|
44
|
+
elsif !mgnl_render_bars
|
45
|
+
result = mgnl_render_component(area_name.to_sym, options)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
result
|
49
|
+
end
|
50
|
+
|
51
|
+
def mgnl_components
|
52
|
+
mgnl_content_data.children
|
53
|
+
end
|
54
|
+
|
55
|
+
def mgnl_render_component(key_or_object, options = {})
|
56
|
+
result = nil
|
57
|
+
node = object_from_key_or_object(key_or_object)
|
58
|
+
if node
|
59
|
+
mgnl_push(node) do
|
60
|
+
if node.jcr_primary_type == "mgnl:component" && mgnl_render_bars
|
61
|
+
result = mgnl_comment_tag(
|
62
|
+
:'cms:component',
|
63
|
+
content: "#{node.jcr_workspace}:#{node.jcr_path}",
|
64
|
+
dialog: dialog_for_node(node),
|
65
|
+
label: node.mgnl_template) do
|
66
|
+
begin
|
67
|
+
render create_render_params(node, options)
|
68
|
+
rescue ActionView::MissingTemplate => e
|
69
|
+
render_missing_template(node, e)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
result = result.html_safe
|
73
|
+
else
|
74
|
+
begin
|
75
|
+
result = render create_render_params(node, options)
|
76
|
+
rescue ActionView::MissingTemplate => e
|
77
|
+
result = render_missing_template(node, e)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
result
|
83
|
+
end
|
84
|
+
|
85
|
+
def mgnl_render_bars
|
86
|
+
request.headers["HTTP_X_MGNL_ADMIN"].present? && !Rails.env.production?
|
87
|
+
end
|
88
|
+
|
89
|
+
def mgnl_preview_mode
|
90
|
+
request.headers["HTTP_X_MGNL_PREVIEW"] == "true" || !mgnl_render_bars
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def render_missing_template(node, error)
|
96
|
+
type = node.jcr_primary_type == "mgnl:area" ? "area" : "component"
|
97
|
+
unless Rails.env.production?
|
98
|
+
content_tag(:div, nil, class: "mgnl-missing-template-error") do
|
99
|
+
content_tag(:p, nil, class: "mgnl-message") do
|
100
|
+
"Missing partial for #{type} ".html_safe +
|
101
|
+
content_tag(:code) do
|
102
|
+
node.mgnl_template.presence || node.jcr_name
|
103
|
+
end + "."
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def create_render_params(node, options)
|
110
|
+
params = { partial: partial_name_for_node(node) }
|
111
|
+
params[:locals] = options[:locals] if options.key?(:locals)
|
112
|
+
params
|
113
|
+
end
|
114
|
+
|
115
|
+
def partial_name_for_node(node)
|
116
|
+
partial_name = nil
|
117
|
+
if node
|
118
|
+
if node.mgnl_template
|
119
|
+
partial_name = node.mgnl_template.gsub(":", "/")
|
120
|
+
elsif node.jcr_primary_type == "mgnl:area"
|
121
|
+
partial_name = "areas/#{node.jcr_name}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
partial_name = "mgnl/" + partial_name if partial_name
|
125
|
+
partial_name
|
126
|
+
end
|
127
|
+
|
128
|
+
def dialog_for_node(node)
|
129
|
+
@dialog_resolver ||= Templating::DialogResolver.new
|
130
|
+
@dialog_resolver.dialog_for_node(node)
|
131
|
+
end
|
132
|
+
|
133
|
+
def comment_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
134
|
+
result = content_tag(name, content_or_options_with_block, options, escape, &block)
|
135
|
+
result.gsub!("<", "<!-- ")
|
136
|
+
result.gsub!(">", " -->\n")
|
137
|
+
result
|
138
|
+
end
|
139
|
+
|
140
|
+
def initialize_area(base_node, area_name)
|
141
|
+
if mgnl_render_bars
|
142
|
+
@area_handler ||= Templating::AreaHandler.new
|
143
|
+
@area_handler.lookup_or_create_area(base_node, area_name)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def mgnl_comment_tag(tag, options = {}, &block)
|
148
|
+
return yield if mgnl_preview_mode
|
149
|
+
result = "<!-- "
|
150
|
+
result << tag.to_s
|
151
|
+
options.each do |key, value|
|
152
|
+
result << " #{escape_once(key.to_s)}=\"#{escape_once(value.to_s)}\""
|
153
|
+
end
|
154
|
+
result << " -->\n"
|
155
|
+
if block_given?
|
156
|
+
yield_result = yield
|
157
|
+
result << yield_result if yield_result.present?
|
158
|
+
end
|
159
|
+
result << "\n<!-- /#{tag} -->"
|
160
|
+
end
|
161
|
+
|
162
|
+
def component_path(component, path)
|
163
|
+
"#{component}:#{path}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|