Module: Katalyst::Content::FrontendHelper

Includes:
TableHelper
Defined in:
app/helpers/katalyst/content/frontend_helper.rb

Instance Method Summary collapse

Methods included from TableHelper

#normalize_content_table, #sanitize_content_table

Instance Method Details

#content_item_tag(item) ⇒ Object



40
41
42
# File 'app/helpers/katalyst/content/frontend_helper.rb', line 40

def content_item_tag(item, ...)
  FrontendBuilder.new(self, item).render(...)
end

#content_items_tag(tag, content_theme:, **attributes) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'app/helpers/katalyst/content/frontend_helper.rb', line 44

def content_items_tag(tag, content_theme:, **attributes, &)
  html_attributes = {
    class: "content-items",
    data:  {
      content_theme:,
    },
  }.merge_html(attributes)
  (tag, **html_attributes, &)
end

#render_content(version) ⇒ ActiveSupport::SafeBuffer, ...

Render all items from a content version as HTML Example usage:

<%= render_content(version) %>

Parameters:

Returns:

  • (ActiveSupport::SafeBuffer, String, nil)

    Content as HTML



15
16
17
18
19
20
21
22
23
# File 'app/helpers/katalyst/content/frontend_helper.rb', line 15

def render_content(version)
  capture do
    cache version do
      without_partial_path_prefix do
        concat(render_content_items(*version.tree.select(&:visible?), class: "flow"))
      end
    end
  end
end

#render_content_items(*items, tag: :div, theme: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/katalyst/content/frontend_helper.rb', line 25

def render_content_items(*items, tag: :div, theme: nil, **)
  items = items.flatten.select(&:visible?)

  grouped_items = items.slice_when { |first, second| first.theme != second.theme }

  grouped_items.each do |siblings|
    content_theme = (siblings.first.theme if siblings.first.theme != theme)
    concat(content_items_tag(tag, content_theme:, **) do
      without_partial_path_prefix do
        concat(render(partial: siblings))
      end
    end)
  end
end

#without_partial_path_prefixObject



54
55
56
57
58
59
60
61
# File 'app/helpers/katalyst/content/frontend_helper.rb', line 54

def without_partial_path_prefix
  current = prefix_partial_path_with_controller_namespace

  self.prefix_partial_path_with_controller_namespace = false
  yield
ensure
  self.prefix_partial_path_with_controller_namespace = current
end