Module: ScrivitoHelper
- Includes:
- Scrivito::RoutingHelper
- Defined in:
- app/helpers/scrivito_helper.rb
Overview
This module provides several helper methods for rendering the CMS contents and enabling the in-place editing.
Instance Method Summary collapse
-
#scrivito_body_tags ⇒ Object
Renders all tags needed in the HTML body.
-
#scrivito_field(obj, field_name) ⇒ Object
Renders a field from the CMS.
-
#scrivito_head_tags ⇒ Object
Renders all tags needed in the HTML head.
-
#scrivito_image_tag(obj, field_name_or_tag_options = nil, tag_or_editing_options = {}, editing_options = {}) ⇒ String
Calculates an HTML image tag of an image stored in the CMS for inplace editing.
-
#scrivito_in_editable_view? ⇒ Boolean
Returns whether the GUI is in the
editable
view. -
#scrivito_tag(tag_name, obj_or_widget, field_name, html_options = {}, &block) ⇒ String
Renders a field within the given HTML tag.
-
#scrivito_tag_list(tag_name, obj, field_name, options = {}) {|list, child| ... } ⇒ String
The rendered html tag.
-
#scrivito_thumbnail(title, icon = :scrivito, &block) ⇒ Object
Thumbnail helper generates HTML for the page class selection dialog and the widget class selection dialog.
-
#scrivito_user ⇒ Scrivito::User
Returns the current user.
-
#scrivito_value(value) ⇒ Object
Renders an attribute value of a CMS model.
Methods included from Scrivito::RoutingHelper
Instance Method Details
#scrivito_body_tags ⇒ Object
Renders all tags needed in the HTML body.
276 277 278 |
# File 'app/helpers/scrivito_helper.rb', line 276 def Scrivito::LayoutTags.new(self).client_config(@obj, @scrivito_resource) end |
#scrivito_field(obj, field_name) ⇒ Object
Content rendered using this method will not be editable in the Scrivito UI. If you want in-place editing, then please use #scrivito_tag instead.
Renders a field from the CMS.
205 206 207 |
# File 'app/helpers/scrivito_helper.rb', line 205 def scrivito_field(obj, field_name) scrivito_value(obj[field_name]) end |
#scrivito_head_tags ⇒ Object
Renders all tags needed in the HTML head.
264 265 266 267 268 269 270 |
# File 'app/helpers/scrivito_helper.rb', line 264 def = Scrivito::LayoutTags.new(self) capture do concat .editing_auth_warning concat . end end |
#scrivito_image_tag(obj, field_name_or_tag_options = nil, tag_or_editing_options = {}, editing_options = {}) ⇒ String
If you do not specify an HTML alt
attribute, the helper method will use display_title
of the target object
Calculates an HTML image tag of an image stored in the CMS for inplace editing.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/scrivito_helper.rb', line 139 def scrivito_image_tag(obj, =nil, = {}, = {}) field_name, , = if .is_a?(Hash) [nil, , ] else [, , ] end if field_name.blank? if obj.binary? field_name = :blob else raise Scrivito::ScrivitoError, "when omitting `field_name' you have to pass a binary obj" end end = Scrivito::ImageTagHelper.new(self).(obj, field_name, .with_indifferent_access, .with_indifferent_access) scrivito_tag('img', obj, field_name, ) end |
#scrivito_in_editable_view? ⇒ Boolean
Returns whether the GUI is in the editable
view.
327 328 329 |
# File 'app/helpers/scrivito_helper.rb', line 327 def scrivito_in_editable_view? Scrivito::EditingContextHelper.new(request).in_editable_view? end |
#scrivito_tag(tag_name, obj_or_widget, field_name, html_options = {}, &block) ⇒ String
If the param field_name
is of type widget
, then tag_name
must be a block tag, like div
or h1
. An inline tag like p
or span
could result in broken HTML output, since the widgets are rendered within block tags.
Renders a field within the given HTML tag.
This method also renders additional attributes, which are needed for in-place editing. These attributes are only rendered when appropriate, i.e. not for a regular visitor.
The helper is similar to (and internally uses) api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag. You can add additional HTML attributes by passing them in html_options
.
58 59 60 61 62 |
# File 'app/helpers/scrivito_helper.rb', line 58 def scrivito_tag(tag_name, , field_name, = {}, &block) Scrivito::CmsFieldTag.new( self, tag_name, , field_name.to_s ).render(, &block) end |
#scrivito_tag_list(tag_name, obj, field_name, options = {}) {|list, child| ... } ⇒ String
Returns The rendered html tag.
95 96 97 |
# File 'app/helpers/scrivito_helper.rb', line 95 def scrivito_tag_list(tag_name, obj, field_name, = {}, &block) Scrivito::ChildListTag.new(tag_name, obj, field_name.to_s, self).render(, &block) end |
#scrivito_thumbnail(title, icon = :scrivito, &block) ⇒ Object
Thumbnail helper generates HTML for the page class selection dialog and the widget class selection dialog. The generated HTML has appropriate DOM structure and CSS classes, which are compatible with the CSS of the SDK. By using this helper you ensure, that the look of your thumbnails fits into the SDK’s design.
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'app/helpers/scrivito_helper.rb', line 239 def scrivito_thumbnail(title, icon = :scrivito, &block) if icon.is_a?(Symbol) icon_code = { content: '', headline: '', image: '', scrivito: '', text: '', }.fetch(icon, '') icon = content_tag(:i, icon_code.html_safe, class: 'scrivito_icon') end content_tag(:div, class: 'scrivito_editing_widget_preview') do capture do concat content_tag(:div, icon, class: 'scrivito_editing_widget_visualization') concat content_tag(:div, title, class: 'scrivito_editing_widget_title') concat content_tag(:div, class: 'scrivito_editing_widget_description', &block) end end end |
#scrivito_user ⇒ Scrivito::User
Returns the current user.
308 309 310 |
# File 'app/helpers/scrivito_helper.rb', line 308 def scrivito_user Scrivito::EditingContextHelper.new(request).scrivito_user end |
#scrivito_value(value) ⇒ Object
Content rendered using this method will not be editable in the Scrivito UI. If you want In-Place-Editing, use #scrivito_tag instead.
Renders an attribute value of a CMS model.
<%= scrivito_value @obj.title %>
Renders the value, taking its type into account.
-
An HtmlString will be exported by converting its links
-
A Time will be exported in an international form: Year-Month-Day Hour:Minutes
-
A non-HTML String will be quoted
-
other values will be rendered unchanged
178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/helpers/scrivito_helper.rb', line 178 def scrivito_value(value) case value when Scrivito::HtmlString Scrivito::CmsRouting.new(request, main_app).convert_links(value).html_safe when String then h(value) when Time then h(l(value)) when Scrivito::BasicWidget render(template: value.to_show_view_path, locals: {widget: value}) else value end end |