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.
- checksums.yaml +4 -4
- data/app/controllers/scrivito/blobs_controller.rb +1 -2
- data/app/controllers/scrivito/default_cms_controller.rb +9 -75
- data/app/controllers/scrivito/objs_controller.rb +107 -119
- data/app/controllers/scrivito/tasks_controller.rb +1 -1
- data/app/controllers/scrivito/users_controller.rb +1 -1
- data/app/controllers/scrivito/webservice_controller.rb +6 -2
- data/app/controllers/scrivito/workspaces_controller.rb +57 -17
- data/app/helpers/scrivito_helper.rb +285 -0
- data/app/views/google_maps_widget/show.html.erb +1 -0
- data/app/views/scrivito/_editing_auth_warning.html.erb +43 -0
- data/app/views/scrivito/blobs/upload_permission.json.jbuilder +1 -0
- data/app/views/scrivito/objs/copy.json.jbuilder +1 -0
- data/app/views/scrivito/objs/copy_widget.html.erb +1 -1
- data/app/views/scrivito/objs/create.json.jbuilder +1 -0
- data/app/views/scrivito/objs/create_widget.html.erb +1 -1
- data/app/views/scrivito/objs/details.json.jbuilder +1 -0
- data/app/views/scrivito/objs/format_missing_error.json.jbuilder +1 -0
- data/app/views/scrivito/objs/modification.json.jbuilder +1 -0
- data/app/views/scrivito/objs/page_class_selection.json.jbuilder +1 -0
- data/app/views/scrivito/objs/search.json.jbuilder +6 -0
- data/app/views/scrivito/objs/search_only_size.json.jbuilder +1 -0
- data/app/views/scrivito/objs/update.json.jbuilder +1 -0
- data/app/views/scrivito/objs/widget_class_selection.json.jbuilder +1 -0
- data/app/views/scrivito/objs/widget_modification.json.jbuilder +1 -0
- data/app/views/scrivito/tasks/show.json.jbuilder +3 -0
- data/app/views/scrivito/users/suggest.json.jbuilder +1 -0
- data/app/views/scrivito/webservice/empty.json +1 -0
- data/app/views/scrivito/webservice/error.json.jbuilder +2 -0
- data/app/views/scrivito/workspaces/_workspace.json.jbuilder +5 -0
- data/app/views/scrivito/workspaces/check.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/create.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/index.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/show.json.jbuilder +1 -0
- data/app/views/scrivito/workspaces/task.json.jbuilder +5 -0
- data/config/ca-bundle.crt +259 -234
- data/config/cms_routes.rb +2 -2
- data/config/routes.rb +3 -0
- data/lib/assets/javascripts/{scrivito_editing.js → scrivito_sdk.js} +1662 -1180
- data/lib/assets/stylesheets/{scrivito_editing.css → scrivito_sdk.css} +242 -6
- data/lib/generators/scrivito/install/install_generator.rb +62 -0
- data/lib/generators/scrivito/install/templates/app/controllers/cms_controller.rb +3 -0
- data/lib/generators/scrivito/install/templates/app/controllers/page_controller.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/models/headline_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/image.rb +5 -0
- data/lib/generators/scrivito/install/templates/app/models/image_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/obj.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/models/page.rb +8 -0
- data/lib/generators/scrivito/install/templates/app/models/text_widget.rb +7 -0
- data/lib/generators/scrivito/install/templates/app/models/widget.rb +2 -0
- data/lib/generators/scrivito/install/templates/app/views/headline_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/headline_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/image_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/image_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/page/details.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/page/index.html.erb +16 -0
- data/lib/generators/scrivito/install/templates/app/views/page/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/app/views/text_widget/show.html.erb +1 -0
- data/lib/generators/scrivito/install/templates/app/views/text_widget/thumbnail.html.erb +3 -0
- data/lib/generators/scrivito/install/templates/config/initializers/scrivito.rb +10 -0
- data/lib/generators/scrivito/install/templates/scrivito/migrate/install_scrivito.rb +49 -0
- data/lib/generators/scrivito/migration/USAGE +9 -0
- data/lib/generators/{cms → scrivito}/migration/migration_generator.rb +4 -9
- data/lib/generators/{cms → scrivito}/migration/templates/migration.erb +3 -3
- data/lib/generators/{cms → scrivito}/widget/templates/details.html.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/migration.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/model.erb +0 -0
- data/lib/generators/{cms → scrivito}/widget/templates/show.html.erb +0 -0
- data/lib/generators/scrivito/widget/templates/thumbnail.html.erb +3 -0
- data/lib/generators/{cms → scrivito}/widget/widget_generator.rb +3 -2
- data/lib/obj.rb +17 -3
- data/lib/scrivito/attribute_collection.rb +7 -12
- data/lib/scrivito/attribute_content.rb +31 -12
- data/lib/scrivito/basic_obj.rb +186 -96
- data/lib/scrivito/basic_widget.rb +25 -10
- data/lib/scrivito/binary.rb +75 -0
- data/lib/scrivito/cache_garbage_collector.rb +19 -4
- data/lib/scrivito/child_list_tag.rb +108 -0
- data/lib/scrivito/client_config.rb +2 -1
- data/lib/scrivito/client_error.rb +3 -2
- data/lib/scrivito/cms_backend.rb +81 -16
- data/lib/scrivito/cms_dispatch_controller.rb +7 -0
- data/lib/scrivito/cms_env.rb +0 -2
- data/lib/scrivito/cms_field_tag.rb +44 -35
- data/lib/scrivito/cms_rest_api.rb +23 -6
- data/lib/scrivito/cms_rest_api/attribute_serializer.rb +1 -1
- data/lib/scrivito/cms_routing.rb +120 -0
- data/lib/scrivito/configuration.rb +69 -58
- data/lib/scrivito/connection_manager.rb +30 -1
- data/lib/scrivito/content_service.rb +10 -7
- data/lib/scrivito/controller_actions.rb +108 -0
- data/lib/scrivito/diff.rb +30 -15
- data/lib/scrivito/editing_context.rb +4 -0
- data/lib/scrivito/editing_context_helper.rb +19 -0
- data/lib/scrivito/editing_context_middleware.rb +20 -1
- data/lib/scrivito/image_tag_helper.rb +44 -0
- data/lib/scrivito/layout_tags.rb +33 -0
- data/lib/scrivito/link.rb +4 -2
- data/lib/scrivito/membership.rb +0 -8
- data/lib/scrivito/migrations.rb +0 -1
- data/lib/scrivito/migrations/installer.rb +1 -1
- data/lib/scrivito/migrations/migration.rb +0 -2
- data/lib/scrivito/migrations/migrator.rb +2 -3
- data/lib/scrivito/obj_class.rb +64 -16
- data/lib/scrivito/obj_class_data.rb +4 -0
- data/lib/scrivito/obj_search_enumerator.rb +1 -1
- data/lib/scrivito/routing_helper.rb +42 -0
- data/lib/scrivito/{engine.rb → sdk_engine.rb} +15 -29
- data/lib/scrivito/tag_renderer.rb +40 -0
- data/lib/scrivito/test_request.rb +40 -0
- data/lib/scrivito/type_computer.rb +1 -6
- data/lib/scrivito/user.rb +33 -15
- data/lib/scrivito/user_definition.rb +34 -6
- data/lib/scrivito/widget_tag.rb +67 -0
- data/lib/scrivito/workspace.rb +12 -24
- data/lib/scrivito_sdk.rb +17 -1
- data/lib/tasks/cache.rake +4 -5
- data/lib/tasks/migration.rake +1 -1
- data/lib/widget.rb +21 -3
- metadata +119 -70
- data/README +0 -6
- data/app/controllers/cms_controller.rb +0 -7
- data/app/helpers/cms_helper.rb +0 -7
- data/app/helpers/cms_routing_helper.rb +0 -7
- data/app/helpers/scrivito/cms_asset_helper.rb +0 -110
- data/app/helpers/scrivito/cms_tag_helper.rb +0 -232
- data/app/helpers/scrivito/default_cms_helper.rb +0 -21
- data/app/helpers/scrivito/default_cms_routing_helper.rb +0 -128
- data/app/helpers/scrivito/display_helper.rb +0 -64
- data/app/helpers/scrivito/editing_helper.rb +0 -32
- data/app/helpers/scrivito/layout_helper.rb +0 -21
- data/app/models/named_link.rb +0 -2
- data/app/views/cms/_index.html.erb +0 -7
- data/app/views/cms/index.html.erb +0 -1
- data/app/views/scrivito/_editing_javascript.html.erb +0 -7
- data/app/views/scrivito/default_cms/show_widget.html.erb +0 -1
- data/lib/assets/stylesheets/scrivito.css +0 -199
- data/lib/generators/cms/migration/USAGE +0 -9
- data/lib/generators/cms/widget/templates/thumbnail.html.erb +0 -2
- data/lib/scrivito/blob.rb +0 -48
- data/lib/scrivito/cms_accessible.rb +0 -30
- data/lib/scrivito/cms_rest_api/blob_uploader.rb +0 -18
- data/lib/scrivito/cms_test_request.rb +0 -23
- data/lib/scrivito/migrations/migration_dsl.rb +0 -180
@@ -2,7 +2,8 @@ module Scrivito
|
|
2
2
|
|
3
3
|
class WebserviceController < ActionController::Base
|
4
4
|
rescue_from ClientError do |exception|
|
5
|
-
|
5
|
+
@exception = exception
|
6
|
+
render 'scrivito/webservice/error', formats: :json, status: exception.http_code
|
6
7
|
end
|
7
8
|
|
8
9
|
before_filter :merge_correctly_parsed_json_params
|
@@ -36,6 +37,9 @@ class WebserviceController < ActionController::Base
|
|
36
37
|
request.body.rewind
|
37
38
|
params.merge!(ActiveSupport::JSON.decode(body)) if body.present?
|
38
39
|
end
|
40
|
+
rescue JSON::ParserError => e
|
41
|
+
# Rails TestRequest mixes up arguments, therefore ignore elements here
|
42
|
+
raise e unless Rails.env.test?
|
39
43
|
end
|
40
44
|
|
41
45
|
def can_user_access_workspace?(verb, workspace)
|
@@ -51,7 +55,7 @@ class WebserviceController < ActionController::Base
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def render_empty_json
|
54
|
-
render
|
58
|
+
render 'scrivito/webservice/empty', formats: :json
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
@@ -5,24 +5,29 @@ module Scrivito
|
|
5
5
|
around_action :authorize_current_workspace_publish, only: [:check, :publish]
|
6
6
|
|
7
7
|
def index
|
8
|
-
workspaces = Workspace.all.select do |workspace|
|
9
|
-
can_user_access_workspace?(:read, workspace)
|
8
|
+
@workspaces = Workspace.all.select do |workspace|
|
9
|
+
can_user_access_workspace?(:read, workspace)
|
10
10
|
end
|
11
|
-
render json: workspaces
|
12
11
|
end
|
13
12
|
|
14
13
|
def show
|
15
|
-
render json: current_workspace
|
16
14
|
end
|
17
15
|
|
18
16
|
def create
|
19
17
|
create_workspace_params = workspace_params.dup
|
20
|
-
|
21
|
-
|
18
|
+
unless scrivito_user.system_user?
|
19
|
+
create_workspace_params.deep_merge!(memberships: {scrivito_user.id => {role: 'owner'}})
|
20
|
+
end
|
21
|
+
result = task_unaware_request(:post, '/workspaces', workspace: create_workspace_params)
|
22
|
+
|
23
|
+
handle_if_task(result) do
|
24
|
+
@workspace_result = result
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
def update
|
25
|
-
|
29
|
+
current_workspace.update(workspace_params)
|
30
|
+
render_empty_json
|
26
31
|
end
|
27
32
|
|
28
33
|
def destroy
|
@@ -31,29 +36,40 @@ module Scrivito
|
|
31
36
|
end
|
32
37
|
|
33
38
|
def rebase
|
34
|
-
|
35
|
-
|
39
|
+
@task = task_unaware_request(:put, current_workspace_backend_path('/rebase'), {})['task']
|
40
|
+
render :task
|
36
41
|
end
|
37
42
|
|
38
43
|
def check
|
39
|
-
|
44
|
+
assert_workspace_is_not_outdated
|
45
|
+
@check_result = publish_checker.call(params[:from].to_i)
|
40
46
|
end
|
41
47
|
|
42
48
|
def publish
|
43
49
|
if valid_publish_request?
|
44
|
-
|
45
|
-
|
50
|
+
@task = conditional_publish['task']
|
51
|
+
render :task
|
46
52
|
else
|
47
|
-
|
53
|
+
raise_content_state_id_changed
|
48
54
|
end
|
49
|
-
rescue Workspace::PublishPreventedDueToContentChange
|
50
|
-
concurrent_content_change_response
|
51
55
|
rescue ScrivitoError => e
|
52
56
|
raise ClientError.new(e.message, 400)
|
53
57
|
end
|
54
58
|
|
55
59
|
private
|
56
60
|
|
61
|
+
delegate :task_unaware_request, to: CmsRestApi
|
62
|
+
|
63
|
+
def current_workspace_backend_path(suffix)
|
64
|
+
"/workspaces/#{current_workspace.id}#{suffix}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def conditional_publish
|
68
|
+
task_unaware_request(:put, current_workspace_backend_path('/publish'), {
|
69
|
+
if_content_state_id_equals: current_workspace.content_state.content_state_id
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
57
73
|
def valid_publish_request?
|
58
74
|
publish_checker.passing_certificates?(certificates_param)
|
59
75
|
end
|
@@ -81,6 +97,7 @@ module Scrivito
|
|
81
97
|
def current_workspace
|
82
98
|
@current_workspace ||= Workspace.find(params[:id])
|
83
99
|
end
|
100
|
+
helper_method :current_workspace
|
84
101
|
|
85
102
|
def workspace_params
|
86
103
|
assert_valid_workspace_params
|
@@ -92,6 +109,25 @@ module Scrivito
|
|
92
109
|
params[:certificates]
|
93
110
|
end
|
94
111
|
|
112
|
+
def handle_if_task(result)
|
113
|
+
if result['task'].present?
|
114
|
+
@task = result['task']
|
115
|
+
render :task
|
116
|
+
else
|
117
|
+
yield result
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def assert_workspace_is_not_outdated
|
122
|
+
if current_workspace.outdated?
|
123
|
+
raise ClientError.new(
|
124
|
+
'Workspace is outdated',
|
125
|
+
400,
|
126
|
+
'precondition_not_verifiable.workspace.publish.content_state_id'
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
95
131
|
def assert_valid_certificates_param
|
96
132
|
if params[:certificates].blank?
|
97
133
|
raise ClientError.new("Required parameter 'certificates' is missing.", 400)
|
@@ -106,8 +142,12 @@ module Scrivito
|
|
106
142
|
raise "Parameter 'workspace' is not a hash." unless params[:workspace].is_a?(Hash)
|
107
143
|
end
|
108
144
|
|
109
|
-
def
|
110
|
-
|
145
|
+
def raise_content_state_id_changed
|
146
|
+
raise ClientError.new(
|
147
|
+
'Content state id changed',
|
148
|
+
400,
|
149
|
+
'precondition_not_met.workspace.publish.content_state_id'
|
150
|
+
)
|
111
151
|
end
|
112
152
|
end
|
113
153
|
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
#
|
2
|
+
# This module provides several helper methods for rendering the CMS contents and enabling the
|
3
|
+
# in-place editing.
|
4
|
+
#
|
5
|
+
# @api public
|
6
|
+
#
|
7
|
+
module ScrivitoHelper
|
8
|
+
include Scrivito::RoutingHelper
|
9
|
+
|
10
|
+
#
|
11
|
+
# Returns an HTML block tag containing content from an Obj.
|
12
|
+
# Add HTML attributes by passing an attributes hash to options.
|
13
|
+
# The helper method is somewhat similar to (and internally uses)
|
14
|
+
# http://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag.
|
15
|
+
#
|
16
|
+
# @api public
|
17
|
+
#
|
18
|
+
# This helper method also renders additional data attributes, which are needed for inplace editing.
|
19
|
+
# These attributes are only rendered when appropriate, i.e. not for a regular visitor.
|
20
|
+
#
|
21
|
+
# @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
|
22
|
+
# @param obj_or_widget [Scrivito::BasicObj, Scrivito::BasicWidget] A {Scrivito::BasicObj}
|
23
|
+
# or {Scrivito::BasicWidget} from which the +field_name+ is read.
|
24
|
+
# @param field_name [String, Symbol] Which field of the Obj should be rendered.
|
25
|
+
# @param html_options [Hash] HTML options to be passed to +content_tag+.
|
26
|
+
# @param block [Proc] Optional block to render inner HTML. If none given the value of attribute
|
27
|
+
# will be rendered instead. +block+ is not allowed for fields of type +widget+.
|
28
|
+
# @raise ArgumentError if the field behind +field_name+ is of type +widget+ and a +block+ is given.
|
29
|
+
# @return [String] The rendered html tag
|
30
|
+
#
|
31
|
+
# @example Renders an <h2> tag containing the text of the +headline+ attribute of +@obj+ and assigns the tag a css class called +very_important+.
|
32
|
+
# <%= scrivito_tag :h2, @obj, :headline, class: "very_important" %>
|
33
|
+
#
|
34
|
+
# @example Renders an <h2> tag containing an escaped +headline+.
|
35
|
+
# <%= scrivito_tag :h2, @obj, :headline do %>
|
36
|
+
# <%= strip_tags @obj.headline %>
|
37
|
+
# <% end %>
|
38
|
+
#
|
39
|
+
def scrivito_tag(tag_name, obj_or_widget, field_name, html_options = {}, &block)
|
40
|
+
Scrivito::CmsFieldTag.new(
|
41
|
+
self, tag_name, obj_or_widget, field_name.to_s
|
42
|
+
).render(html_options, &block)
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# @api public
|
47
|
+
#
|
48
|
+
# @param tag_name [String, Symbol] Name of the html tag (e.g. +:h1+ or +:div+).
|
49
|
+
# @param obj [Scrivito::BasicObj] A {Scrivito::BasicObj} from which field_name is read.
|
50
|
+
# @param field_name [String, Symbol] Which field_name of the Obj should be rendered. Currently
|
51
|
+
# only +toclist+ is supported
|
52
|
+
# @param options [Hash] Additional options, which are passed to +content_tag+. Use them to add
|
53
|
+
# HTML attributes to the tag
|
54
|
+
#
|
55
|
+
# @yieldparam [Scrivito::ChildListTag::ObjTag] list An instance, where +tag+ should be called once.
|
56
|
+
# @yieldparam [Scrivito::BasicObj] child Each child of +toclist+
|
57
|
+
#
|
58
|
+
# @return [String] The rendered html tag
|
59
|
+
#
|
60
|
+
# @example
|
61
|
+
# <%= scrivito_tag_list :div, @obj, :toclist, class: "very_important" do |list, child| %>
|
62
|
+
# <%= list.tag :div, class: "also_important" do %>
|
63
|
+
# <%= link_to scrivito_path(child) do %>
|
64
|
+
# <%= scrivito_tag :span, child, :title %>
|
65
|
+
# <% end %>
|
66
|
+
# <% end %>
|
67
|
+
# <% end %>
|
68
|
+
#
|
69
|
+
# # results for an obj with two children in
|
70
|
+
#
|
71
|
+
# <div class="very_important">
|
72
|
+
# <div class="also_important"><a href="/child1"><span>Child 1</span></a></div>
|
73
|
+
# <div class="also_important"><a href="/child2"><span>Child 2</span></a></div>
|
74
|
+
# </div>
|
75
|
+
#
|
76
|
+
def scrivito_tag_list(tag_name, obj, field_name, options = {}, &block)
|
77
|
+
Scrivito::ChildListTag.new(tag_name, obj, field_name.to_s, self).render(options, &block)
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Calculates an HTML image tag of an image storeg in the CMS for inplace editing.
|
82
|
+
#
|
83
|
+
# @api public
|
84
|
+
#
|
85
|
+
# @note If you do not specify an HTML +alt+ attribute, the helper method will use
|
86
|
+
# +display_title+ of the target object
|
87
|
+
#
|
88
|
+
# @param [Obj] obj Obj with an attribute of type +LinkList+
|
89
|
+
# @param [String, Symbol] field_name Name of +LinkList+, +reference+ or +link+ attribute,
|
90
|
+
# which contains the image
|
91
|
+
# @param [Hash] tag_options Additional HTML attributes for the tag
|
92
|
+
# @param [Hash] editing_options Additional options for inplace editing
|
93
|
+
# @option editing_options [String] :placeholder ('/assets/scrivito/image_placeholder.png') URL
|
94
|
+
# or path to image to be displayed if target is missing
|
95
|
+
#
|
96
|
+
# @example
|
97
|
+
# scrivito_image_tag @obj, :my_linklist
|
98
|
+
# scrivito_image_tag @obj, :my_linklist, alt: 'Interesting picture', class: 'my_image'
|
99
|
+
# scrivito_image_tag @obj, :my_linklist, {}, placeholder: image_path('my_placeholder.png')
|
100
|
+
# scrivito_image_tag @obj, :my_linklist, {class: 'my_image'}, placeholder: 'http://placehold.it/350x150'
|
101
|
+
#
|
102
|
+
# @example Create image tag for reference attributes.
|
103
|
+
# scrivito_image_tag @obj, :my_reference
|
104
|
+
#
|
105
|
+
# @example Create image tag for link attributes.
|
106
|
+
# scrivito_image_tag @obj, :my_link
|
107
|
+
#
|
108
|
+
# @return [String] HTML image tag
|
109
|
+
#
|
110
|
+
def scrivito_image_tag(obj, field_name, tag_options = {}, editing_options = {})
|
111
|
+
options = Scrivito::ImageTagHelper.new(self).options(obj, field_name,
|
112
|
+
tag_options.symbolize_keys, editing_options.symbolize_keys)
|
113
|
+
scrivito_tag('img', obj, field_name, options)
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Renders an attribute <em>value</em> of a CMS model.
|
118
|
+
#
|
119
|
+
# <%= scrivito_value @obj.title %>
|
120
|
+
# Renders the value, taking its type into account.
|
121
|
+
# * An HtmlString will be exported by converting its links
|
122
|
+
# * A Time will be exported in an international form: Year-Month-Day Hour:Minutes
|
123
|
+
# * A non-HTML String will be quoted
|
124
|
+
# * other values will be rendered unchanged
|
125
|
+
#
|
126
|
+
# @note Content rendered using this method
|
127
|
+
# will not be editable in the Scrivito UI.
|
128
|
+
# If you want In-Place-Editing, use {ScrivitoHelper#scrivito_tag} instead.
|
129
|
+
#
|
130
|
+
# @api public
|
131
|
+
#
|
132
|
+
def scrivito_value(value)
|
133
|
+
case value
|
134
|
+
when Scrivito::HtmlString
|
135
|
+
Scrivito::CmsRouting.new(request, main_app).convert_links(value).html_safe
|
136
|
+
when String then h(value)
|
137
|
+
when Time then h(l(value))
|
138
|
+
when Scrivito::BasicWidget
|
139
|
+
render(template: value.to_show_view_path, locals: {widget: value})
|
140
|
+
else value
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#
|
145
|
+
# Renders a field from the CMS.
|
146
|
+
#
|
147
|
+
# @api public
|
148
|
+
#
|
149
|
+
# @note Content rendered using this method will not be editable in the Scrivito UI.
|
150
|
+
# If you want in-place editing, then please use {ScrivitoHelper#scrivito_tag} instead.
|
151
|
+
#
|
152
|
+
# @param obj [Scrivito::BasicObj] an +Obj+, whose field should be rendered.
|
153
|
+
# @param field_name [String, Symbol] the field of +obj+ to be rendered.
|
154
|
+
#
|
155
|
+
# @example
|
156
|
+
# <%= scrivito_field @obj, :title %>
|
157
|
+
# <%= scrivito_field @obj, 'headline' %>
|
158
|
+
#
|
159
|
+
def scrivito_field(obj, field_name)
|
160
|
+
scrivito_value(obj[field_name])
|
161
|
+
end
|
162
|
+
|
163
|
+
#
|
164
|
+
# Thumbnail helper generates HTML for the page class selection dialog and the widget class selection dialog.
|
165
|
+
# The generated HTML has appropriate DOM structure and CSS classes, which are compatible with the CSS of the SDK.
|
166
|
+
# By using this helper you ensure, that the look of your thumbnails fits into the SDK's design.
|
167
|
+
#
|
168
|
+
# @api public
|
169
|
+
#
|
170
|
+
# @param title [String] title of the thumbnail, e.g. "Content Page" or "Image Widget".
|
171
|
+
# @param icon [Symbol, String] icon of the thumbnail.
|
172
|
+
# You can use one of the built-in icons or specify your own HTML.
|
173
|
+
# There are following built-in icons: +:content+, +:headline+, +:image+, +:scrivito+ and +:text+.
|
174
|
+
# If the name of the specyfied icon is unknown, then the default icon (+:scrivito+) will be displayed.
|
175
|
+
# If you are speifying your own HTML string, then make sure it is HTML safe.
|
176
|
+
# @param block [Proc] the description of the thumbnail.
|
177
|
+
#
|
178
|
+
# @example A simple thumbnail
|
179
|
+
# <%= scrivito_thumbnail 'Content Page' do %>
|
180
|
+
# A content page.
|
181
|
+
# <% end %>
|
182
|
+
#
|
183
|
+
# @example A thumbnail with a built-in icon
|
184
|
+
# <%= scrivito_thumbnail 'Image Widget', :image do %>
|
185
|
+
# An image widget.
|
186
|
+
# <% end %>
|
187
|
+
#
|
188
|
+
# @example A thumbnail with custom icon HTML
|
189
|
+
# <%= scrivito_thumbnail 'Blog', content_tag(:i, '', class: 'thumbnail-blog') do %>
|
190
|
+
# A blog post.
|
191
|
+
# <% end %>
|
192
|
+
#
|
193
|
+
def scrivito_thumbnail(title, icon = :scrivito, &block)
|
194
|
+
if icon.is_a?(Symbol)
|
195
|
+
icon_code = {
|
196
|
+
content: '',
|
197
|
+
headline: '',
|
198
|
+
image: '',
|
199
|
+
scrivito: '',
|
200
|
+
text: '',
|
201
|
+
}.fetch(icon, '')
|
202
|
+
icon = content_tag(:i, icon_code.html_safe, class: 'scrivito_icon')
|
203
|
+
end
|
204
|
+
|
205
|
+
content_tag(:div, class: 'scrivito_editing_widget_preview') do
|
206
|
+
capture do
|
207
|
+
concat content_tag(:div, icon, class: 'scrivito_editing_widget_visualization')
|
208
|
+
concat content_tag(:div, title, class: 'scrivito_editing_widget_title')
|
209
|
+
concat content_tag(:div, class: 'scrivito_editing_widget_description', &block)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
#
|
215
|
+
# Renders all tags needed in the HTML head.
|
216
|
+
# @api public
|
217
|
+
#
|
218
|
+
def scrivito_head_tags
|
219
|
+
layout_tags = Scrivito::LayoutTags.new(self)
|
220
|
+
capture do
|
221
|
+
concat layout_tags.editing_auth_warning
|
222
|
+
concat layout_tags.generator_meta_tag
|
223
|
+
concat layout_tags.reset_stylesheet_tag
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
#
|
228
|
+
# Renders all tags needed in the HTML body.
|
229
|
+
# @api public
|
230
|
+
#
|
231
|
+
def scrivito_body_tags
|
232
|
+
Scrivito::LayoutTags.new(self).client_config(@obj, @scrivito_resource)
|
233
|
+
end
|
234
|
+
|
235
|
+
{
|
236
|
+
'cms_image_tag' => 'scrivito_image_tag',
|
237
|
+
'cms_path' => 'scrivito_path',
|
238
|
+
'cms_tag' => 'scrivito_tag',
|
239
|
+
'cms_tag_list' => 'scrivito_tag_list',
|
240
|
+
'cms_url' => 'scrivito_url',
|
241
|
+
'display_field' => 'scrivito_field',
|
242
|
+
'display_value' => 'scrivito_value',
|
243
|
+
'render_widget' => 'scrivito_value',
|
244
|
+
'scrivito_after_content_tags' => 'scrivito_body_tags',
|
245
|
+
'scrivito_header_tags' => 'scrivito_head_tags',
|
246
|
+
}.each_pair do |old_method_name, new_method_name|
|
247
|
+
define_method(old_method_name) do |*args|
|
248
|
+
raise %{
|
249
|
+
The helper method `#{old_method_name}' has been removed.
|
250
|
+
Please use `#{new_method_name}' instead.
|
251
|
+
}
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
#
|
256
|
+
# Returns the current user.
|
257
|
+
#
|
258
|
+
# @api public
|
259
|
+
# @return [Scrivito::User] if the {Scrivito::Configuration.editing_auth} callback returns an
|
260
|
+
# instance of {Scrivito::User}.
|
261
|
+
# @return +nil+ otherwise.
|
262
|
+
#
|
263
|
+
def scrivito_user
|
264
|
+
Scrivito::EditingContextHelper.new(request).scrivito_user
|
265
|
+
end
|
266
|
+
|
267
|
+
def inplace_editing_allowed?
|
268
|
+
raise %{
|
269
|
+
The helper method `inplace_editing_allowed?' has been removed.
|
270
|
+
Please use helper method `scrivito_user` instead.
|
271
|
+
}
|
272
|
+
end
|
273
|
+
|
274
|
+
#
|
275
|
+
# Returns whether the GUI is in the +editable+ view.
|
276
|
+
#
|
277
|
+
# @api public
|
278
|
+
# @return +true+ if the current visitor is an authenticated editor, the selected workspace is
|
279
|
+
# editable and the display mode is +editing+.
|
280
|
+
# @return +false+ otherwise.
|
281
|
+
#
|
282
|
+
def scrivito_in_editable_view?
|
283
|
+
Scrivito::EditingContextHelper.new(request).in_editable_view?
|
284
|
+
end
|
285
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<div id="spam">eggs</div>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
#scrivito_editing_auth_warning {
|
3
|
+
background: #aa4040;
|
4
|
+
box-shadow: 0 0 5px rgba(0,0,0,0.6);
|
5
|
+
color: #fff;
|
6
|
+
left: 0;
|
7
|
+
margin-bottom: 47px;
|
8
|
+
padding: 10px;
|
9
|
+
position: fixed;
|
10
|
+
text-align: center;
|
11
|
+
top: 0;
|
12
|
+
width: 100%;
|
13
|
+
z-index: 111111;
|
14
|
+
}
|
15
|
+
|
16
|
+
#scrivito_editing_auth_warning a {
|
17
|
+
color: #fff;
|
18
|
+
text-decoration: underline;
|
19
|
+
}
|
20
|
+
</style>
|
21
|
+
|
22
|
+
<%= javascript_tag do %>
|
23
|
+
// Following may not rely on jQuery or any other library.
|
24
|
+
|
25
|
+
window.addEventListener('load', function() {
|
26
|
+
var wrapper = document.createElement('div');
|
27
|
+
wrapper.innerHTML = '<div id="scrivito_editing_auth_warning">' +
|
28
|
+
'In the <%= Rails.env %> environment,' +
|
29
|
+
' <a href="https://scrivito.com/permissions" target="_blank">' +
|
30
|
+
'authentication for Scrivito needs to be enabled</a>' +
|
31
|
+
' for logging in and editing content in place.' +
|
32
|
+
' <a class="scrivito_close" href="#">Close</a>' +
|
33
|
+
'</div>';
|
34
|
+
document.getElementsByTagName('body')[0].appendChild(wrapper);
|
35
|
+
|
36
|
+
var close_link = document.querySelectorAll('#scrivito_editing_auth_warning .scrivito_close')[0];
|
37
|
+
close_link.addEventListener('click', function() {
|
38
|
+
var notice = document.querySelectorAll('#scrivito_editing_auth_warning')[0];
|
39
|
+
notice.parentNode.removeChild(notice);
|
40
|
+
return false;
|
41
|
+
});
|
42
|
+
});
|
43
|
+
<% end %>
|