scrivito_sdk 0.65.2 → 0.66.0.rc1

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.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/binary_redirect_controller.rb +19 -0
  3. data/app/controllers/scrivito/objs_controller.rb +6 -2
  4. data/app/controllers/scrivito/webservice_controller.rb +1 -1
  5. data/app/controllers/scrivito/workspaces_controller.rb +1 -7
  6. data/app/helpers/scrivito_helper.rb +115 -64
  7. data/app/views/scrivito/objs/is_outdated.json.jbuilder +1 -0
  8. data/app/views/scrivito/ui/index.html.erb +1 -0
  9. data/config/ca-bundle.crt +1 -1
  10. data/config/precedence_routes.rb +6 -4
  11. data/config/routes.rb +1 -1
  12. data/lib/assets/images/scrivito/source_too_large.png +0 -0
  13. data/lib/assets/images/scrivito/source_type_invalid.png +0 -0
  14. data/lib/assets/javascripts/scrivito_ui.js +2975 -357
  15. data/lib/assets/stylesheets/scrivito_sdk.css +1 -3
  16. data/lib/assets/stylesheets/scrivito_ui.css +1 -3
  17. data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito_migration.rb +0 -2
  18. data/lib/generators/scrivito/migration/templates/migration.erb +6 -8
  19. data/lib/scrivito/attribute_content.rb +16 -52
  20. data/lib/scrivito/attribute_deserializer.rb +3 -5
  21. data/lib/scrivito/attribute_serializer.rb +42 -45
  22. data/lib/scrivito/backend/content_state_node.rb +71 -19
  23. data/lib/scrivito/backend/index.rb +20 -0
  24. data/lib/scrivito/backend/obj_data_cache.rb +157 -31
  25. data/lib/scrivito/backend/obj_data_from_rest.rb +1 -0
  26. data/lib/scrivito/backend/obj_load.rb +10 -6
  27. data/lib/scrivito/backend/obj_query.rb +2 -1
  28. data/lib/scrivito/backend/parent_path_index.rb +5 -1
  29. data/lib/scrivito/backend/path_index.rb +5 -1
  30. data/lib/scrivito/backend/permalink_index.rb +18 -10
  31. data/lib/scrivito/basic_obj.rb +62 -42
  32. data/lib/scrivito/basic_widget.rb +5 -5
  33. data/lib/scrivito/binary.rb +154 -13
  34. data/lib/scrivito/binary_param_verifier.rb +31 -0
  35. data/lib/scrivito/binary_rewrite.rb +35 -0
  36. data/lib/scrivito/cache_middleware.rb +5 -0
  37. data/lib/scrivito/child_list_tag.rb +3 -3
  38. data/lib/scrivito/cms_backend.rb +89 -57
  39. data/lib/scrivito/cms_data_cache.rb +21 -4
  40. data/lib/scrivito/cms_dispatch_controller.rb +13 -0
  41. data/lib/scrivito/cms_field_tag.rb +16 -3
  42. data/lib/scrivito/cms_rest_api.rb +2 -2
  43. data/lib/scrivito/cms_routing.rb +41 -18
  44. data/lib/scrivito/configuration.rb +22 -0
  45. data/lib/scrivito/content_state.rb +1 -9
  46. data/lib/scrivito/content_state_caching.rb +0 -20
  47. data/lib/scrivito/controller_actions.rb +3 -2
  48. data/lib/scrivito/controller_runtime.rb +16 -8
  49. data/lib/scrivito/dialog_size_helper.rb +11 -0
  50. data/lib/scrivito/diff.rb +0 -2
  51. data/lib/scrivito/editing_context.rb +24 -13
  52. data/lib/scrivito/editing_context_middleware.rb +6 -1
  53. data/lib/scrivito/errors.rb +18 -0
  54. data/lib/scrivito/image_tag.rb +55 -0
  55. data/lib/scrivito/link.rb +12 -0
  56. data/lib/scrivito/membership_collection.rb +3 -2
  57. data/lib/scrivito/migrations/cms_backend.rb +6 -13
  58. data/lib/scrivito/migrations/migrator.rb +2 -23
  59. data/lib/scrivito/migrations/workspace_lock.rb +23 -11
  60. data/lib/scrivito/named_link.rb +1 -1
  61. data/lib/scrivito/obj_collection.rb +1 -1
  62. data/lib/scrivito/obj_data_from_service.rb +0 -7
  63. data/lib/scrivito/obj_search_enumerator.rb +2 -2
  64. data/lib/scrivito/parent_path.rb +9 -0
  65. data/lib/scrivito/routing_helper.rb +2 -2
  66. data/lib/scrivito/user.rb +2 -2
  67. data/lib/scrivito/user_definition.rb +2 -2
  68. data/lib/scrivito/widget_garbage_collection.rb +2 -2
  69. data/lib/scrivito/widget_tag.rb +6 -3
  70. data/lib/scrivito/workspace.rb +60 -41
  71. data/lib/scrivito/workspace_data.rb +40 -4
  72. data/lib/scrivito/workspace_data_from_service.rb +0 -10
  73. data/lib/scrivito_sdk.rb +0 -16
  74. metadata +12 -12
  75. data/lib/scrivito/attribute.rb +0 -152
  76. data/lib/scrivito/attribute_collection.rb +0 -66
  77. data/lib/scrivito/attribute_definition_migrator.rb +0 -188
  78. data/lib/scrivito/cms_rest_api/legacy_attribute_serializer.rb +0 -105
  79. data/lib/scrivito/image_tag_helper.rb +0 -46
  80. data/lib/scrivito/obj_class.rb +0 -258
  81. data/lib/scrivito/obj_class_collection.rb +0 -71
  82. data/lib/scrivito/obj_class_data.rb +0 -37
  83. data/lib/tasks/migrate_attribute_definitions.rake +0 -6
@@ -12,29 +12,65 @@ module Scrivito
12
12
  data_attr_reader :title
13
13
  data_attr_reader :memberships
14
14
  data_attr_reader :revision_id
15
- data_attr_reader :content_state_id
16
- data_attr_reader :uses_obj_classes
17
15
  data_attr_reader :base_revision_id
18
- data_attr_reader :base_content_state_id
16
+
17
+ def content_state_id
18
+ @data["content_state_id"] or raise InternalError
19
+ end
20
+
21
+ def content_state_id?
22
+ @data["content_state_id"].present?
23
+ end
24
+
25
+ def base_content_state_id
26
+ @data["base_content_state_id"] or raise InternalError
27
+ end
28
+
29
+ def base_content_state_id?
30
+ @data["base_content_state_id"].present?
31
+ end
19
32
 
20
33
  def initialize(data)
34
+ raise InternalError unless Hash === data && data["id"].present?
21
35
  @data = data
36
+ assert_no_obj_classes
22
37
  end
23
38
 
24
39
  def store_in_cache
25
40
  CmsDataCache.write_workspace_data(id, to_hash)
26
41
  end
27
42
 
43
+ def content_state
44
+ @content_state ||= ContentState.find_or_create(content_state_id) if content_state_id
45
+ end
46
+
47
+ def base_content_state
48
+ if base_content_state_id
49
+ @base_content_state ||= ContentState.find_or_create(base_content_state_id)
50
+ end
51
+ end
52
+
28
53
  private
29
54
 
55
+ def assert_no_obj_classes
56
+ if @data['uses_obj_classes']
57
+ raise ScrivitoError, "The working copy titled #{title} has ObjClasses, which is no longer "\
58
+ "supported. Please use version 0.60.0 to have CMS-based ObjClasses removed from your "\
59
+ "working copies. See https://scrivito.com/scrivito/obj-class-migration for a "\
60
+ "detailed guide on upgrading."
61
+ end
62
+ end
63
+
30
64
  def to_hash
65
+ base_csid = base_content_state_id? ? base_content_state_id : nil
66
+
31
67
  {
32
68
  'id' => id,
33
69
  'revision_id' => revision_id,
34
70
  'title' => title,
35
71
  'content_state_id' => content_state_id,
36
72
  'base_revision_id' => base_revision_id,
37
- 'base_content_state_id' => base_content_state_id,
73
+ 'base_content_state_id' => base_csid,
38
74
  'memberships' => memberships,
39
75
  }
40
76
  end
@@ -32,16 +32,6 @@ class WorkspaceDataFromService < WorkspaceData
32
32
  store_in_cache
33
33
  end
34
34
 
35
- def content_state
36
- @content_state ||= ContentState.find_or_create(content_state_id) if content_state_id
37
- end
38
-
39
- def base_content_state
40
- if base_content_state_id
41
- @base_content_state ||= ContentState.find_or_create(base_content_state_id)
42
- end
43
- end
44
-
45
35
  private
46
36
 
47
37
  def create_content_state
@@ -123,22 +123,6 @@ module Scrivito
123
123
  end
124
124
  end
125
125
 
126
- def self.obj_class_deprecated_message
127
- %{
128
- The SDK now allows defining classes and attributes directly in your application source code.
129
- Please run the migration tool to have your model migrated automatically in order to use this version of the SDK.
130
- See https://scrivito.com/obj-class-migration for details.
131
- }
132
- end
133
-
134
- def self.raise_obj_class_deprecated_error
135
- raise ScrivitoError, obj_class_deprecated_message
136
- end
137
-
138
- def self.print_obj_class_deprecated_warning
139
- Deprecation.warn(obj_class_deprecated_message)
140
- end
141
-
142
126
  autoload_all_sources
143
127
  end
144
128
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.65.2
4
+ version: 0.66.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infopark AG
@@ -172,6 +172,7 @@ extra_rdoc_files: []
172
172
  files:
173
173
  - ".yardopts"
174
174
  - README.md
175
+ - app/controllers/scrivito/binary_redirect_controller.rb
175
176
  - app/controllers/scrivito/blobs_controller.rb
176
177
  - app/controllers/scrivito/default_cms_controller.rb
177
178
  - app/controllers/scrivito/objs_controller.rb
@@ -192,6 +193,7 @@ files:
192
193
  - app/views/scrivito/objs/create_widget.html.erb
193
194
  - app/views/scrivito/objs/destroy.json.jbuilder
194
195
  - app/views/scrivito/objs/format_missing_error.json.jbuilder
196
+ - app/views/scrivito/objs/is_outdated.json.jbuilder
195
197
  - app/views/scrivito/objs/obj.json.jbuilder
196
198
  - app/views/scrivito/objs/page_class_selection.json.jbuilder
197
199
  - app/views/scrivito/objs/search.json.jbuilder
@@ -222,6 +224,8 @@ files:
222
224
  - config/precedence_routes.rb
223
225
  - config/routes.rb
224
226
  - lib/assets/images/scrivito/image_placeholder.png
227
+ - lib/assets/images/scrivito/source_too_large.png
228
+ - lib/assets/images/scrivito/source_type_invalid.png
225
229
  - lib/assets/javascripts/scrivito_sdk.js
226
230
  - lib/assets/javascripts/scrivito_ui.js
227
231
  - lib/assets/stylesheets/scrivito_sdk.css
@@ -267,12 +271,9 @@ files:
267
271
  - lib/generators/scrivito/widget/widget_generator.rb
268
272
  - lib/obj.rb
269
273
  - lib/scrivito/access_denied.rb
270
- - lib/scrivito/attribute.rb
271
- - lib/scrivito/attribute_collection.rb
272
274
  - lib/scrivito/attribute_content.rb
273
275
  - lib/scrivito/attribute_definition.rb
274
276
  - lib/scrivito/attribute_definition_collection.rb
275
- - lib/scrivito/attribute_definition_migrator.rb
276
277
  - lib/scrivito/attribute_deserializer.rb
277
278
  - lib/scrivito/attribute_serializer.rb
278
279
  - lib/scrivito/backend/content_state_node.rb
@@ -288,6 +289,8 @@ files:
288
289
  - lib/scrivito/basic_obj.rb
289
290
  - lib/scrivito/basic_widget.rb
290
291
  - lib/scrivito/binary.rb
292
+ - lib/scrivito/binary_param_verifier.rb
293
+ - lib/scrivito/binary_rewrite.rb
291
294
  - lib/scrivito/cache.rb
292
295
  - lib/scrivito/cache/chainable.rb
293
296
  - lib/scrivito/cache/file_store.rb
@@ -304,7 +307,6 @@ files:
304
307
  - lib/scrivito/cms_env.rb
305
308
  - lib/scrivito/cms_field_tag.rb
306
309
  - lib/scrivito/cms_rest_api.rb
307
- - lib/scrivito/cms_rest_api/legacy_attribute_serializer.rb
308
310
  - lib/scrivito/cms_rest_api/rate_limit.rb
309
311
  - lib/scrivito/cms_rest_api/widget_extractor.rb
310
312
  - lib/scrivito/cms_routing.rb
@@ -321,6 +323,7 @@ files:
321
323
  - lib/scrivito/controller_runtime.rb
322
324
  - lib/scrivito/date_attribute.rb
323
325
  - lib/scrivito/deprecation.rb
326
+ - lib/scrivito/dialog_size_helper.rb
324
327
  - lib/scrivito/diff.rb
325
328
  - lib/scrivito/editing_context.rb
326
329
  - lib/scrivito/editing_context_helper.rb
@@ -328,7 +331,7 @@ files:
328
331
  - lib/scrivito/errors.rb
329
332
  - lib/scrivito/gem_info.rb
330
333
  - lib/scrivito/html_string.rb
331
- - lib/scrivito/image_tag_helper.rb
334
+ - lib/scrivito/image_tag.rb
332
335
  - lib/scrivito/layout_tags.rb
333
336
  - lib/scrivito/link.rb
334
337
  - lib/scrivito/link_parser.rb
@@ -347,9 +350,6 @@ files:
347
350
  - lib/scrivito/modification.rb
348
351
  - lib/scrivito/named_link.rb
349
352
  - lib/scrivito/network_error.rb
350
- - lib/scrivito/obj_class.rb
351
- - lib/scrivito/obj_class_collection.rb
352
- - lib/scrivito/obj_class_data.rb
353
353
  - lib/scrivito/obj_collection.rb
354
354
  - lib/scrivito/obj_create_params_parser.rb
355
355
  - lib/scrivito/obj_data.rb
@@ -359,6 +359,7 @@ files:
359
359
  - lib/scrivito/obj_search_builder.rb
360
360
  - lib/scrivito/obj_search_enumerator.rb
361
361
  - lib/scrivito/obj_update_params_parser.rb
362
+ - lib/scrivito/parent_path.rb
362
363
  - lib/scrivito/rate_limit_exceeded.rb
363
364
  - lib/scrivito/restriction_set.rb
364
365
  - lib/scrivito/revision.rb
@@ -383,7 +384,6 @@ files:
383
384
  - lib/scrivito/workspace_selection_middleware.rb
384
385
  - lib/scrivito_sdk.rb
385
386
  - lib/tasks/cache.rake
386
- - lib/tasks/migrate_attribute_definitions.rake
387
387
  - lib/tasks/migration.rake
388
388
  - lib/widget.rb
389
389
  homepage: https://scrivito.com
@@ -401,9 +401,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
401
401
  version: 2.1.0
402
402
  required_rubygems_version: !ruby/object:Gem::Requirement
403
403
  requirements:
404
- - - ">="
404
+ - - ">"
405
405
  - !ruby/object:Gem::Version
406
- version: '0'
406
+ version: 1.3.1
407
407
  requirements: []
408
408
  rubyforge_project:
409
409
  rubygems_version: 2.4.5
@@ -1,152 +0,0 @@
1
- module Scrivito
2
- # This class represents a CMS attribute. Attributes can be created, updated, deleted and all
3
- # attribute properties can be read. Attributes are part of an
4
- # {Scrivito::ObjClass} and therefore each attribute belongs to exactly
5
- # one {Scrivito::ObjClass}. Most of the operations interact with the currently
6
- # selected {Scrivito::Workspace}. Operations like +create+, +destroy+
7
- # and +update+ need to be performed in the "rtc" workspace.
8
- #
9
- # @api public
10
- # @deprecated
11
- class Attribute
12
- include ModelIdentity
13
-
14
- # Initializes a new attribute.
15
- #
16
- # @api public
17
- # @deprecated
18
- #
19
- # This allows you to set the different properties of an attribute by
20
- # providing a Hash with the property names as keys and the values you want to set as values.
21
- #
22
- # @example Create a new attribute with name "locale" and type "string".
23
- # Attribute.new(name: 'locale', type: :string)
24
- #
25
- # @example Create a new "enum" attribute named "category" and provide values.
26
- # Attribute.new(name: 'category', type: :enum, values: %w(tech social))
27
- #
28
- # @param [Hash] properties
29
- # @option properties [String] :name The name of the attribute.
30
- # @option properties [String] :type The type of the attribute, can be +string+, +text+, +html+, +linklist+, +link+, +reference+, +referencelist+, +date+, +binary+, +widget+, +enum+ or +multienum+.
31
- # @option properties [Array<String>] :values Possible values if the type is either +enum+ or +multienum+.
32
- #
33
- # @return [Scrivito::Attribute]
34
- # @raise [Scrivito::ScrivitoError] Raised when no +properties+ are provided.
35
- def initialize(properties)
36
- raise ScrivitoError, 'Please provide a hash of Attribute properties.' unless properties
37
-
38
- update_instance_properties(properties)
39
- end
40
-
41
- # Returns the name of this attribute.
42
- # @api public
43
- # @deprecated
44
- # @return [String]
45
- def name
46
- @name
47
- end
48
-
49
- # Returns the type of this attribute. The type is either +string+, +text+, +html+, +linklist+,
50
- # +link+, +reference+, +referencelist+, +date+, +binary+, +widget+, +enum+ or +multienum+.
51
- # @api public
52
- # @deprecated
53
- # @return [String]
54
- def type
55
- @type
56
- end
57
-
58
- # Returns the values of this attribute, if it is of type +enum+ or +multienum+.
59
- # @api public
60
- # @deprecated
61
- # @return [Array<String>] values
62
- def values
63
- @values
64
- end
65
-
66
- # Returns the obj class this attribute belongs to.
67
- # @api public
68
- # @deprecated
69
- # @return [Scrivito::ObjClass]
70
- attr_reader :obj_class
71
-
72
- # Returns a unique identifier of this attribute. An attribute is unique by
73
- # its +name+ and its +obj_class+. Implements the {Scrivito::ModelIdentity} interface.
74
- # @return [Array]
75
- def id
76
- [name, obj_class]
77
- end
78
-
79
- # Binds this attribute to an obj class.
80
- # @return [Scrivito::ObjClass]
81
- attr_writer :obj_class
82
-
83
- # Updates this attribute and persists the changes
84
- # in the CMS on its obj class. The +obj_class+ and +name+ of this attribute can not be updated.
85
- #
86
- # @api public
87
- # @deprecated
88
- #
89
- # See {Attribute#initialize} for a detailed overview of what properties are allowed
90
- # and how to set them.
91
- #
92
- # @example Change the +type+ of the "locale" attribute to "string".
93
- # attribute = ObjClass.find('Homepage').attributes['locale']
94
- # attribute.update(type: :string)
95
- #
96
- # @example Adding the value "sports" to the +enum+ attribute "category" on the "Homepage" obj class.
97
- # attribute = ObjClass.find('Homepage').attributes['category']
98
- # attribute.update(values: attribute.values << 'sports')
99
- #
100
- # @param [Hash] properties
101
- #
102
- # @return [nil]
103
- # @raise [Scrivito::ScrivitoError] Raised when trying to change the +name+ or +obj_class+ property.
104
- def update(properties)
105
- Scrivito.raise_obj_class_deprecated_error
106
- end
107
-
108
- # Destroys this attribute and persists the change in the CMS.
109
- #
110
- # @api public
111
- # @deprecated
112
- #
113
- # @example Remove the "locale" attribute from the "Homepage" obj class.
114
- # ObjClass.find('Homepage').attributes['locale'].destroy
115
- #
116
- # @return [nil]
117
- def destroy
118
- Scrivito.raise_obj_class_deprecated_error
119
- end
120
-
121
- # Returns this attribute in the CMS REST API format.
122
- #
123
- # @return [Hash]
124
- def to_cms_rest_api
125
- data = {
126
- name: name,
127
- type: type,
128
- }
129
-
130
- if %w(enum multienum).include?(type)
131
- data[:values] = values
132
- end
133
-
134
- data
135
- end
136
-
137
- private
138
-
139
- # Updates the instance properties of this attribute with +properties+
140
- # given in the CMS REST API format.
141
- #
142
- # @param [Hash] properties
143
- # @return [void]
144
- def update_instance_properties(properties)
145
- properties = properties.with_indifferent_access
146
-
147
- @name = properties[:name].to_s
148
- @type = properties[:type].to_s
149
- @values = (properties[:values] || []).map(&:to_s)
150
- end
151
- end
152
- end
@@ -1,66 +0,0 @@
1
- module Scrivito
2
- # Represents a collection of {Scrivito::Attribute} instances. It provides convienient ways to
3
- # find and add attributes and is returned by {Scrivito::ObjClass#attributes}. It behaves almost
4
- # exactly as an Array, so methods like `#each`, `#select` etc. are available. It is not necessary
5
- # to manually create an {Scrivito::AttributeCollection}, because a simple Array with attributes
6
- # can be used instead.
7
- #
8
- # @api public
9
- # @deprecated
10
- class AttributeCollection
11
- include Enumerable
12
- extend Forwardable
13
-
14
- # Initializes an attribute collection for an obj class.
15
- #
16
- # @param [Scrivito::ObjClass] obj_class
17
- # @param [Array<Scrivito::Attribute>] attributes
18
- # @return [Scrivito::AttributeCollection]
19
- def initialize(obj_class, attributes)
20
- @obj_class = obj_class
21
- @attributes = attributes
22
- end
23
-
24
- # Yields successive attributes of the collection. Implements the {Enumerable} interface.
25
- # @api public
26
- # @deprecated
27
- def_delegators :@attributes, :each
28
-
29
- #
30
- # Finds an attribute in this collection by its name.
31
- #
32
- # @api public
33
- # @deprecated
34
- #
35
- # @param [String] name the name of the attribute
36
- # @return [Scrivito::Attribute] if there is an attribute with name +name+
37
- # @return [nil] if there is no attribute with name +name+
38
- #
39
- # @see Scrivito::ObjClass#attributes Examples of how to find an attribute by name.
40
- #
41
- def [](name)
42
- @attributes.detect { |attribute| attribute.name == name.to_s }
43
- end
44
-
45
- # Adds an attribute to this collection and updates the obj class.
46
- #
47
- # @api public
48
- # @deprecated
49
- #
50
- # See {Scrivito::ObjClass#attributes} for example of how to add an attribute.
51
- #
52
- # @param [Scrivito::Attribute, Hash] attribute The attribute to add. Can be either an attribute
53
- # instance or an attribute property hash.
54
- # @return [Scrivito::AttributeCollection]
55
- def add(attribute)
56
- attribute = Attribute.new(attribute) unless attribute.respond_to?(:to_cms_rest_api)
57
- @attributes << attribute
58
- @obj_class.update(attributes: @attributes)
59
- self
60
- end
61
- alias_method :<<, :add
62
-
63
- # Deletes all attributes from this collection that are equal to the given attribute.
64
- def_delegators :@attributes, :delete
65
- end
66
- end
@@ -1,188 +0,0 @@
1
- require 'thor'
2
-
3
- module Scrivito
4
-
5
- class AttributeDefinitionMigrator
6
- include Thor::Actions
7
- include Thor::Base
8
- include Thor::Shell
9
-
10
- def initialize(path)
11
- self.destination_root = Rails.root.to_s
12
- self.options = {}
13
- @path = path.to_s
14
- end
15
-
16
- def self.migrate_application
17
- Dir[Rails.root + 'app/models/**/*.rb'].each do |model_path|
18
- new(model_path).migrate
19
- end
20
- check_abandoned_obj_classes
21
- end
22
-
23
- def migrate
24
- relative_path = path.gsub("#{Rails.root.to_s}/", '')
25
- if model_class && (page_model? || widget_model?)
26
- say_status :inspecting, relative_path
27
- if obj_class
28
- say_status :migrating, relative_path
29
- inject_attribute_definitions
30
- inject_hide_from_editor if hidden_from_editor?
31
- check_model_name
32
- else
33
- with_padding do
34
- say %{[warning] Model "#{model_class}" has no corresponding ObjClass in published workspace.
35
- Ignore this message if it is an abstract class and should not have an ObjClass by design.
36
- Or maybe "#{model_class}" is not used anymore and file #{relative_path} can be removed?
37
- }, :yellow
38
- end
39
- say_status :skipping, relative_path
40
- end
41
- puts
42
- end
43
- end
44
-
45
- private
46
-
47
- attr_reader :path
48
-
49
- def model_class
50
- @model_class ||= class_name.constantize
51
- rescue NameError
52
- end
53
-
54
- def page_model?
55
- model_class.ancestors.include?(BasicObj) && model_class != ::Obj
56
- end
57
-
58
- def widget_model?
59
- model_class.ancestors.include?(BasicWidget) && model_class != ::Widget
60
- end
61
-
62
- def inject_hide_from_editor
63
- inject_into_class(path, model_class, " hide_from_editor\n\n")
64
- end
65
-
66
- def inject_attribute_definitions
67
- inject_into_class(path, model_class, "#{attribute_definitions.join}\n", verbose: false)
68
- end
69
-
70
- def hidden_from_editor?
71
- !obj_class.active? || (page_model? && !template_exists?)
72
- end
73
-
74
- def template_exists?
75
- lookup_context.template_exists?("#{class_name.underscore}/thumbnail")
76
- end
77
-
78
- def class_name
79
- @class_name ||= path.gsub(/^.*\/app\/models/, '').gsub('.rb', '').classify
80
- end
81
-
82
- def attribute_definitions
83
- definitions = obj_class_attributes.map do |attr|
84
- attribute_definition = " attribute :#{attr.name}, :#{type_for(attr.name, attr.type)}"
85
- if attr.type == 'enum' || attr.type == 'multienum'
86
- attribute_definition << ", values: #{attr.values.to_s}"
87
- end
88
- attribute_definition << "\n"
89
- end
90
-
91
- if page_model? && obj_class.legacy_type?
92
- definitions << " attribute :title, :string\n"
93
- if obj_class.is_binary
94
- definitions << " attribute :blob, :binary\n"
95
- else
96
- definitions << " attribute :body, :html\n"
97
- end
98
- end
99
-
100
- definitions.uniq
101
- end
102
-
103
- def type_for(name, type)
104
- case type
105
- when 'text' then 'string'
106
- when 'widget' then 'widgetlist'
107
- else type
108
- end
109
- end
110
-
111
- def obj_class_attributes
112
- Workspace.published.as_current do
113
- obj_class.attributes.sort_by(&:name)
114
- end
115
- end
116
-
117
- def lookup_context
118
- ActionView::LookupContext.new(ActionController::Base.view_paths)
119
- end
120
-
121
- def obj_class
122
- @obj_class = ObjClass.find(model_class.name)
123
- rescue Scrivito::ResourceNotFound
124
- end
125
-
126
- def check_model_name
127
- name = model_class.name
128
-
129
- if page_model? && !name.ends_with?('Page')
130
- is_binary = if obj_class.legacy_type?
131
- obj_class.binary?
132
- else
133
- obj_class.attributes.any? { |attr| attr.name == 'blob' && attr.type == 'binary' }
134
- end
135
-
136
- unless is_binary
137
- with_padding do
138
- say %{[warning] The class name of the non-binary obj model "#{name}" does not end with "Page".
139
- Class names of page models should end with "Page" in order to be automatically identified by Scrivito as pages.
140
- Please ignore this warning if "#{name}" is not a page by design.
141
- Otherwise you need to tell Scrivito about this page explicitly. Please add following to an initializer:
142
-
143
- Scrivito.models.define { page "#{name}" }
144
- }, :yellow
145
- end
146
- end
147
- end
148
-
149
- if widget_model? && !name.ends_with?('Widget') &&
150
- Scrivito.models.widgets.none? { |w| w.name == name }
151
- with_padding do
152
- say %{[warning] The class name of the widget model "#{name}" does not end with "Widget".
153
- Class names of widget models should end with "Widget" in order to be automatically identified by Scrivito as widgets.
154
- You need to tell Scrivito about this widget explicitly. Please add following to an initializer:
155
-
156
- Scrivito.models.define { widget "#{name}" }
157
- }, :yellow
158
- end
159
- end
160
- end
161
-
162
- class << self
163
- include Thor::Actions
164
- include Thor::Base
165
- include Thor::Shell
166
-
167
- private
168
-
169
- def check_abandoned_obj_classes
170
- ObjClass.all.each do |obj_class|
171
- next if obj_class.name == 'MigrationStore'
172
- begin
173
- obj_class.name.constantize
174
- rescue NameError
175
- with_padding do
176
- say %{[warning] Could not find a ruby class for ObjClass "#{obj_class.name}".
177
- Plase create a ruby class for that ObjClass and run this script again.
178
-
179
- }, :yellow
180
- end
181
- end
182
- end
183
-
184
- end
185
- end
186
- end
187
-
188
- end