Module: LeanCms::ContentHelper

Defined in:
app/helpers/lean_cms/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_edit_cms?Boolean

Check if current user can edit CMS content

Returns:

  • (Boolean)


23
24
25
# File 'app/helpers/lean_cms/content_helper.rb', line 23

def can_edit_cms?
  current_user&.has_any_cms_permission?
end

Show edit link if user is CMS editor



28
29
30
31
32
# File 'app/helpers/lean_cms/content_helper.rb', line 28

def cms_edit_link(path, text: "Edit", css_class: "")
  return unless can_edit_cms?

  link_to text, path, class: "cms-edit-link #{css_class}".strip
end

#render_editable_section(page_key, section_key, default: nil, **options) ⇒ Object

Render editable content section



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/lean_cms/content_helper.rb', line 4

def render_editable_section(page_key, section_key, default: nil, **options)
  content = LeanCms::PageContent.for_section(page_key, section_key)

  if content.persisted?
    case content.content_type.to_sym
    when :rich
      (:div, content.rich_content, **options)
    when :markdown
      # TODO: Add markdown rendering with a gem like Redcarpet
      (:div, simple_format(content.content), **options)
    else
      (:div, content.content, **options)
    end
  else
    default
  end
end