Module: HeraCms::TagHelper

Defined in:
app/helpers/hera_cms/tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#hera_admin_navbarObject



4
5
6
# File 'app/helpers/hera_cms/tag_helper.rb', line 4

def hera_admin_navbar
  render 'hera_cms/shared/navbar'
end


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/hera_cms/tag_helper.rb', line 8

def hera_link(identifier, args = {}, &block)
  link = HeraCms::Link.identify(identifier)
  inner_text, style, identifier, path = link.inner_text, link.style, link.identifier, link.path
  classes = set_classes(args, link)

  html_options = {
    class: classes,
    style: style,
    id: identifier,
    data: { editable_id: link.id, editable_type: link.model_name.route_key}
  }

  args[:attributes]&.each do |key, value|
    html_options[key] = value
  end

  if block_given?
    link_to(path, html_options, &block)
  else
    link_to(inner_text, path, html_options)
  end
end

#hera_text(identifier, args = {}) ⇒ Object

Generate HTML tag



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/hera_cms/tag_helper.rb', line 74

def hera_text(identifier, args = {})
  text = Text.identify(identifier)
  inner_text, style, identifier = text.inner_text, text.style, text.identifier
  classes = set_classes(args, text)
  args[:html_tag] ||= "p"

  html_options = {
    class: classes,
    style: style,
    id: identifier,
    data: { editable_id: text.id, editable_type: text.model_name.route_key}
  }
  return (args[:html_tag].to_sym, inner_text, html_options)
end

#set_classes(args, editable) ⇒ Object



114
115
116
117
118
# File 'app/helpers/hera_cms/tag_helper.rb', line 114

def set_classes(args, editable)
  args[:add_class] ||= ""
  classes = "#{ args[:class] || editable.classes } #{args[:add_class]}"
  classes += " hera-editable" unless args[:editable] == false || editable.classes.include?("hera-editable") || !editable.editable?
end

#set_editable(editable) ⇒ Object

def hera_form(identifier, args = {})

form = Form.identify(identifier)
set_editable(form) unless args[:editable] == false
identifier, send_to, classes, style = form.identifier, form.send_to, form.classes, form.style
html_options = {
  class: classes,
  style: style,
  id: identifier,
  data: { editable_id: form.id, editable_type: form.model_name.route_key, mail: form.send_to}
}
form_tag("/contact", html_options ) do
  concat hidden_field_tag("form_id", form.id)
  concat text_field_tag('name',"", placeholder: "Nome")
  concat text_field_tag('email',"", placeholder: "E-mail")
  concat text_field_tag('phone',"", placeholder: "Telefone")
  concat text_area_tag('message',"", placeholder: "Digite sua mensagem aqui")
  concat submit_tag('Enviar')
end

end



110
111
112
# File 'app/helpers/hera_cms/tag_helper.rb', line 110

def set_editable(editable)
  editable.classes += " hera-editable" if editable.editable? && (editable.classes && !editable.classes.include?("hera-editable"))
end