Giter Club home page Giter Club logo

pagedown-bootstrap-rails's Introduction

PageDown Bootstrap Rails

A Ruby gem version of https://github.com/tchapi/pagedown-bootstrap for the Rails asset pipeline.

Installation

Add to your Gemfile:

gem 'pagedown-bootstrap-rails'

In Rails 3.1 or Rails 3.2 this goes in the :asset group, but in Rails 4 it goes with the top level gems.

Usage

Require the CSS with Sprockets:

/*= require pagedown_bootstrap */

Or with a SASS import:

@import "pagedown_bootstrap";

Sprockets require the JS too:

//= require pagedown_bootstrap

Or individually as you please:

//= require markdown.converter
//= require markdown.editor
//= require markdown.sanitizer
//= require markdown.extra

You will need to instantiate PageDown. I recommend a lib/assets/javascripts/pagedown_init.js.coffee that contains:

$ ->
  $('textarea.wmd-input').each (i, input) ->
    attr = $(input).attr('id').split('wmd-input')[1]
    converter = new Markdown.Converter()
    Markdown.Extra.init(converter)
    editor = new Markdown.Editor(converter, attr)
    editor.run()

Require it with Sprockets:

//= require pagedown_bootstrap
//= require pagedown_init

Then combine it with a new SimpleForm input:

class PagedownInput < SimpleForm::Inputs::TextInput
  def input
    out = "<div id=\"wmd-button-bar-#{attribute_name}\"></div>\n"
    out << "#{@builder.text_area(attribute_name, input_html_options.merge(
      { :class => 'wmd-input', :id => "wmd-input-#{attribute_name}"})) }"
    if input_html_options[:preview]
      out << "<div id=\"wmd-preview-#{attribute_name}\" class=\"wmd-preview\"></div>"
    end
    out.html_safe
  end
end

Which you use in your form like so:

= f.input :description, :as => :pagedown, :input_html => { :preview => true }

This is how it looks:

Glorious

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.