Class: Locomotive::RteInput

Inherits:
SimpleForm::Inputs::Base
  • Object
show all
Includes:
SimpleForm::Inputs::FasterTranslate
Defined in:
app/inputs/locomotive/rte_input.rb

Direct Known Subclasses

MarkdownInput

Defined Under Namespace

Classes: ImageForm, LinkForm, TableForm

Instance Method Summary collapse

Methods included from SimpleForm::Inputs::FasterTranslate

#translate_from_namespace

Instance Method Details

#image_popoverObject



28
29
30
31
32
33
# File 'app/inputs/locomotive/rte_input.rb', line 28

def image_popover
  remove_form(template.render(
    partial:  'locomotive/shared/rte/image_popover',
    locals:   { image_form: ImageForm.new }
  )).html_safe
end

#input(wrapper_options) ⇒ Object



6
7
8
9
# File 'app/inputs/locomotive/rte_input.rb', line 6

def input(wrapper_options)
  input_html_options[:class] << 'form-control'
  toolbar_html + @builder.text_area(attribute_name, input_html_options)
end


35
36
37
38
39
40
# File 'app/inputs/locomotive/rte_input.rb', line 35

def link_popover
  remove_form(template.render(
    partial:  'locomotive/shared/rte/link_popover',
    locals:   { link_form: LinkForm.new }
  )).html_safe
end

#remove_form(template) ⇒ Object



49
50
51
52
53
# File 'app/inputs/locomotive/rte_input.rb', line 49

def remove_form(template)
  template.gsub(/<form([^<]*)>/, '')
    .gsub(/<input name="(utf8|authenticity_token)"([^<]*)>/, '')
    .gsub('</form>', '')
end

#table_popoverObject



42
43
44
45
46
47
# File 'app/inputs/locomotive/rte_input.rb', line 42

def table_popover
  remove_form(template.render(
    partial:  'locomotive/shared/rte/table_popover',
    locals:   { table_form: TableForm.new }
  )).html_safe
end

#toolbar_htmlObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/inputs/locomotive/rte_input.rb', line 11

def toolbar_html
  template.render(
    partial:  'locomotive/shared/rte/toolbar',
    locals:   {
      wysihtml5_prefix: wysihtml5_prefix,
      link_popover:     link_popover,
      image_popover:    image_popover,
      table_popover:    table_popover,
      inline:           input_html_options[:data].try(:[], :inline)
    })
end

#wysihtml5_prefixObject



23
24
25
26
# File 'app/inputs/locomotive/rte_input.rb', line 23

def wysihtml5_prefix
  _object_name = @builder.template.send(:sanitize_to_id, object_name)
  "#{_object_name}_#{attribute_name}"
end