scrivito_sdk 1.3.0.rc2 → 1.3.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d1442e15679c332992fb3c8af22db2aa2beea44
4
- data.tar.gz: 15f40e970f9aee7630120ac34475d2328d5bcb61
3
+ metadata.gz: d1a53aae675467a88a901cfd6f35149cecc24675
4
+ data.tar.gz: 4ef81f19d941b658384eadee4a05e48bd397e76a
5
5
  SHA512:
6
- metadata.gz: 2bc8d4fbb380f8d4b39947725691e79aacc9b125895065a6f0e2d6181f059645a042a1896a3c5b94797f4b3c550fe019bae774f910f7b5f1a7430031c6b20060
7
- data.tar.gz: 455a1d78a551fc3e9a6c9db9385220475906fc63c41e47bd736039c8684f12465f06246ea3f463bfab9dad6e87012ab17d3ec9bc909b7fcc175a3602434c7614
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(_routes, :slug_id)
8
- redirect_to route.generate_path(self, params.slice(:id, :slug).symbolize_keys)
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: Thu Apr 28 10:37:42 2016
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
@@ -20,6 +20,8 @@ module Scrivito
20
20
  # @api public
21
21
  #
22
22
  class BasicObj
23
+ extend ::ActiveSupport::DescendantsTracker
24
+
23
25
  PublicSystemAttributeDefinition = Class.new(AttributeDefinition)
24
26
 
25
27
  SYSTEM_ATTRIBUTES = AttributeDefinitionCollection.new(
@@ -8,6 +8,7 @@ module Scrivito
8
8
  # @api public
9
9
  class BasicWidget
10
10
  extend AttributeContent::ClassMethods
11
+ extend ::ActiveSupport::DescendantsTracker
11
12
  include AttributeContent
12
13
 
13
14
  def self.type_computer
@@ -7,7 +7,7 @@ class ClassCollection
7
7
  include Enumerable
8
8
 
9
9
  def initialize(classes)
10
- @classes = classes.compact.uniq
10
+ @classes = classes
11
11
  end
12
12
 
13
13
  #
@@ -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 && route_defined?(:permalink) && permalink.split('/').first != 'scrivito'
81
- use_route(:permalink, path_or_url, options.merge(:permalink => permalink))
82
- elsif homepage?(obj) && route_defined?(:homepage)
83
- use_route(:homepage, path_or_url, options)
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 route_defined?(:slug_id)
86
+ elsif route = find_route(:slug_id)
87
87
  slug = obj.slug.present? ? obj.slug.sub(/^\//, '') : nil
88
- id_path_or_url_for_objs(obj, path_or_url, options.merge(slug: slug))
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 id_path_or_url_for_objs(obj, path_or_url, options)
97
- options[:id] = obj.id
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 = nil
24
- @widgets = nil
25
- @objs = nil
26
- @paths = nil
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 ||= load_models('page', Scrivito::BasicObj)
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 ||= load_models('widget', Scrivito::BasicWidget)
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 ||= load_obj_models
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 load_models(type, base_class)
94
- model_classes = load_models_from_paths(type, base_class) + load_custom_models(type, base_class)
95
- ClassCollection.new(model_classes)
86
+ def build_class_collection
87
+ require_dependencies
88
+ ClassCollection.new(yield)
96
89
  end
97
90
 
98
- def load_models_from_paths(type, base_class)
99
- paths.map { |path| load_models_from_path(type, path, base_class) }.flatten
91
+ def valid_widget_classes
92
+ BasicWidget.descendants.select { |descendant| valid_widget_class?(descendant) }
100
93
  end
101
94
 
102
- def load_models_from_path(type, path, base_class)
103
- candidates_from_path(type, path).map do |file_path|
104
- load_model(file_path.gsub(path, '').gsub('.rb', '').camelize, base_class)
105
- end
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 candidates_from_path(type, path)
109
- Dir["#{path}/**/*.rb"].select do |file_path|
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 load_model(class_name, base_class)
119
- model_class = class_name.constantize
120
- model_class if model_class.ancestors.include?(base_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 load_custom_models(type, base_class)
126
- send("custom_#{type}s").map do |class_name|
127
- load_model(class_name, base_class)
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
 
@@ -10,12 +10,16 @@ class Route
10
10
  registry(route_set)[name] = new(name)
11
11
  end
12
12
 
13
- def defined?(route_set, name)
14
- !!registry(route_set)[name]
15
- end
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
- def find(route_set, name)
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
- random_segment = Digest::SHA1.hexdigest(@name.to_s)[0..15]
45
- @helper_name ||= "scrivito_#{random_segment}"
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 generate_path(context, options = {})
49
- generate(context, :path, options)
62
+ def defined_in?(context)
63
+ context.respond_to?("#{helper_name}_path")
50
64
  end
51
65
 
52
- def generate_url(context, options = {})
53
- generate(context, :url, options)
66
+ def apply_to(context)
67
+ RouteApplication.new(self, context)
54
68
  end
55
69
 
56
- def generate(context, path_or_url, options = {})
57
- context.public_send("#{helper_name}_#{path_or_url}", options)
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.rc2
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-28 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable