Sha256: ceabb18d59fd659c3992ef23bf1918546a1e2bf675cb17776b69a36e92453ee8
Contents?: true
Size: 1.82 KB
Versions: 1
Compression:
Stored size: 1.82 KB
Contents
require "quill/rails5/version" require 'json' module Quill module Rails5 module ViewHelpers def quill(options = {}, html_options = {}, &block) default_options = { modules: { 'toolbar': [ [{ 'font': [] }, { 'size': [] }], [ 'bold', 'italic', 'underline', 'strike' ], [{ 'color': [] }, { 'background': [] }], [{ 'script': 'super' }, { 'script': 'sub' }], [{ 'header': '1' }, { 'header': '2' }, 'blockquote', 'code-block' ], [{ 'list': 'ordered' }, { 'list': 'bullet'}, { 'indent': '-1' }, { 'indent': '+1' }], [ 'direction', { 'align': [] }], [ 'link', 'image', 'video', 'formula' ], [ 'clean' ] ], }, theme: 'snow' } actual_options = default_options.merge(options) default_html_options = { id: 'editor', } actual_html_options = default_html_options.merge(html_options) stylesheet_link_tag("//cdn.quilljs.com/#{VERSION}/quill.#{actual_options[:theme]}.css") + content_tag(:div, capture(&block), actual_html_options, escape: false) + javascript_include_tag("//cdn.quilljs.com/#{VERSION}/quill.min.js") + javascript_tag(" var quill = new Quill('##{actual_html_options[:id]}', #{actual_options.to_json} );") end def quill_field(form, name, editor_id = 'editor') field_id = [form.object_name, name].join('_') form.hidden_field(name) + javascript_tag(" $(document).on('turbolinks:load', function() { $('form##{form.options[:html][:id]}').submit(function() { $('##{field_id}').val($('##{editor_id} .ql-editor').html()); }); });") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
quill-rails5-1.1.3 | lib/quill/rails5/view_helpers.rb |