Class: MarkdownInput

Inherits:
FormtasticBootstrap::Inputs::TextInput
  • Object
show all
Defined in:
app/inputs/markdown_input.rb

Instance Method Summary collapse

Instance Method Details

#editor_idObject



23
24
25
# File 'app/inputs/markdown_input.rb', line 23

def editor_id
  "#{dom_id}_editor-#{id}"
end

#idObject



15
16
17
# File 'app/inputs/markdown_input.rb', line 15

def id
  builder.object.id || 'new'
end

#input_html_optionsObject



27
28
29
30
31
# File 'app/inputs/markdown_input.rb', line 27

def input_html_options
  {
    class: "col-md-12",
  }.merge(super).merge(id: textarea_id)
end

#markdown_hintObject



33
34
35
# File 'app/inputs/markdown_input.rb', line 33

def markdown_hint
  "Use markdown syntax for formatting. You can also use HTML directly. <a href=\"#{builder.template.guide_path('markdown')}\" data-toggle=\"remote-load\" data-target=\"#content-guide\">See our markdown syntax reference</a>".html_safe
end

#textarea_idObject



19
20
21
# File 'app/inputs/markdown_input.rb', line 19

def textarea_id
  "#{dom_id}-#{id}"
end

#to_htmlObject



3
4
5
6
7
8
9
10
11
12
13
# File 'app/inputs/markdown_input.rb', line 3

def to_html
  self.options[:hint] = markdown_hint if self.options[:hint].blank?
  bootstrap_wrapping do
    text_area = builder.text_area(method, form_control_input_html_options)
    editor = builder.template. :div do
      builder.template.(:div, nil, id: editor_id, class: 'ace_editor', data: { id: id, type: :markdown, name: dom_id, init: "$('##{editor_id}').smithy_editor()".html_safe, assets_url: builder.template.selector_modal_assets_path, pages_url: builder.template.selector_modal_pages_path }) +
      builder.template.(:div, nil, id: 'content-guide')
    end
    text_area + editor
  end
end