scrivito_sdk 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/README +6 -0
- data/app/controllers/cms_controller.rb +7 -0
- data/app/controllers/scrivito/blobs_controller.rb +10 -0
- data/app/controllers/scrivito/default_cms_controller.rb +61 -0
- data/app/controllers/scrivito/objs_controller.rb +200 -0
- data/app/controllers/scrivito/tasks_controller.rb +11 -0
- data/app/controllers/scrivito/webservice_controller.rb +36 -0
- data/app/controllers/scrivito/workspaces_controller.rb +41 -0
- data/app/helpers/cms_helper.rb +7 -0
- data/app/helpers/cms_routing_helper.rb +7 -0
- data/app/helpers/scrivito/cms_asset_helper.rb +103 -0
- data/app/helpers/scrivito/cms_tag_helper.rb +231 -0
- data/app/helpers/scrivito/default_cms_helper.rb +21 -0
- data/app/helpers/scrivito/default_cms_routing_helper.rb +130 -0
- data/app/helpers/scrivito/display_helper.rb +71 -0
- data/app/helpers/scrivito/editing_helper.rb +26 -0
- data/app/helpers/scrivito/layout_helper.rb +28 -0
- data/app/models/named_link.rb +2 -0
- data/app/views/cms/_index.html.erb +7 -0
- data/app/views/cms/index.html.erb +1 -0
- data/app/views/scrivito/_editing_javascript.html.erb +7 -0
- data/app/views/scrivito/default_cms/show_widget.html.erb +1 -0
- data/app/views/scrivito/objs/copy_widget.html.erb +1 -0
- data/app/views/scrivito/objs/create_widget.html.erb +1 -0
- data/app/views/scrivito/widget_thumbnail.html.erb +9 -0
- data/config/ca-bundle.crt +3509 -0
- data/config/cms_routes.rb +17 -0
- data/config/locales/de.scrivito.errors.yml +7 -0
- data/config/locales/de.scrivito.lib.yml +6 -0
- data/config/locales/de.scrivito.models.yml +6 -0
- data/config/locales/en.scrivito.errors.yml +7 -0
- data/config/locales/en.scrivito.lib.yml +6 -0
- data/config/locales/en.scrivito.models.yml +6 -0
- data/config/routes.rb +37 -0
- data/lib/assets/images/180x120.gif +0 -0
- data/lib/assets/images/scrivito/image_placeholder.png +0 -0
- data/lib/assets/javascripts/scrivito_editing.js +14642 -0
- data/lib/assets/stylesheets/scrivito.css +180 -0
- data/lib/assets/stylesheets/scrivito_editing.css +2213 -0
- data/lib/generators/cms/migration/USAGE +9 -0
- data/lib/generators/cms/migration/migration_generator.rb +21 -0
- data/lib/generators/cms/migration/templates/migration.erb +10 -0
- data/lib/obj.rb +3 -0
- data/lib/scrivito/access_denied.rb +6 -0
- data/lib/scrivito/attribute_content.rb +194 -0
- data/lib/scrivito/backend_error.rb +4 -0
- data/lib/scrivito/basic_obj.rb +840 -0
- data/lib/scrivito/basic_widget.rb +238 -0
- data/lib/scrivito/blob.rb +48 -0
- data/lib/scrivito/cache.rb +41 -0
- data/lib/scrivito/cache_garbage_collector.rb +83 -0
- data/lib/scrivito/cache_middleware.rb +17 -0
- data/lib/scrivito/client_config.rb +62 -0
- data/lib/scrivito/client_error.rb +12 -0
- data/lib/scrivito/cms_accessible.rb +30 -0
- data/lib/scrivito/cms_backend.rb +238 -0
- data/lib/scrivito/cms_cache_storage.rb +51 -0
- data/lib/scrivito/cms_dispatch_controller.rb +46 -0
- data/lib/scrivito/cms_env.rb +63 -0
- data/lib/scrivito/cms_field_tag.rb +112 -0
- data/lib/scrivito/cms_rest_api.rb +151 -0
- data/lib/scrivito/cms_rest_api/attribute_serializer.rb +98 -0
- data/lib/scrivito/cms_rest_api/blob_uploader.rb +18 -0
- data/lib/scrivito/cms_rest_api/widget_extractor.rb +42 -0
- data/lib/scrivito/cms_test_request.rb +23 -0
- data/lib/scrivito/communication_error.rb +17 -0
- data/lib/scrivito/comparison.rb +67 -0
- data/lib/scrivito/configuration.rb +221 -0
- data/lib/scrivito/connection_manager.rb +100 -0
- data/lib/scrivito/content_conversion.rb +43 -0
- data/lib/scrivito/content_service.rb +118 -0
- data/lib/scrivito/content_state.rb +109 -0
- data/lib/scrivito/content_state_caching.rb +47 -0
- data/lib/scrivito/content_state_visitor.rb +19 -0
- data/lib/scrivito/controller_runtime.rb +35 -0
- data/lib/scrivito/date_attribute.rb +16 -0
- data/lib/scrivito/deprecation.rb +21 -0
- data/lib/scrivito/diff.rb +110 -0
- data/lib/scrivito/editing_context.rb +106 -0
- data/lib/scrivito/editing_context_middleware.rb +60 -0
- data/lib/scrivito/engine.rb +65 -0
- data/lib/scrivito/errors.rb +11 -0
- data/lib/scrivito/html_string.rb +18 -0
- data/lib/scrivito/link.rb +187 -0
- data/lib/scrivito/link_parser.rb +81 -0
- data/lib/scrivito/log_subscriber.rb +29 -0
- data/lib/scrivito/migration.rb +2 -0
- data/lib/scrivito/migrations.rb +12 -0
- data/lib/scrivito/migrations/cms_backend.rb +94 -0
- data/lib/scrivito/migrations/installer.rb +45 -0
- data/lib/scrivito/migrations/migration.rb +93 -0
- data/lib/scrivito/migrations/migration_dsl.rb +143 -0
- data/lib/scrivito/migrations/migration_store.rb +23 -0
- data/lib/scrivito/migrations/migrator.rb +135 -0
- data/lib/scrivito/migrations/workspace_lock.rb +39 -0
- data/lib/scrivito/model_identity.rb +13 -0
- data/lib/scrivito/modification.rb +8 -0
- data/lib/scrivito/named_link.rb +75 -0
- data/lib/scrivito/network_error.rb +11 -0
- data/lib/scrivito/obj_data.rb +140 -0
- data/lib/scrivito/obj_data_from_hash.rb +31 -0
- data/lib/scrivito/obj_data_from_service.rb +84 -0
- data/lib/scrivito/obj_params_parser.rb +61 -0
- data/lib/scrivito/obj_search_builder.rb +62 -0
- data/lib/scrivito/obj_search_enumerator.rb +374 -0
- data/lib/scrivito/rate_limit_exceeded.rb +5 -0
- data/lib/scrivito/revision.rb +9 -0
- data/lib/scrivito/string_tagging.rb +18 -0
- data/lib/scrivito/text_link.rb +52 -0
- data/lib/scrivito/text_link_conversion.rb +52 -0
- data/lib/scrivito/type_computer.rb +34 -0
- data/lib/scrivito/widget_field_params.rb +61 -0
- data/lib/scrivito/widget_garbage_collection.rb +97 -0
- data/lib/scrivito/workspace.rb +222 -0
- data/lib/scrivito/workspace_data_from_service.rb +80 -0
- data/lib/scrivito/workspace_selection_middleware.rb +23 -0
- data/lib/scrivito_sdk.rb +19 -0
- data/lib/tasks/cache.rake +12 -0
- data/lib/tasks/migration.rake +35 -0
- data/lib/widget.rb +3 -0
- metadata +291 -0
@@ -0,0 +1,231 @@
|
|
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
|
+
class List
|
70
|
+
|
71
|
+
attr_reader :output
|
72
|
+
|
73
|
+
def initialize(template, child_obj, show_sortable_options, modification)
|
74
|
+
@template = template
|
75
|
+
@child_obj = child_obj
|
76
|
+
@show_sortable_options = show_sortable_options
|
77
|
+
@modification = modification
|
78
|
+
end
|
79
|
+
|
80
|
+
# @param tag_name [String, Symbol] Name of the html tag (e.g. +:div+ or +:span+).
|
81
|
+
# @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
|
82
|
+
# @return [String] The rendered html tag
|
83
|
+
#
|
84
|
+
# @example Render a <div> tag containing the text "random content" and assigns the tag a css class called +very_important+.
|
85
|
+
# <%= list.tag :div, class: "very_important" do %>
|
86
|
+
# random content
|
87
|
+
# <% end %>
|
88
|
+
def tag(tag_name, options = {}, &block)
|
89
|
+
if @output.present?
|
90
|
+
raise '"list.tag" can only be called once per iteration!'
|
91
|
+
else
|
92
|
+
if @show_sortable_options
|
93
|
+
options = options.merge({
|
94
|
+
'data-scrivito-private-obj-id' => @child_obj.id,
|
95
|
+
'data-scrivito-private-obj-description-for-editor' => @child_obj.description_for_editor,
|
96
|
+
})
|
97
|
+
|
98
|
+
if @modification == Modification::NEW || @modification == Modification::DELETED
|
99
|
+
options['data-scrivito-private-obj-modification'] = @modification
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
@output = @template.content_tag(tag_name, options, &block) + "\n"
|
104
|
+
|
105
|
+
nil
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
|
112
|
+
# @param obj [Obj] A {Obj} from which method_name is read.
|
113
|
+
# @param method_name [String, Symbol] Which method_name of the Obj should be rendered. Currently only +toclist+ is supported
|
114
|
+
# @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add HTML attributes to the tag.
|
115
|
+
# @yieldparam [List] list An instance, where +tag+ should be called once.
|
116
|
+
# @yieldparam [Obj] child Each child of +toclist+
|
117
|
+
# @return [String] The rendered html tag
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# <%= cms_tag_list :div, @obj, :toclist, class: "very_important" do |list, child| %>
|
121
|
+
# <%= list.tag :div, class: "also_important" do %>
|
122
|
+
# <%= link_to cms_path(child) do %>
|
123
|
+
# <%= cms_tag :span, child, :title %>
|
124
|
+
# <% end %>
|
125
|
+
# <% end %>
|
126
|
+
# <% end %>
|
127
|
+
#
|
128
|
+
# # results for an obj with two children in
|
129
|
+
#
|
130
|
+
# <div class="very_important">
|
131
|
+
# <div class="also_important"><a href="/child1"><span>Child 1</span></a></div>
|
132
|
+
# <div class="also_important"><a href="/child2"><span>Child 2</span></a></div>
|
133
|
+
# </div>
|
134
|
+
def cms_tag_list(tag_name, obj, method_name, options = {})
|
135
|
+
if method_name.to_s == 'toclist'
|
136
|
+
items = obj.toclist
|
137
|
+
else
|
138
|
+
raise "#{method_name} is not (yet) supported. Currently only toclist is supported."
|
139
|
+
end
|
140
|
+
|
141
|
+
children_sortable = false
|
142
|
+
|
143
|
+
if inplace_editing_allowed?
|
144
|
+
options['data-scrivito-private-obj-description-for-editor'] = obj.description_for_editor
|
145
|
+
end
|
146
|
+
|
147
|
+
if obj.has_attribute?(:child_order)
|
148
|
+
items = Obj.sort_by_list(items, obj.child_order)
|
149
|
+
children_sortable = inplace_editing_allowed?
|
150
|
+
|
151
|
+
if children_sortable
|
152
|
+
options = options.merge({
|
153
|
+
'data-scrivito-private-child-list-order-obj-id' => obj.id,
|
154
|
+
})
|
155
|
+
|
156
|
+
modification = cms_editing_context.comparison.modification_for_attribute(obj,
|
157
|
+
:child_order)
|
158
|
+
if modification == Modification::EDITED
|
159
|
+
options['data-scrivito-private-child-list-modification'] = modification
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
inner_html = "\n".html_safe
|
165
|
+
|
166
|
+
items.each do |item|
|
167
|
+
item_modification = cms_editing_context.comparison.modification(item)
|
168
|
+
list = List.new(self, item, children_sortable, item_modification)
|
169
|
+
|
170
|
+
yield list, item
|
171
|
+
|
172
|
+
inner_html << list.output
|
173
|
+
end
|
174
|
+
|
175
|
+
valid_page_classes = Obj.valid_page_classes_beneath(obj.path)
|
176
|
+
|
177
|
+
if inplace_editing_allowed?
|
178
|
+
options = options.merge({
|
179
|
+
'data-scrivito-private-child-list-path' => obj.path,
|
180
|
+
'data-scrivito-private-child-list-allowed-classes' => valid_page_classes.to_json,
|
181
|
+
})
|
182
|
+
end
|
183
|
+
|
184
|
+
content_tag(tag_name, inner_html, options)
|
185
|
+
end
|
186
|
+
|
187
|
+
def render_widget(widget,
|
188
|
+
container_modification = nil,
|
189
|
+
obj = @obj,
|
190
|
+
field_name = widget.container_field_name,
|
191
|
+
container = widget.container)
|
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
|
+
|
198
|
+
if has_widget_details_view?(widget)
|
199
|
+
options['data-scrivito-private-widget-has-details-view'] = true
|
200
|
+
end
|
201
|
+
|
202
|
+
comparison = cms_editing_context.comparison
|
203
|
+
options['data-scrivito-private-widget-modification'] =
|
204
|
+
if comparison.revision == widget.revision
|
205
|
+
if container_modification
|
206
|
+
unless widget.in_revision(Workspace.current.revision)
|
207
|
+
Modification::DELETED
|
208
|
+
end
|
209
|
+
end
|
210
|
+
else
|
211
|
+
comparison.modification(widget)
|
212
|
+
end
|
213
|
+
|
214
|
+
options['data-scrivito-private-widget-container-modification'] =
|
215
|
+
container_modification
|
216
|
+
end
|
217
|
+
|
218
|
+
content_tag(:div, options) do
|
219
|
+
render(template: "#{widget.class.to_s.underscore}/show", locals: {widget: widget})
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
def has_widget_details_view?(widget)
|
224
|
+
details_template_path = "#{widget.obj_class_name.underscore}/details"
|
225
|
+
lookup_context.find(details_template_path).present?
|
226
|
+
rescue ActionView::MissingTemplate
|
227
|
+
false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
@@ -0,0 +1,130 @@
|
|
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
|
+
dont_resolve_blobs = options.delete(:dont_resolve_blobs)
|
68
|
+
if permalink
|
69
|
+
__send__("cms_permalink_#{path_or_url}", options.merge(:permalink => permalink))
|
70
|
+
elsif obj.homepage?
|
71
|
+
__send__("root_#{path_or_url}", options)
|
72
|
+
else
|
73
|
+
if obj.binary? && !dont_resolve_blobs
|
74
|
+
if obj.body_data_url
|
75
|
+
enforce_protocol_from_request(obj.body_data_url)
|
76
|
+
else
|
77
|
+
LINK_TO_EMPTY_BLOB
|
78
|
+
end
|
79
|
+
else
|
80
|
+
__send__(
|
81
|
+
"cms_id_#{path_or_url}",
|
82
|
+
options.merge(
|
83
|
+
id: obj.id,
|
84
|
+
slug: obj.slug.presence
|
85
|
+
)
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def cms_editing_context
|
92
|
+
request.env[EditingContextMiddleware::ENVKEY] || EditingContext.new
|
93
|
+
end
|
94
|
+
|
95
|
+
def inplace_editing_allowed?
|
96
|
+
cms_editing_context.authenticated_editor?
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
|
101
|
+
def cms_with_editing_context?(target)
|
102
|
+
inplace_editing_allowed? && (!target.is_a?(Link) || target.internal?)
|
103
|
+
end
|
104
|
+
|
105
|
+
def basic_url_or_path_for_link(link, path_or_url, options = {})
|
106
|
+
if link.internal?
|
107
|
+
cms_path_or_url_without_editing_context(link.obj, path_or_url, options)
|
108
|
+
else
|
109
|
+
url = link.url
|
110
|
+
options.delete(:dont_resolve_blobs)
|
111
|
+
url = merge_options(url, options) if options.any?
|
112
|
+
url
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def merge_options(url, options)
|
117
|
+
parsed_url = URI.parse(url)
|
118
|
+
|
119
|
+
query = Rack::Utils.parse_query(parsed_url.query)
|
120
|
+
merged_query = query.merge(options.stringify_keys)
|
121
|
+
parsed_url.query = merged_query.to_query
|
122
|
+
|
123
|
+
parsed_url.to_s
|
124
|
+
end
|
125
|
+
|
126
|
+
def enforce_protocol_from_request(url)
|
127
|
+
request.ssl? && !url.starts_with?('https') ? url.gsub(/^http/, 'https') : url
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Scrivito
|
2
|
+
|
3
|
+
# This module contains a helper that can be used to render attributes of the CMS models.
|
4
|
+
# @api public
|
5
|
+
module DisplayHelper
|
6
|
+
|
7
|
+
# For a consistent look of your site and easy maintenance, only the display helpers
|
8
|
+
# should be used to render an attribute <em>value</em> of a CMS model.
|
9
|
+
#
|
10
|
+
# <%= display_value @obj.title %>
|
11
|
+
# Renders the value, taking its type into account.
|
12
|
+
# * An HtmlString will be exported by converting its links
|
13
|
+
# * A Time will be exported in an international form: Year-Month-Day Hour:Minutes
|
14
|
+
# * A non-HTML String will be quoted
|
15
|
+
# * other values will be rendered unchanged
|
16
|
+
#
|
17
|
+
# @api public
|
18
|
+
def display_value(value)
|
19
|
+
case value
|
20
|
+
when HtmlString then convert_links(value).html_safe
|
21
|
+
when String then h(value)
|
22
|
+
when Time then h(l(value))
|
23
|
+
else value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def display_original_value(value)
|
28
|
+
case value
|
29
|
+
when HtmlString then convert_links(value, :dont_resolve_blobs => true).html_safe
|
30
|
+
else display_value(value)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Renders a field from the CMS.
|
35
|
+
#
|
36
|
+
# <%= display_field @obj, :title %>
|
37
|
+
#
|
38
|
+
# @api public
|
39
|
+
def display_field(obj, attr, options = {})
|
40
|
+
display_value obj[attr]
|
41
|
+
end
|
42
|
+
|
43
|
+
# Legacy method - deprecated
|
44
|
+
#
|
45
|
+
# Use display_value and display_field instead
|
46
|
+
def display(*args)
|
47
|
+
if args.last.kind_of? Hash
|
48
|
+
options = args.pop
|
49
|
+
else
|
50
|
+
options = {}
|
51
|
+
end
|
52
|
+
return display_value(args.first) if args.size == 1
|
53
|
+
display_field(args[0], args[1], options)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def convert_links(html, cms_path_options = {})
|
59
|
+
if html
|
60
|
+
html.gsub(%r{<?\bobjid:([a-f0-9]{16})\b>?}) do
|
61
|
+
if obj = Obj.find_by_id($1)
|
62
|
+
cms_path(obj, cms_path_options)
|
63
|
+
else
|
64
|
+
"#__target_object_not_reachable"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|