Sha256: ceb95e654dd14d213b97f154e9c33e6f1c6cf289207362611addb141b302022e

Contents?: true

Size: 1.66 KB

Versions: 14

Compression:

Stored size: 1.66 KB

Contents

class BsAceeditorInput < Formtastic::Inputs::StringInput
  include FormtasticBootstrap::Inputs::Base
  include FormtasticBootstrap::Inputs::Base::Collections
  include ActionView::Helpers::TagHelper
  include ActionView::Context
  include FontAwesome::Rails::IconHelper
  include ActionView::Helpers::JavaScriptHelper


  ##
  # Nel caso di collection si può definire con
  # :show_hidden => [true] per stampare il campo hidden o meno con il vero valore
  # :display_field come options quale campo usare per stampare
  #
  def to_html

    theme = options[:theme] || 'twilight'
    mode = options[:mode] || 'ruby'
    height = options[:height] || '300px'

    bootstrap_wrapping do
      content_tag(:div) do

        id = SecureRandom.hex

        buff = ActiveSupport::SafeBuffer.new

        buff<< content_tag(:div, :class => "container_editor clearfix", :style => 'width:100%;') do
          content_tag(:div, object.send(method), id: id, style: "height:#{height};width:100px;")
        end

        id_hidden = SecureRandom.hex
        buff<< builder.hidden_field(method, form_control_input_html_options.merge(:id => id_hidden))

        buff<< content_tag(:script, :type => "text/javascript") do
          raw "var editor = ace.edit('#{id}');\n
             editor.setTheme('ace/theme/#{theme}');\n
             editor.getSession().setMode('ace/mode/#{mode}');\n
             $('##{id}').width($('##{id}').closest('.container_editor').width());\n
             editor.resize();\n
             editor.getSession().on('change', function(e) {
                  $('##{id_hidden}').val(editor.getValue());
             });
             "
        end

        buff

      end
    end
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
kono_utils-1.0.1 app/input/bs_aceeditor_input.rb
kono_utils-1.0.0 app/input/bs_aceeditor_input.rb
kono_utils-0.15.16 app/input/bs_aceeditor_input.rb
kono_utils-0.15.15 app/input/bs_aceeditor_input.rb
kono_utils-0.15.14 app/input/bs_aceeditor_input.rb
kono_utils-0.15.13 app/input/bs_aceeditor_input.rb
kono_utils-0.15.12 app/input/bs_aceeditor_input.rb
kono_utils-0.15.11 app/input/bs_aceeditor_input.rb
kono_utils-0.15.10 app/input/bs_aceeditor_input.rb
kono_utils-0.15.9 app/input/bs_aceeditor_input.rb
kono_utils-0.15.8 app/input/bs_aceeditor_input.rb
kono_utils-0.15.7 app/input/bs_aceeditor_input.rb
kono_utils-0.15.6 app/input/bs_aceeditor_input.rb
kono_utils-0.15.5 app/input/bs_aceeditor_input.rb