Class: Locomotive::CodeInput

Inherits:
Formtastic::Inputs::TextInput
  • Object
show all
Defined in:
app/inputs/locomotive/code_input.rb

Instance Method Summary collapse

Instance Method Details

#copy_from_main_locale_htmlObject



39
40
41
42
43
44
45
46
47
48
# File 'app/inputs/locomotive/code_input.rb', line 39

def copy_from_main_locale_html
  url = options.delete(:main_locale_template_url)

  return nil unless url

  template.link_to(
    template.(:i, '', class: 'icon-download') +
    template.t('locomotive.code_editing.copy_template'),
    url, id: 'copy-template-link', class: 'copy')
end

#hint_textObject



10
11
12
# File 'app/inputs/locomotive/code_input.rb', line 10

def hint_text
  localized_string(method, options[:hint], :hint)
end

#image_picker_htmlObject



30
31
32
33
34
35
36
37
# File 'app/inputs/locomotive/code_input.rb', line 30

def image_picker_html
  return nil if options.delete(:picker) == false

  template.link_to(
    template.(:i, '', class: 'icon-picture') +
    template.t('locomotive.code_editing.image_picker'),
    template.theme_assets_path, id: 'image-picker-link', class: 'picture')
end

#input_wrapping(&block) ⇒ Object



4
5
6
7
8
# File 'app/inputs/locomotive/code_input.rb', line 4

def input_wrapping(&block)
  elements = [template.capture(&block), error_html, toolbar_html, hint_html]

  template.(:li, elements.join("\n").html_safe, wrapper_html_options)
end

#to_htmlObject



14
15
16
17
18
# File 'app/inputs/locomotive/code_input.rb', line 14

def to_html
  input_wrapping do
    builder.text_area(method, input_html_options)
  end
end

#toolbar_htmlObject



20
21
22
23
24
25
26
27
28
# File 'app/inputs/locomotive/code_input.rb', line 20

def toolbar_html
  elements = [image_picker_html, copy_from_main_locale_html].compact

  return '' if elements.size == 0

  template.(:div,
    elements.join(' | ').html_safe,
    class: 'more error-anchor')
end