Module: ContentBlocksHelper
- Included in:
- CmsApplicationHelpers
- Defined in:
- lib/generators/ruby_cms/templates/helpers/content_blocks_helper.rb
Instance Method Summary collapse
- #content_block(key, default_or_nil = nil, locale: nil, fallback: nil, default: nil, translation_namespace: nil, **options) ⇒ Object (also: #cms_content_block)
- #content_block_list_items(key, locale: nil, fallback: nil) ⇒ Object (also: #cms_content_block_list_items)
- #content_block_text(key, locale: nil, default: nil, fallback: nil, translation_namespace: nil) ⇒ Object (also: #cms_content_block_text)
Instance Method Details
#content_block(key, default_or_nil = nil, locale: nil, fallback: nil, default: nil, translation_namespace: nil, **options) ⇒ Object Also known as: cms_content_block
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/ruby_cms/templates/helpers/content_blocks_helper.rb', line 4 def content_block(key, default_or_nil = nil, locale: nil, fallback: nil, default: nil, translation_namespace: nil, **) default = default_or_nil.kind_of?(Hash) ? default : (default_or_nil || default) cache_opts = .delete(:cache) wrap = .delete(:wrap) wrap = true if wrap.nil? cache_key = cache_key_for_content_block(key, cache_opts) if cache_opts && cache_key Rails.cache.fetch(cache_key) do render_content_block(key, locale, default, fallback, translation_namespace, , wrap:) end else render_content_block(key, locale, default, fallback, translation_namespace, , wrap:) end end |
#content_block_list_items(key, locale: nil, fallback: nil) ⇒ Object Also known as: cms_content_block_list_items
33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/ruby_cms/templates/helpers/content_blocks_helper.rb', line 33 def content_block_list_items(key, locale: nil, fallback: nil) locale = normalize_locale(locale) block = find_content_block(key, locale) return Array(fallback) if block.blank? raw = block.content.to_s items = parse_list_items(raw) items.presence || Array(fallback) end |
#content_block_text(key, locale: nil, default: nil, fallback: nil, translation_namespace: nil) ⇒ Object Also known as: cms_content_block_text
24 25 26 27 28 29 |
# File 'lib/generators/ruby_cms/templates/helpers/content_blocks_helper.rb', line 24 def content_block_text(key, locale: nil, default: nil, fallback: nil, translation_namespace: nil) locale = normalize_locale(locale) block = find_content_block(key, locale) content = content_for_block_text(block, default, fallback, key, translation_namespace, locale) (content) end |