Module: Cms::ContentBlockHelper
- Defined in:
- app/helpers/cms/content_block_helper.rb
Instance Method Summary collapse
-
#block_row_tag(block) ⇒ Object
Prints the <tr> for each block.
- #class_name_for(block) ⇒ Object
-
#content_block_tr_tag(block) ⇒ Object
For each row in content block table, we need to output all the paths for the actions in a way that JS can read them.
Instance Method Details
#block_row_tag(block) ⇒ Object
Prints the <tr> for each block. Adds classes based on:
-
Name/id of the block
-
If a block is published/draft
-
If the user can edit/publish it
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/cms/content_block_helper.rb', line 11 def block_row_tag(block) cname = class_name_for(block) can_modify = current_user.able_to_modify?(block) = { :id => "#{cname}_#{block.id}", :class => cname } [:class] += block.class.publishable? && !block.published? ? ' draft' : ' published' [:class] += ' non-editable' unless can_modify && current_user.able_to?(:edit_content) [:class] += ' non-publishable' unless can_modify && current_user.able_to?(:publish_content) tag "tr", , true end |
#class_name_for(block) ⇒ Object
50 51 52 |
# File 'app/helpers/cms/content_block_helper.rb', line 50 def class_name_for(block) block.class.name.underscore end |
#content_block_tr_tag(block) ⇒ Object
For each row in content block table, we need to output all the paths for the actions in a way that JS can read them. We use ‘data-’ elements here to avoid duplication of path calculations.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/helpers/cms/content_block_helper.rb', line 29 def content_block_tr_tag(block) cname = class_name_for(block) can_modify = current_user.able_to_modify?(block) = {} data = [:data] = {} data[:status] = block.class.publishable? && !block.published? ? ' draft' : ' published' [:id] = "#{cname}_#{block.id}" [:class] = [cname] [:class] << 'non-editable' unless can_modify && current_user.able_to?(:edit_content) [:class] << 'non-publishable' unless can_modify && current_user.able_to?(:publish_content) ['data-new_path'] = url_for(new_block_path(block)) ['data-view_path'] = url_for(block_path(block)) ['data-edit_path'] = url_for(block_path(block, :edit)) ['data-versions_path'] = url_for(block_path(block, :versions)) if block.class.versioned? ['data-delete_path'] = url_for(block_path(block)) ['data-publish_path'] = url_for(block_path(block, :publish)) if block.class.publishable? tag "tr", , true end |