scrivito_sdk 0.18.1 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/scrivito/blobs_controller.rb +1 -2
  3. data/app/controllers/scrivito/default_cms_controller.rb +9 -75
  4. data/app/controllers/scrivito/objs_controller.rb +107 -119
  5. data/app/controllers/scrivito/tasks_controller.rb +1 -1
  6. data/app/controllers/scrivito/users_controller.rb +1 -1
  7. data/app/controllers/scrivito/webservice_controller.rb +6 -2
  8. data/app/controllers/scrivito/workspaces_controller.rb +57 -17
  9. data/app/helpers/scrivito_helper.rb +285 -0
  10. data/app/views/google_maps_widget/show.html.erb +1 -0
  11. data/app/views/scrivito/_editing_auth_warning.html.erb +43 -0
  12. data/app/views/scrivito/blobs/upload_permission.json.jbuilder +1 -0
  13. data/app/views/scrivito/objs/copy.json.jbuilder +1 -0
  14. data/app/views/scrivito/objs/copy_widget.html.erb +1 -1
  15. data/app/views/scrivito/objs/create.json.jbuilder +1 -0
  16. data/app/views/scrivito/objs/create_widget.html.erb +1 -1
  17. data/app/views/scrivito/objs/details.json.jbuilder +1 -0
  18. data/app/views/scrivito/objs/format_missing_error.json.jbuilder +1 -0
  19. data/app/views/scrivito/objs/modification.json.jbuilder +1 -0
  20. data/app/views/scrivito/objs/page_class_selection.json.jbuilder +1 -0
  21. data/app/views/scrivito/objs/search.json.jbuilder +6 -0
  22. data/app/views/scrivito/objs/search_only_size.json.jbuilder +1 -0
  23. data/app/views/scrivito/objs/update.json.jbuilder +1 -0
  24. data/app/views/scrivito/objs/widget_class_selection.json.jbuilder +1 -0
  25. data/app/views/scrivito/objs/widget_modification.json.jbuilder +1 -0
  26. data/app/views/scrivito/tasks/show.json.jbuilder +3 -0
  27. data/app/views/scrivito/users/suggest.json.jbuilder +1 -0
  28. data/app/views/scrivito/webservice/empty.json +1 -0
  29. data/app/views/scrivito/webservice/error.json.jbuilder +2 -0
  30. data/app/views/scrivito/workspaces/_workspace.json.jbuilder +5 -0
  31. data/app/views/scrivito/workspaces/check.json.jbuilder +1 -0
  32. data/app/views/scrivito/workspaces/create.json.jbuilder +1 -0
  33. data/app/views/scrivito/workspaces/index.json.jbuilder +1 -0
  34. data/app/views/scrivito/workspaces/show.json.jbuilder +1 -0
  35. data/app/views/scrivito/workspaces/task.json.jbuilder +5 -0
  36. data/config/ca-bundle.crt +259 -234
  37. data/config/cms_routes.rb +2 -2
  38. data/config/routes.rb +3 -0
  39. data/lib/assets/javascripts/{scrivito_editing.js → scrivito_sdk.js} +1662 -1180
  40. data/lib/assets/stylesheets/{scrivito_editing.css → scrivito_sdk.css} +242 -6
  41. data/lib/generators/scrivito/install/install_generator.rb +62 -0
  42. data/lib/generators/scrivito/install/templates/app/controllers/cms_controller.rb +3 -0
  43. data/lib/generators/scrivito/install/templates/app/controllers/page_controller.rb +2 -0
  44. data/lib/generators/scrivito/install/templates/app/models/headline_widget.rb +7 -0
  45. data/lib/generators/scrivito/install/templates/app/models/image.rb +5 -0
  46. data/lib/generators/scrivito/install/templates/app/models/image_widget.rb +7 -0
  47. data/lib/generators/scrivito/install/templates/app/models/obj.rb +2 -0
  48. data/lib/generators/scrivito/install/templates/app/models/page.rb +8 -0
  49. data/lib/generators/scrivito/install/templates/app/models/text_widget.rb +7 -0
  50. data/lib/generators/scrivito/install/templates/app/models/widget.rb +2 -0
  51. data/lib/generators/scrivito/install/templates/app/views/headline_widget/show.html.erb +1 -0
  52. data/lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb +3 -0
  53. data/lib/generators/scrivito/install/templates/app/views/image_widget/show.html.erb +1 -0
  54. data/lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb +3 -0
  55. data/lib/generators/scrivito/install/templates/app/views/page/details.html.erb +1 -0
  56. data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +16 -0
  57. data/lib/generators/scrivito/install/templates/app/views/page/thumbnail.html.erb +3 -0
  58. data/lib/generators/scrivito/install/templates/app/views/text_widget/show.html.erb +1 -0
  59. data/lib/generators/scrivito/install/templates/app/views/text_widget/thumbnail.html.erb +3 -0
  60. data/lib/generators/scrivito/install/templates/config/initializers/scrivito.rb +10 -0
  61. data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito.rb +49 -0
  62. data/lib/generators/scrivito/migration/USAGE +9 -0
  63. data/lib/generators/{cms → scrivito}/migration/migration_generator.rb +4 -9
  64. data/lib/generators/{cms → scrivito}/migration/templates/migration.erb +3 -3
  65. data/lib/generators/{cms → scrivito}/widget/templates/details.html.erb +0 -0
  66. data/lib/generators/{cms → scrivito}/widget/templates/migration.erb +0 -0
  67. data/lib/generators/{cms → scrivito}/widget/templates/model.erb +0 -0
  68. data/lib/generators/{cms → scrivito}/widget/templates/show.html.erb +0 -0
  69. data/lib/generators/scrivito/widget/templates/thumbnail.html.erb +3 -0
  70. data/lib/generators/{cms → scrivito}/widget/widget_generator.rb +3 -2
  71. data/lib/obj.rb +17 -3
  72. data/lib/scrivito/attribute_collection.rb +7 -12
  73. data/lib/scrivito/attribute_content.rb +31 -12
  74. data/lib/scrivito/basic_obj.rb +186 -96
  75. data/lib/scrivito/basic_widget.rb +25 -10
  76. data/lib/scrivito/binary.rb +75 -0
  77. data/lib/scrivito/cache_garbage_collector.rb +19 -4
  78. data/lib/scrivito/child_list_tag.rb +108 -0
  79. data/lib/scrivito/client_config.rb +2 -1
  80. data/lib/scrivito/client_error.rb +3 -2
  81. data/lib/scrivito/cms_backend.rb +81 -16
  82. data/lib/scrivito/cms_dispatch_controller.rb +7 -0
  83. data/lib/scrivito/cms_env.rb +0 -2
  84. data/lib/scrivito/cms_field_tag.rb +44 -35
  85. data/lib/scrivito/cms_rest_api.rb +23 -6
  86. data/lib/scrivito/cms_rest_api/attribute_serializer.rb +1 -1
  87. data/lib/scrivito/cms_routing.rb +120 -0
  88. data/lib/scrivito/configuration.rb +69 -58
  89. data/lib/scrivito/connection_manager.rb +30 -1
  90. data/lib/scrivito/content_service.rb +10 -7
  91. data/lib/scrivito/controller_actions.rb +108 -0
  92. data/lib/scrivito/diff.rb +30 -15
  93. data/lib/scrivito/editing_context.rb +4 -0
  94. data/lib/scrivito/editing_context_helper.rb +19 -0
  95. data/lib/scrivito/editing_context_middleware.rb +20 -1
  96. data/lib/scrivito/image_tag_helper.rb +44 -0
  97. data/lib/scrivito/layout_tags.rb +33 -0
  98. data/lib/scrivito/link.rb +4 -2
  99. data/lib/scrivito/membership.rb +0 -8
  100. data/lib/scrivito/migrations.rb +0 -1
  101. data/lib/scrivito/migrations/installer.rb +1 -1
  102. data/lib/scrivito/migrations/migration.rb +0 -2
  103. data/lib/scrivito/migrations/migrator.rb +2 -3
  104. data/lib/scrivito/obj_class.rb +64 -16
  105. data/lib/scrivito/obj_class_data.rb +4 -0
  106. data/lib/scrivito/obj_search_enumerator.rb +1 -1
  107. data/lib/scrivito/routing_helper.rb +42 -0
  108. data/lib/scrivito/{engine.rb → sdk_engine.rb} +15 -29
  109. data/lib/scrivito/tag_renderer.rb +40 -0
  110. data/lib/scrivito/test_request.rb +40 -0
  111. data/lib/scrivito/type_computer.rb +1 -6
  112. data/lib/scrivito/user.rb +33 -15
  113. data/lib/scrivito/user_definition.rb +34 -6
  114. data/lib/scrivito/widget_tag.rb +67 -0
  115. data/lib/scrivito/workspace.rb +12 -24
  116. data/lib/scrivito_sdk.rb +17 -1
  117. data/lib/tasks/cache.rake +4 -5
  118. data/lib/tasks/migration.rake +1 -1
  119. data/lib/widget.rb +21 -3
  120. metadata +119 -70
  121. data/README +0 -6
  122. data/app/controllers/cms_controller.rb +0 -7
  123. data/app/helpers/cms_helper.rb +0 -7
  124. data/app/helpers/cms_routing_helper.rb +0 -7
  125. data/app/helpers/scrivito/cms_asset_helper.rb +0 -110
  126. data/app/helpers/scrivito/cms_tag_helper.rb +0 -232
  127. data/app/helpers/scrivito/default_cms_helper.rb +0 -21
  128. data/app/helpers/scrivito/default_cms_routing_helper.rb +0 -128
  129. data/app/helpers/scrivito/display_helper.rb +0 -64
  130. data/app/helpers/scrivito/editing_helper.rb +0 -32
  131. data/app/helpers/scrivito/layout_helper.rb +0 -21
  132. data/app/models/named_link.rb +0 -2
  133. data/app/views/cms/_index.html.erb +0 -7
  134. data/app/views/cms/index.html.erb +0 -1
  135. data/app/views/scrivito/_editing_javascript.html.erb +0 -7
  136. data/app/views/scrivito/default_cms/show_widget.html.erb +0 -1
  137. data/lib/assets/stylesheets/scrivito.css +0 -199
  138. data/lib/generators/cms/migration/USAGE +0 -9
  139. data/lib/generators/cms/widget/templates/thumbnail.html.erb +0 -2
  140. data/lib/scrivito/blob.rb +0 -48
  141. data/lib/scrivito/cms_accessible.rb +0 -30
  142. data/lib/scrivito/cms_rest_api/blob_uploader.rb +0 -18
  143. data/lib/scrivito/cms_test_request.rb +0 -23
  144. data/lib/scrivito/migrations/migration_dsl.rb +0 -180
data/README DELETED
@@ -1,6 +0,0 @@
1
- = Scrivito SDK
2
-
3
- The Scrivito SDK makes CMS objects maintained by means of the cloud-based Scrivito CMS available to your Rails application.
4
- It offers easy-to-use functionality for rendering CMS content, doing searches, etc.
5
-
6
- For more information about Scrivito, please visit {http://scrivito.com/}.
@@ -1,7 +0,0 @@
1
- # This controller inherits all of its behavior from
2
- # {Scrivito::DefaultCmsController}.
3
- #
4
- # {CmsController} is referenced by the Scrivito routes.
5
- # @api public
6
- class CmsController < Scrivito::DefaultCmsController
7
- end
@@ -1,7 +0,0 @@
1
- # {CmsHelper} is a wrapper around {Scrivito::DefaultCmsHelper}.
2
- # It can be replaced in your application in order to add or
3
- # modify helpers.
4
- # @api public
5
- module CmsHelper
6
- include Scrivito::DefaultCmsHelper
7
- end
@@ -1,7 +0,0 @@
1
- # {CmsRoutingHelper} is a wrapper around {Scrivito::DefaultCmsRoutingHelper}.
2
- # It can be replaced in your application in order to add or
3
- # modify helpers.
4
- # @api public
5
- module CmsRoutingHelper
6
- include Scrivito::DefaultCmsRoutingHelper
7
- end
@@ -1,110 +0,0 @@
1
- module Scrivito
2
-
3
- # This module contains helpers that can be used to reference images and other assets stored in the CMS.
4
- #
5
- # @api public
6
- module CmsAssetHelper
7
-
8
- # Calculates an HTML image tag for an image stored in the CMS.
9
- #
10
- # @note There are two different signatures of this method: the first one generates an HTML image tag with no
11
- # inplace editing possible, the second one generated an HTML image tag for inplace editing.
12
- #
13
- # @overload cms_image_tag target, tag_options={}
14
- # @note If you do not specify an HTML +alt+ attribute, the helper method will use +target+'s +display_title+.
15
- # Calculates HTML image tag (no inplace editing possible).
16
- #
17
- # @param [Obj, Link] target Target containing image stored in CMS.
18
- # @param [Hash] tag_options Additional HTML attributes for the tag.
19
- #
20
- # @example
21
- # cms_image_tag @target
22
- # cms_image_tag @target, alt: 'Interesting picture', class: 'my_image'
23
- #
24
- # @overload cms_image_tag obj, linklist, tag_options={}, editing_options={}
25
- # @note If you do not specify an HTML +alt+ attribute, the helper method will use +display_title+ of the target object.
26
- # Calculates HTML image tag for inplace editing.
27
- #
28
- # @param [Obj] obj Obj with an attribute of type +LinkList+.
29
- # @param [String, Symbol] linklist Name of +LinkList+, +reference+ or +link+ attribute, which contains the image.
30
- # @param [Hash] tag_options Additional HTML attributes for the tag.
31
- #
32
- # @param [Hash] editing_options Additional options for inplace editing.
33
- # @option editing_options [String] :placeholder ('/assets/scrivito/image_placeholder.png') URL or path to image to be displayed if target is missing.
34
- #
35
- # @example
36
- # cms_image_tag @obj, :my_linklist
37
- # cms_image_tag @obj, :my_linklist, alt: 'Interesting picture', class: 'my_image'
38
- # cms_image_tag @obj, :my_linklist, {}, placeholder: image_path('my_placeholder.png')
39
- # cms_image_tag @obj, :my_linklist, {class: 'my_image'}, placeholder: 'http://placehold.it/350x150'
40
- #
41
- # @example Create image tag for reference attributes.
42
- # cms_image_tag @obj, :my_reference
43
- #
44
- # @example Create image tag for link attributes.
45
- # cms_image_tag @obj, :my_link
46
- #
47
- # @return [String] HTML image tag
48
- # @api public
49
- def cms_image_tag(*args)
50
- if args.second.nil? || args.second.is_a?(Hash)
51
- # Backwards compatibility.
52
- target = args.first
53
-
54
- tag_options = args.second || {}
55
- tag_options.symbolize_keys!
56
- tag_options[:src] = cms_path(target)
57
- tag_options[:alt] ||= display_title(target)
58
-
59
- tag('img', tag_options)
60
- else
61
- obj = args.first
62
- field_name = args.second
63
- tag_options = args.third || {}
64
- editing_options = args.fourth || {}
65
-
66
- cms_tag('img', obj, field_name, cms_image_tag_options(obj, field_name,
67
- tag_options.symbolize_keys, editing_options.symbolize_keys))
68
- end
69
-
70
- end
71
-
72
- private
73
-
74
- def cms_image_tag_options(obj, field_name, tag_options, editing_options)
75
- tag_options.reverse_merge(src: cms_image_tag_src(obj, field_name, editing_options),
76
- alt: cms_image_tag_alt(obj, field_name))
77
- end
78
-
79
- def cms_image_tag_src(obj, field_name, editing_options)
80
- cms_image_tag_path(obj, field_name) || editing_options[:placeholder] ||
81
- image_path('scrivito/image_placeholder.png')
82
- end
83
-
84
- def cms_image_tag_alt(obj, field_name)
85
- display_title(obj[field_name])
86
- end
87
-
88
- def cms_image_tag_path(obj, field_name)
89
- field_type = obj.type_of_attribute(field_name)
90
- field_value = obj[field_name]
91
-
92
- case field_type
93
- when 'reference' then field_value && cms_path(field_value)
94
- when 'link' then field_value && cms_path(field_value)
95
- when 'linklist'
96
- path = cms_path(field_value)
97
- path == DefaultCmsRoutingHelper::LINK_TO_EMPTY_LINKLIST ? nil : path
98
- end
99
- end
100
-
101
- def display_title(target)
102
- if target.respond_to?(:display_title)
103
- return target.display_title
104
- elsif target.respond_to?(:first) && target.first.respond_to?(:display_title)
105
- return target.first.display_title
106
- end
107
- end
108
-
109
- end
110
- end
@@ -1,232 +0,0 @@
1
- module Scrivito
2
-
3
- # @api public
4
- module CmsTagHelper
5
- VOID_TAGS = %w[area base br col command embed hr img input keygen
6
- link meta param source track wbr]
7
-
8
- # Returns an HTML block tag containing content from an Obj.
9
- # Add HTML attributes by passing an attributes hash to options.
10
- # The helper method is somewhat similar to (and internally uses) http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag.
11
- #
12
- # This helper method also renders additional data attributes, which are needed for inplace editing.
13
- # These attributes are only rendered when appropriate, i.e. not for a regular visitor.
14
- #
15
- # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
16
- # @param obj_or_widget [BasicObj, BasicWidget] A {BasicObj} or {BasicWidget} from which the +field_name+ is read.
17
- # @param field_name [String, Symbol] Which field of the Obj should be rendered.
18
- # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
19
- # @param block [Proc] Optional block to render inner HTML. If none given the value of attribute will be rendered instead.
20
- # @return [String] The rendered html tag
21
- #
22
- # @example Renders an <h2> tag containing the text of the +headline+ attribute of +@obj+ and assigns the tag a css class called +very_important+.
23
- # <%= cms_tag :h2, @obj, :headline, class: "very_important" %>
24
- #
25
- # @example Renders an <h2> tag containing an escaped +headline+.
26
- # <%= cms_tag :h2, @obj, :headline do %>
27
- # <%= strip_tags @obj.headline %>
28
- # <% end %>
29
- #
30
- # @api public
31
- def cms_tag(tag_name, obj_or_widget, field_name, options = {}, &block)
32
- cms_field_tag = CmsFieldTag.new(
33
- self, cms_editing_context, obj_or_widget, field_name.to_s
34
- )
35
-
36
- begin
37
- field_type = cms_field_tag.field_type
38
- rescue ScrivitoError => e
39
- return content_tag(tag_name, '', options)
40
- end
41
-
42
- options.merge!(cms_field_tag.options)
43
-
44
- if VOID_TAGS.include?(tag_name.to_s)
45
- tag(tag_name, options)
46
- else
47
- inner_html =
48
- if block_given? && field_type != 'widget'
49
- capture { yield }
50
- else
51
- to_render = cms_field_tag.default_content
52
-
53
- if field_type == 'widget'
54
- modifications = cms_field_tag.modification_info || []
55
- rendered_widgets = to_render.each_with_index.map do |widget, index|
56
- render_widget(widget, modifications[index])
57
- end
58
-
59
- safe_join(rendered_widgets)
60
- else
61
- display_value(to_render)
62
- end
63
- end
64
-
65
- content_tag(tag_name, inner_html, options)
66
- end
67
- end
68
-
69
- # This is a helper class for {Scrivito::CmsTagHelper#cms_tag_list}.
70
- # @api public
71
- class List
72
-
73
- attr_reader :output
74
-
75
- def initialize(template, child_obj, show_sortable_options, modification)
76
- @template = template
77
- @child_obj = child_obj
78
- @show_sortable_options = show_sortable_options
79
- @modification = modification
80
- end
81
-
82
- # @param tag_name [String, Symbol] Name of the html tag (e.g. +:div+ or +:span+).
83
- # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
84
- # @return [String] The rendered html tag
85
- #
86
- # @example Render a <div> tag containing the text "random content" and assigns the tag a css class called +very_important+.
87
- # <%= list.tag :div, class: "very_important" do %>
88
- # random content
89
- # <% end %>
90
- # @api public
91
- def tag(tag_name, options = {}, &block)
92
- if @output.present?
93
- raise '"list.tag" can only be called once per iteration!'
94
- else
95
- if @show_sortable_options
96
- options = options.merge({
97
- 'data-scrivito-private-obj-id' => @child_obj.id,
98
- 'data-scrivito-private-obj-description-for-editor' => @child_obj.description_for_editor,
99
- })
100
-
101
- if @modification == Modification::NEW || @modification == Modification::DELETED
102
- options['data-scrivito-private-obj-modification'] = @modification
103
- end
104
- end
105
-
106
- @output = @template.content_tag(tag_name, options, &block) + "\n"
107
-
108
- nil
109
- end
110
- end
111
-
112
- end
113
-
114
- # @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
115
- # @param obj [BasicObj] A {BasicObj} from which method_name is read.
116
- # @param method_name [String, Symbol] Which method_name of the Obj should be rendered. Currently only +toclist+ is supported
117
- # @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
118
- # @yieldparam [List] list An instance, where +tag+ should be called once.
119
- # @yieldparam [BasicObj] child Each child of +toclist+
120
- # @return [String] The rendered html tag
121
- #
122
- # @example
123
- # <%= cms_tag_list :div, @obj, :toclist, class: "very_important" do |list, child| %>
124
- # <%= list.tag :div, class: "also_important" do %>
125
- # <%= link_to cms_path(child) do %>
126
- # <%= cms_tag :span, child, :title %>
127
- # <% end %>
128
- # <% end %>
129
- # <% end %>
130
- #
131
- # # results for an obj with two children in
132
- #
133
- # <div class="very_important">
134
- # <div class="also_important"><a href="/child1"><span>Child 1</span></a></div>
135
- # <div class="also_important"><a href="/child2"><span>Child 2</span></a></div>
136
- # </div>
137
- # @api public
138
- def cms_tag_list(tag_name, obj, method_name, options = {})
139
- if method_name.to_s == 'toclist'
140
- items = obj.toclist
141
- else
142
- raise "#{method_name} is not (yet) supported. Currently only toclist is supported."
143
- end
144
-
145
- children_sortable = false
146
-
147
- if inplace_editing_allowed?
148
- options['data-scrivito-private-obj-description-for-editor'] = obj.description_for_editor
149
- end
150
-
151
- if obj.has_attribute?(:child_order)
152
- items = Obj.sort_by_list(items, obj.child_order)
153
- children_sortable = inplace_editing_allowed?
154
-
155
- if children_sortable
156
- options = options.merge({
157
- 'data-scrivito-private-child-list-order-obj-id' => obj.id,
158
- })
159
-
160
- modification = cms_editing_context.comparison.modification_for_attribute(obj,
161
- :child_order)
162
- if modification == Modification::EDITED
163
- options['data-scrivito-private-child-list-modification'] = modification
164
- end
165
- end
166
- end
167
-
168
- inner_html = "\n".html_safe
169
-
170
- items.each do |item|
171
- item_modification = cms_editing_context.comparison.modification(item)
172
- list = List.new(self, item, children_sortable, item_modification)
173
-
174
- yield list, item
175
-
176
- inner_html << list.output
177
- end
178
-
179
- valid_page_classes = Obj.valid_page_classes_beneath(obj.path)
180
-
181
- if inplace_editing_allowed?
182
- options = options.merge({
183
- 'data-scrivito-private-child-list-path' => obj.path,
184
- 'data-scrivito-private-child-list-allowed-classes' => valid_page_classes.to_json,
185
- })
186
- end
187
-
188
- content_tag(tag_name, inner_html, options)
189
- end
190
-
191
- def render_widget(widget, container_modification = nil)
192
- options = {}
193
-
194
- if inplace_editing_allowed?
195
- options['data-scrivito-private-widget-id'] = widget.id
196
- options['data-scrivito-widget-obj-class'] = widget.obj_class_name
197
- options['data-scrivito-private-widget-description-for-editor'] = widget.description_for_editor
198
-
199
- if has_widget_details_view?(widget)
200
- options['data-scrivito-private-widget-has-details-view'] = true
201
- end
202
-
203
- comparison = cms_editing_context.comparison
204
- options['data-scrivito-private-widget-modification'] =
205
- if comparison.revision == widget.revision
206
- if container_modification
207
- unless widget.in_revision(Workspace.current.revision)
208
- Modification::DELETED
209
- end
210
- end
211
- else
212
- comparison.modification(widget)
213
- end
214
-
215
- options['data-scrivito-private-widget-container-modification'] =
216
- container_modification
217
- end
218
-
219
- content_tag(:div, options) do
220
- render(template: "#{widget.class.to_s.underscore}/show", locals: {widget: widget})
221
- end
222
- end
223
-
224
- def has_widget_details_view?(widget)
225
- details_template_path = "#{widget.obj_class_name.underscore}/details"
226
- lookup_context.find(details_template_path).present?
227
- rescue ActionView::MissingTemplate
228
- false
229
- end
230
- end
231
-
232
- end
@@ -1,21 +0,0 @@
1
- module Scrivito
2
-
3
- # This is a wrapper module for the default set of Scrivito helper modules.
4
- #
5
- # To make autoloading from +CmsController+ work, this module must be wrapped
6
- # by a module named +CmsHelper+:
7
- #
8
- # module CmsHelper
9
- # include Scrivito::DefaultCmsHelper
10
- # end
11
- # @api public
12
- module DefaultCmsHelper
13
- include DisplayHelper
14
- include CmsAssetHelper
15
- include Scrivito::CmsAssetHelper
16
- include Scrivito::EditingHelper
17
- include Scrivito::LayoutHelper
18
- include Scrivito::CmsTagHelper
19
- end
20
-
21
- end
@@ -1,128 +0,0 @@
1
- module Scrivito
2
-
3
- # @api public
4
- module DefaultCmsRoutingHelper
5
- # Returns the path for +target+ using the +CmsController+ routes.
6
- # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
7
- # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
8
- # +options+ are optional and include url settings such as path parameters or protocol.
9
- # @return [String]
10
- # @api public
11
- def cms_path(target, options = {})
12
- cms_path_or_url(target, "path", options)
13
- end
14
-
15
- # Returns the absolute URL for target using the +CmsController+ routes.
16
- # +target+ can be an +Obj+ or a +Link+ or a +LinkList+.
17
- # If +target+ is a +Linklist+, it must be non-empty. The first +Link+ from the +LinkList+ will be used.
18
- # +options+ are optional and include url settings such as path parameters or protocol.
19
- # @return [String]
20
- # @api public
21
- def cms_url(target, options = {})
22
- cms_path_or_url(target, "url", options)
23
- end
24
-
25
- LINK_TO_EMPTY_LINKLIST = "#__empty_linklist"
26
- LINK_TO_EMPTY_BLOB = "#__empty_blob"
27
-
28
- def cms_path_or_url(target, path_or_url, options)
29
- if cms_with_editing_context?(target)
30
- cms_path_or_url_with_editing_context(target, path_or_url, options)
31
- else
32
- cms_path_or_url_without_editing_context(target, path_or_url, options)
33
- end
34
- end
35
-
36
- def cms_path_or_url_with_editing_context(target, path_or_url, options)
37
- cms_path_or_url_without_editing_context(target, path_or_url,
38
- options.merge(cms_editing_context.to_params))
39
- end
40
-
41
- def cms_path_or_url_without_editing_context(target, path_or_url, options)
42
- if target.is_a?(Link)
43
- cms_path_or_url_for_links(target, path_or_url, options)
44
- elsif target.is_a?(Obj)
45
- cms_path_or_url_for_objs(target, path_or_url, options)
46
- elsif target.respond_to?(:first)
47
- if target.first.is_a?(Link)
48
- cms_path_or_url_for_links(target.first, path_or_url, options)
49
- else
50
- return LINK_TO_EMPTY_LINKLIST
51
- end
52
- else
53
- raise "cms_path or cms_url was called with an instance of #{target.class}. "+
54
- "It must only be called with an Obj or a Link or a non-empty LinkList."
55
- end
56
- end
57
-
58
- def cms_path_or_url_for_links(link, path_or_url, options = {})
59
- url = basic_url_or_path_for_link(link, path_or_url,
60
- Rack::Utils.parse_nested_query(link.query).merge(options))
61
- url = url + "##{link.fragment}" if link.fragment.present?
62
- url
63
- end
64
-
65
- def cms_path_or_url_for_objs(obj, path_or_url, options = {})
66
- permalink = obj.permalink
67
- if permalink
68
- main_app.public_send("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
69
- elsif obj.homepage?
70
- main_app.public_send("cms_root_#{path_or_url}", options)
71
- else
72
- if obj.binary? && cms_editing_context.display_mode != "editing"
73
- if obj.body_data_url
74
- enforce_protocol_from_request(obj.body_data_url)
75
- else
76
- LINK_TO_EMPTY_BLOB
77
- end
78
- else
79
- main_app.public_send(
80
- "cms_id_#{path_or_url}",
81
- options.merge(
82
- id: obj.id,
83
- slug: obj.slug.presence
84
- )
85
- )
86
- end
87
- end
88
- end
89
-
90
- def cms_editing_context
91
- request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new
92
- end
93
-
94
- def inplace_editing_allowed?
95
- cms_editing_context.authenticated_editor?
96
- end
97
-
98
- private
99
-
100
- def cms_with_editing_context?(target)
101
- inplace_editing_allowed? && (!target.is_a?(Link) || target.internal?)
102
- end
103
-
104
- def basic_url_or_path_for_link(link, path_or_url, options = {})
105
- if link.internal?
106
- cms_path_or_url_without_editing_context(link.obj, path_or_url, options)
107
- else
108
- url = link.url
109
- url = merge_options(url, options) if options.any?
110
- url
111
- end
112
- end
113
-
114
- def merge_options(url, options)
115
- parsed_url = URI.parse(url)
116
-
117
- query = Rack::Utils.parse_query(parsed_url.query)
118
- merged_query = query.merge(options.stringify_keys)
119
- parsed_url.query = merged_query.to_query
120
-
121
- parsed_url.to_s
122
- end
123
-
124
- def enforce_protocol_from_request(url)
125
- request.ssl? && !url.starts_with?('https') ? url.gsub(/^http/, 'https') : url
126
- end
127
- end
128
- end