Module: LatoCms::PagesHelper

Defined in:
app/helpers/lato_cms/pages_helper.rb

Constant Summary collapse

BUILTIN_FIELD_TYPES =
%w[string textarea text number date datetime boolean select multiselect color json file image gallery].freeze

Instance Method Summary collapse

Instance Method Details

#lato_cms_attachment_path(attachment) ⇒ Object

Returns the path for an Active Storage attachment. Using main_app avoids the missing ‘attachment_path` error inside the engine.



7
8
9
10
11
# File 'app/helpers/lato_cms/pages_helper.rb', line 7

def lato_cms_attachment_path(attachment)
  main_app.rails_blob_path(attachment.blob, only_path: true)
rescue StandardError
  '#'
end

#lato_cms_page_actions(page, show_edit: false, show_delete: false, hide_show: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/lato_cms/pages_helper.rb', line 20

def lato_cms_page_actions(page, show_edit: false, show_delete: false, hide_show: false)
  btn_group = capture do
    (:div, class: 'btn-group btn-group-sm') do
      concat(link_to(t('lato_cms.cta_show'), lato_cms.pages_show_path(page), class: 'btn btn-primary')) unless hide_show
      if show_edit
        concat link_to(t('lato_cms.cta_edit'), lato_cms.pages_update_path(page), class: 'btn btn-secondary',
          data: { lato_action_target: 'trigger', turbo_frame: dom_id(page, 'form'), action_title: t('lato_cms.page_update_title') })
      end
      if show_delete
        concat link_to(t('lato_cms.cta_delete'), lato_cms.pages_destroy_action_path(page), class: 'btn btn-danger',
          data: { turbo_method: 'DELETE', turbo_confirm: t('lato_cms.cta_delete_confirm') })
      end
    end
  end

  (:div, class: 'd-flex align-items-center gap-2') do
    if page.frontend_url.blank?
      concat (:span, t('lato_cms.action_view_frontend'), class: 'btn btn-sm btn-link px-0 disabled text-muted')
    else
      concat link_to(t('lato_cms.action_view_frontend'), page.frontend_url, class: 'btn btn-sm btn-link px-0', target: '_blank')
    end
    concat btn_group
  end
end

#lato_cms_page_locale(page) ⇒ Object



13
14
15
16
17
18
# File 'app/helpers/lato_cms/pages_helper.rb', line 13

def lato_cms_page_locale(page)
  (:span, class: 'badge bg-secondary') do
    concat locale_to_flag(page.locale)
    concat " #{page.locale.upcase}"
  end
end

#lato_cms_render_field(field_id:, field_config:, page_field:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/lato_cms/pages_helper.rb', line 45

def lato_cms_render_field(field_id:, field_config:, page_field:)
  render resolve_lato_cms_field_partial(field_config),
    field_id: field_id,
    field_config: field_config,
    page_field: page_field
rescue ActionView::MissingTemplate => e
  (:div, class: 'alert alert-danger mb-0') do
    "Field '#{field_id}' render error: #{e.message}"
  end
end