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



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

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

#idObject



12
13
14
# File 'app/inputs/markdown_input.rb', line 12

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

#input_html_optionsObject



24
25
26
27
28
# File 'app/inputs/markdown_input.rb', line 24

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

#markdown_hintObject



30
31
32
# File 'app/inputs/markdown_input.rb', line 30

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



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

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

#to_htmlObject



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

def to_html
  self.options[:hint] = markdown_hint if self.options[:hint].blank?
  bootstrap_wrapping do
    builder.text_area(method, form_control_input_html_options) +
    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
end