sinicum 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,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
|