# Uses the CodeMirror editor
#------------------------------------------------------------------------------
class CodeEditorInput < SimpleForm::Inputs::TextInput
def input(wrapper_options)
options[:mode] = (options[:mode] || 'markdown').downcase
editor_mode = case options[:mode]
when 'textile'
:htmlmixed # no textile mode available
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 << "
"
out << ""
(out << @builder.text_area(attribute_name, input_html_options)).html_safe
out << "
"
end
end
# def input(wrapper_options)
# # :preview_version is a custom attribute from :input_html hash, so you can pick custom sizes
# version = input_html_options.delete(:preview_version)
# out = '' # the output string we're going to build
#
# # append file input. it will work accordingly with your simple_form wrappers
# (out << @builder.file_field(attribute_name, input_html_options)).html_safe
#
# # check if there's an uploaded file (eg: edit mode or form not saved)
# if object.send("#{attribute_name}?")
# # append preview image to output
# out << template.image_tag(object.send(attribute_name).tap {|o| break o.send(version) if version}.send('url'))
# end
# return out
# end