Module: DynamicText::ViewHelper

Defined in:
app/helpers/dynamic_text/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_text(text = "", tag: "default", filler: "N/A") ⇒ Object



3
4
5
6
# File 'app/helpers/dynamic_text/view_helper.rb', line 3

def dynamic_text(text="", tag: "default", filler: "N/A")
  text = filler if !text || text.empty?
  (:span, text, class: "dynamic-text", data: {"dynamic-tag": tag})
end

#dynamic_text_for(resource, attribute, options = {}) ⇒ Object



14
15
16
17
# File 'app/helpers/dynamic_text/view_helper.rb', line 14

def dynamic_text_for(resource, attribute, options={})
  options = dynamic_attributes(resource, attribute, options)
  dynamic_text_tag(options)
end

#editable_text(text = "", tag: "default", placeholder: "Enter text...") ⇒ Object



8
9
10
11
12
# File 'app/helpers/dynamic_text/view_helper.rb', line 8

def editable_text(text="", tag: "default", placeholder: "Enter text...")
  (:span, class: "editable-text-container") do
    (:span, text, class: "editable-text", contenteditable: true, placeholder: placeholder, data: {"dynamic-tag": tag})
  end
end

#editable_text_for(resource, attribute, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/dynamic_text/view_helper.rb', line 19

def editable_text_for(resource, attribute, options = {})
  options = editable_attributes(resource, attribute, options)

  (:span, class: "editable-text-container") do
    editable_text_tag(options) +
    patch_request_tag(options)
  end
end