scrivito_sdk 1.3.0.rc2 → 1.3.0.rc3
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 +4 -4
- data/app/controllers/scrivito/legacy_redirect_controller.rb +2 -2
- data/config/ca-bundle.crt +1 -1
- data/lib/scrivito/basic_obj.rb +2 -0
- data/lib/scrivito/basic_widget.rb +1 -0
- data/lib/scrivito/class_collection.rb +1 -1
- data/lib/scrivito/cms_routing.rb +8 -22
- data/lib/scrivito/model_library.rb +34 -40
- data/lib/scrivito/route.rb +37 -13
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a53aae675467a88a901cfd6f35149cecc24675
|
4
|
+
data.tar.gz: 4ef81f19d941b658384eadee4a05e48bd397e76a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aabab6cdfa1f2e604b0348ea796080b879277f7140e1d6ca8404dd38b16377c1d236776766b0c43f708f943f756e638ac93d5a72dba07606c00c10e121845a57
|
7
|
+
data.tar.gz: f471c6fdac76c0729e572b976b5cda86b92ce59cc247846739e30430f55919df4636eadfa778e196b1e6cab5d7aec773b1cc185040517c8cca8ed8d93d6c066b
|
@@ -4,8 +4,8 @@ module Scrivito
|
|
4
4
|
include Rails.application.routes.url_helpers
|
5
5
|
|
6
6
|
def index
|
7
|
-
route = Route.find(
|
8
|
-
redirect_to route.generate_path(
|
7
|
+
route = Route.find(self, :slug_id)
|
8
|
+
redirect_to route.generate_path(params.slice(:id, :slug).symbolize_keys)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
end
|
data/config/ca-bundle.crt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
##
|
2
2
|
## Bundle of CA Root Certificates
|
3
3
|
##
|
4
|
-
## Certificate data from Mozilla as of:
|
4
|
+
## Certificate data from Mozilla as of: Wed May 4 10:04:08 2016
|
5
5
|
##
|
6
6
|
## This is a bundle of X.509 certificates of public Certificate Authorities
|
7
7
|
## (CA). These were automatically extracted from Mozilla's root certificates
|
data/lib/scrivito/basic_obj.rb
CHANGED
data/lib/scrivito/cms_routing.rb
CHANGED
@@ -77,15 +77,15 @@ class CmsRouting < Struct.new(:request, :context, :scrivito_engine, :image_optio
|
|
77
77
|
|
78
78
|
def path_or_url_for_objs(obj, path_or_url, options)
|
79
79
|
permalink = obj.permalink
|
80
|
-
if permalink &&
|
81
|
-
|
82
|
-
elsif homepage?(obj) &&
|
83
|
-
|
80
|
+
if permalink && (route = find_route(:permalink)) && permalink.split('/').first != 'scrivito'
|
81
|
+
route.generate(path_or_url, options.merge(:permalink => permalink))
|
82
|
+
elsif homepage?(obj) && route = find_route(:homepage)
|
83
|
+
route.generate(path_or_url, options)
|
84
84
|
elsif obj.binary?
|
85
85
|
binary_obj_url(obj) || LINK_TO_EMPTY_BLOB
|
86
|
-
elsif
|
86
|
+
elsif route = find_route(:slug_id)
|
87
87
|
slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
|
88
|
-
|
88
|
+
route.generate(path_or_url, options.merge(id: obj.id, slug: slug))
|
89
89
|
else
|
90
90
|
raise ScrivitoError, "The required scrivito route 'slug_id' is not defined. "\
|
91
91
|
"Please add a 'slug_id' definition to your routes.rb. See the documentation"\
|
@@ -93,22 +93,8 @@ class CmsRouting < Struct.new(:request, :context, :scrivito_engine, :image_optio
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def
|
97
|
-
|
98
|
-
|
99
|
-
# Options must have the key slug.
|
100
|
-
# Otherwise Rails will use the slug from current request params.
|
101
|
-
options[:slug] ||= nil
|
102
|
-
|
103
|
-
use_route(:slug_id, path_or_url, options)
|
104
|
-
end
|
105
|
-
|
106
|
-
def route_defined?(name)
|
107
|
-
Route.defined?(context._routes, name)
|
108
|
-
end
|
109
|
-
|
110
|
-
def use_route(name, path_or_url, options)
|
111
|
-
Route.find(context._routes, name).generate(context, path_or_url, options)
|
96
|
+
def find_route(name)
|
97
|
+
Route.find(context, name)
|
112
98
|
end
|
113
99
|
|
114
100
|
def homepage?(obj)
|
@@ -20,10 +20,11 @@ class ModelLibrary
|
|
20
20
|
# @see Scrivito.models
|
21
21
|
#
|
22
22
|
def clear_cache
|
23
|
-
@pages
|
24
|
-
@widgets
|
25
|
-
@objs
|
26
|
-
@paths
|
23
|
+
@pages = nil
|
24
|
+
@widgets = nil
|
25
|
+
@objs = nil
|
26
|
+
@paths = nil
|
27
|
+
@require_dependencies = nil
|
27
28
|
end
|
28
29
|
|
29
30
|
#
|
@@ -44,7 +45,7 @@ class ModelLibrary
|
|
44
45
|
# @return [Scrivito::ClassCollection] available page classes
|
45
46
|
#
|
46
47
|
def pages
|
47
|
-
@pages ||=
|
48
|
+
@pages ||= build_class_collection { valid_page_classes }
|
48
49
|
end
|
49
50
|
|
50
51
|
#
|
@@ -55,7 +56,7 @@ class ModelLibrary
|
|
55
56
|
# @return [Scrivito::ClassCollection] available widget classes
|
56
57
|
#
|
57
58
|
def widgets
|
58
|
-
@widgets ||=
|
59
|
+
@widgets ||= build_class_collection { valid_widget_classes }
|
59
60
|
end
|
60
61
|
|
61
62
|
#
|
@@ -66,15 +67,7 @@ class ModelLibrary
|
|
66
67
|
# @return [Scrivito::ClassCollection] available CMS object classes
|
67
68
|
#
|
68
69
|
def objs
|
69
|
-
@objs ||=
|
70
|
-
end
|
71
|
-
|
72
|
-
def load_obj_models
|
73
|
-
base_class = Scrivito::BasicObj
|
74
|
-
model_classes = load_models_from_paths('obj', base_class) +
|
75
|
-
load_custom_models('obj', base_class) +
|
76
|
-
load_custom_models('page', base_class)
|
77
|
-
ClassCollection.new(model_classes)
|
70
|
+
@objs ||= build_class_collection { BasicObj.descendants.select(&:name) }
|
78
71
|
end
|
79
72
|
|
80
73
|
#
|
@@ -90,41 +83,42 @@ class ModelLibrary
|
|
90
83
|
|
91
84
|
private
|
92
85
|
|
93
|
-
def
|
94
|
-
|
95
|
-
ClassCollection.new(
|
86
|
+
def build_class_collection
|
87
|
+
require_dependencies
|
88
|
+
ClassCollection.new(yield)
|
96
89
|
end
|
97
90
|
|
98
|
-
def
|
99
|
-
|
91
|
+
def valid_widget_classes
|
92
|
+
BasicWidget.descendants.select { |descendant| valid_widget_class?(descendant) }
|
100
93
|
end
|
101
94
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
95
|
+
def valid_widget_class?(model_class)
|
96
|
+
model_class = model_class.to_s
|
97
|
+
return true if custom_widgets.include?(model_class)
|
98
|
+
|
99
|
+
model_class != 'Widget' && model_class.ends_with?('Widget')
|
106
100
|
end
|
107
101
|
|
108
|
-
def
|
109
|
-
|
110
|
-
case type
|
111
|
-
when 'page' then file_path.ends_with?('page.rb')
|
112
|
-
when 'widget' then file_path.ends_with?('_widget.rb')
|
113
|
-
else true
|
114
|
-
end
|
115
|
-
end
|
102
|
+
def valid_page_classes
|
103
|
+
BasicObj.descendants.select { |descendant| valid_page_class?(descendant) }
|
116
104
|
end
|
117
105
|
|
118
|
-
def
|
119
|
-
model_class =
|
120
|
-
model_class
|
121
|
-
rescue LoadError
|
122
|
-
# Ignore files with invalid models, e.g. empty files.
|
106
|
+
def valid_page_class?(model_class)
|
107
|
+
model_class = model_class.to_s
|
108
|
+
model_class.downcase.ends_with?('page') || custom_pages.include?(model_class)
|
123
109
|
end
|
124
110
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
111
|
+
def require_dependencies
|
112
|
+
@require_dependencies ||= begin
|
113
|
+
paths.each do |path|
|
114
|
+
Dir["#{path}/**/*.rb"].sort.each do |file_path|
|
115
|
+
begin
|
116
|
+
require_dependency(file_path)
|
117
|
+
rescue TypeError => e
|
118
|
+
raise e if file_path.starts_with?(Rails.root.to_s)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
128
122
|
end
|
129
123
|
end
|
130
124
|
|
data/lib/scrivito/route.rb
CHANGED
@@ -10,12 +10,16 @@ class Route
|
|
10
10
|
registry(route_set)[name] = new(name)
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
13
|
+
def find(given_context, name)
|
14
|
+
available_contexts(given_context).each do |context|
|
15
|
+
route = registry(context._routes)[name]
|
16
|
+
|
17
|
+
if route && route.defined_in?(context)
|
18
|
+
return route.apply_to(context)
|
19
|
+
end
|
20
|
+
end
|
16
21
|
|
17
|
-
|
18
|
-
registry(route_set)[name] or raise InternalError, "route #{name} not found"
|
22
|
+
nil
|
19
23
|
end
|
20
24
|
|
21
25
|
private
|
@@ -32,6 +36,13 @@ class Route
|
|
32
36
|
%("#{name}" is not a valid scrivito route name. Valid values are: #{valid_values}.)
|
33
37
|
end
|
34
38
|
end
|
39
|
+
|
40
|
+
def available_contexts(context)
|
41
|
+
[
|
42
|
+
context,
|
43
|
+
context.try(:main_app)
|
44
|
+
].compact
|
45
|
+
end
|
35
46
|
end
|
36
47
|
|
37
48
|
def initialize(name)
|
@@ -41,20 +52,33 @@ class Route
|
|
41
52
|
def helper_name
|
42
53
|
# use a random name to prevent users from getting the idea
|
43
54
|
# that the internally unsed routing helpers might be a stable API
|
44
|
-
|
45
|
-
|
55
|
+
@helper_name ||=
|
56
|
+
begin
|
57
|
+
random_segment = Digest::SHA1.hexdigest(@name.to_s)[0..15]
|
58
|
+
"scrivito_#{random_segment}"
|
59
|
+
end
|
46
60
|
end
|
47
61
|
|
48
|
-
def
|
49
|
-
|
62
|
+
def defined_in?(context)
|
63
|
+
context.respond_to?("#{helper_name}_path")
|
50
64
|
end
|
51
65
|
|
52
|
-
def
|
53
|
-
|
66
|
+
def apply_to(context)
|
67
|
+
RouteApplication.new(self, context)
|
54
68
|
end
|
55
69
|
|
56
|
-
|
57
|
-
|
70
|
+
class RouteApplication < Struct.new(:route, :context)
|
71
|
+
def generate_path(options = {})
|
72
|
+
generate(:path, options)
|
73
|
+
end
|
74
|
+
|
75
|
+
def generate_url(options = {})
|
76
|
+
generate(:url, options)
|
77
|
+
end
|
78
|
+
|
79
|
+
def generate(path_or_url, options = {})
|
80
|
+
context.public_send("#{route.helper_name}_#{path_or_url}", options)
|
81
|
+
end
|
58
82
|
end
|
59
83
|
|
60
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scrivito_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.0.
|
4
|
+
version: 1.3.0.rc3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Infopark AG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04
|
11
|
+
date: 2016-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|