Module: BlockyHelper
- Defined in:
- app/helpers/blocky_helper.rb
Overview
Rails view helper for rendering Blocky content inside view templates.
Instance Method Summary collapse
-
#blocky(content_key, &block) ⇒ Object
Render a Blocky content block with the given unique key.
Instance Method Details
#blocky(content_key, &block) ⇒ Object
Render a Blocky content block with the given unique key. If a block is given, the content inside the block will be saved if it doesn’t already exist for the given key.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/helpers/blocky_helper.rb', line 6 def blocky(content_key, &block) content_block = Blocky::ContentBlock.where(content_key: content_key).first_or_initialize if content_block.new_record? content_block.content = capture(&block) if block_given? content_block.save end if try(:current_admin_user) edit_text = "Edit" edit_text += '<span style="font-weight: normal; margin-left: 0.5em;">' edit_text += content_block.display_name edit_text += "</span>" raw("#{link_to(raw(edit_text), edit_admin_content_block_path(content_block), style: edit_link_style)}#{content_block.content}") else Rails.cache.fetch(content_block, skip_digest: true) do raw(content_block.content) end end end |