Giter Site home page Giter Site logo

todaytix / summernote-rails Goto Github PK

View Code? Open in Web Editor NEW

This project forked from summernote/summernote-rails

0.0 15.0 0.0 791 KB

To gemify the summernote WYSIWYG editor for Rails >= 3.1

Home Page: http://summernote.org/summernote-rails/

License: MIT License

Ruby 80.06% JavaScript 2.20% CoffeeScript 1.97% CSS 0.75% HTML 15.01%

summernote-rails's Introduction

Summernote::Rails

This gem was built to package the assets used in Summernote, the Super Simple WYSIWYG Editor on Bootstrap, for Ruby on Rails version >= 3.1.

https://github.com/summernote/summernote-rails.

The version of summernote-rails is matched with that of summernote editor.

Gem Version

Installation

Add the following gems to your application's Gemfile:

gem 'summernote-rails', 'current version number'
gem 'bootstrap-sass'     # required

And then execute:

$ bundle install

Usage

In app/assets/stylesheets/application.scss,

@import "bootstrap";
@import "summernote";

In app/assets/javascripts/application.js, you should add as follows:

//= require ...
//= require bootstrap
//= require summernote
//= require ...

Basic Example:

<div id="summernote">Hello Summernote</div>

<script type="text/javascript">
  $(document).ready(function() {
    $('#summernote').summernote();
  });
</script>

Or, if your want to use javascript with unobtrusive pattern, you can move the javascript script code lines to app/assets/javascripts/summernote_bootstraped.coffee as follows:

$ ->
  $('#summernote').summernote()

Ideally, you would do it like this:

# This goes into your main javascript file. Customize as you need.

$('[data-provider="summernote"]').each(function(){
  $(this).summernote({ });
})

Or, if you want to code in coffeescript,

$ ->
  $('[data-provider="summernote"]').each ->
    $(this).summernote()

Then, if you are using simple_form, you can use the :summernote input type. This type simply adds the data-provider="summernote" to the field.

<%= simple_form_for :example do | f | %>
  ...
  <%= f.input :text, as: :summernote %>
  ...
<% end %>

Or, if you prefer haml-style,

= simple_form_for(:example) do | f |
  ...
  = f.input :text, as: :summernote
  ...

If you are not using simple_form, then simply add the data-provider="summernote" to the input field yourself.

i18n Support

If you use i18n, you have to include language files. In app/assets/javascripts/application.js, you should add the following:

// load all locales
//= require summernote/locales

// or

// load specific locale(ko-KR)
//= require summernote/locales/ko-KR

and update summernote option

<div id="summernote">Hello Summernote</div>

<script type="text/javascript">
  $(document).ready(function() {
    $('#summernote').summernote({
      lang: 'ko-KR'
    });
  });
</script>

Also, you can move the above javascript code lines to app/assets/javascripts/summernote_bootstraped.coffee and add as follows:

$ ->
  $('#summernote').summernote
    lang: 'ko-KR'

Plugin

If you want to use a plugin, you have to include the corresponding file. In app/assets/javascripts/application.js, you should add the following:

// load hello plugin
//= require summernote/plugin/hello/summernote-ext-hello

and update summernote option.

<div id="summernote">Hello Summernote</div>

<script type="text/javascript">
  $(document).ready(function() {
    $('#summernote').summernote({
      toolbar : [
        ...
        ['insert', [ 'hello' ]]
        ...
      ]
    });
  });
</script>

Also, you can move the above javascript code lines to app/assets/javascripts/summernote_bootstraped.coffee and add as follows:

  $ ->
    $('#summernote').summernote
      toolbar : [
        ...
        [
          'insert'
            [
              'hello'
            ]
        ]
        ...
      ]

Sample projects

For an example, take a look at the example folder in this repository.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.