Module: Cms::RenderingHelper
- Defined in:
- app/helpers/cms/rendering_helper.rb
Instance Method Summary collapse
-
#attachment_viewer(content) ⇒ Object
Renders a table of attachments for a given content block.
-
#content_supports_inline_editing?(connector) ⇒ Boolean
Some content doesn’t have inline editing, so we need to conditionally show move up/down/remove buttons on the page.
-
#is_current_user_able_to_edit_this_content?(content) ⇒ Boolean
(also: #is_editing_page?)
Determines if the current user can edit and is currently editing this content.
- #page_content_iframe(path) ⇒ Object
-
#render_cms_toolbar(tab = :dashboard) ⇒ Object
Renders the toolbar for the CMS.
- #render_connectable(content_block) ⇒ Object
- #render_connector_and_connectable(connector, connectable) ⇒ Object
-
#show(method, options = {}) ⇒ Object
Renders the content for the given field from the current content block.
Instance Method Details
#attachment_viewer(content) ⇒ Object
Renders a table of attachments for a given content block. This is intended as a basic view of the content, and probably won’t be suitable for blocks that need to be added directly to pages.
52 53 54 |
# File 'app/helpers/cms/rendering_helper.rb', line 52 def (content) render :partial => 'cms/attachments/attachment_table', :locals => {:block => content, :can_delete => false} end |
#content_supports_inline_editing?(connector) ⇒ Boolean
Some content doesn’t have inline editing, so we need to conditionally show move up/down/remove buttons on the page
90 91 92 93 |
# File 'app/helpers/cms/rendering_helper.rb', line 90 def content_supports_inline_editing?(connector) content = connector.connectable content.supports_inline_editing? end |
#is_current_user_able_to_edit_this_content?(content) ⇒ Boolean Also known as: is_editing_page?
Determines if the current user can edit and is currently editing this content.
57 58 59 |
# File 'app/helpers/cms/rendering_helper.rb', line 57 def is_current_user_able_to_edit_this_content?(content) content && logged_in? && edit_mode? && current_user.able_to_edit?(content) end |
#page_content_iframe(path) ⇒ Object
8 9 10 11 12 |
# File 'app/helpers/cms/rendering_helper.rb', line 8 def page_content_iframe(path) content_tag "iframe", "" , src: path, id: 'page_content', frameborder: 0, width: '100%', height: '80%' #<iframe id="page_content" src="<%= url_for engine_aware_path(@block, :inline) %>" frameborder="0" width="100%" height="80%"></iframe> end |
#render_cms_toolbar(tab = :dashboard) ⇒ Object
Renders the toolbar for the CMS. All page templates need to include this or they won’t be editable. Typically rendered as an iframe to avoid CSS/JS conflicts.
100 101 102 |
# File 'app/helpers/cms/rendering_helper.rb', line 100 def (tab=:dashboard) render :partial => 'layouts/cms_toolbar', :locals => {:tab => tab} end |
#render_connectable(content_block) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'app/helpers/cms/rendering_helper.rb', line 72 def render_connectable(content_block) if content_block if content_block.class.renderable? Rails.logger.debug "Rendering connectable #{content_block.class} ##{content_block.id} #{"v#{content_block.version}" if content_block.respond_to?(:version)}" content_block.perform_render(controller) else Rails.logger.warn "Connectable #{content_block.class} ##{content_block.id} is not renderable" end else Rails.logger.warn "Connectable is null" end rescue Exception => e Cms::ErrorHandling::NotifierService.notify e Rails.logger.error "Error occurred while rendering #{content_block.class}##{content_block.id}: #{e.message}\n#{e.backtrace.join("\n")}" "ERROR: #{e.message}" end |
#render_connector_and_connectable(connector, connectable) ⇒ Object
64 65 66 67 68 69 70 |
# File 'app/helpers/cms/rendering_helper.rb', line 64 def render_connector_and_connectable(connector, connectable) if is_current_user_able_to_edit_this_content?(connector.page) render(:partial => 'cms/pages/edit_content', :locals => {:connector => connector, :connectable => connectable}) else render_connectable(connectable) end end |
#show(method, options = {}) ⇒ Object
Renders the content for the given field from the current content block. Designed to be used in Block Templates instead of direct output of fields.
Example:
<pre><%= show :content %></pre>
Instead of:
<pre><%= @content_block.content.html_safe %></pre>
Why bother?: This abstracts the actual variable name (makes future upgrades more robust),
as well as let us mark up the content with html_safe,
plus conditionally make fields editable.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/helpers/cms/rendering_helper.rb', line 26 def show(method, ={}) if (!is_current_user_able_to_edit_this_content?(@content_block)) # Need to check the current user can edit the page attached to this block too value = @content_block.send(method) value.respond_to?(:html_safe) ? value.html_safe : value else content_tag 'div', id: random_unique_identifier(), class: 'content-block', contenteditable: true, data: { content_name: @content_block.content_name, id: @content_block.id, attribute: method, page_id: @page.id } do content = @content_block.send(method) content.to_s.html_safe end end end |