Class: CodeEditorInput
- Inherits:
-
SimpleForm::Inputs::TextInput
- Object
- SimpleForm::Inputs::TextInput
- CodeEditorInput
show all
- Defined in:
- app/inputs/code_editor_input.rb
Overview
Uses the CodeMirror editor
Instance Method Summary
collapse
Instance Method Details
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/inputs/code_editor_input.rb', line 4
def input(wrapper_options)
options[:mode] = (options[:mode] || 'markdown').downcase
editor_mode = case options[:mode]
when 'textile'
:htmlmixed when 'markdown'
:markdown
when 'html'
:htmlmixed
else
:markdown
end
input_html_options['codemirror-editor'] = ""
input_html_options['data-mode'] = editor_mode
input_html_options['data-theme'] = options[:theme] || :default
editor_id = "codemirror_container_#{rand(1000)}"
out = ''
out << "<div class='cm_toolbar'>"
out << " <a class='cm_cmd_bold_#{options[:mode]}' href='javascript:void(0);' data-editor='\##{editor_id}'><i class='icon-bold'></i></a>"
out << " <a class='cm_cmd_italic_#{options[:mode]}' href='javascript:void(0);' data-editor='\##{editor_id}'><i class='icon-italic'></i></a>"
out << " <a class='cm_cmd_link_#{options[:mode]}' href='javascript:void(0);' data-editor='\##{editor_id}'><i class='icon-link5'></i></a>"
out << " <a class='cm_cmd_fullscreen' title='Fullscreen (Esc exits)' href='javascript:void(0);' data-editor='\##{editor_id}'><i class='icon-expand'></i></a>"
out << "</div>"
out << "<div id='#{editor_id}'>"
(out << @builder.text_area(attribute_name, input_html_options)).html_safe
out << "</div>"
end
|