Giter Club home page Giter Club logo

markdownizer's Introduction

#Markdownizer

A simple gem for Rails 3 to render some ActiveRecord text field as Markdown!

It mixes CodeRay and RDiscount to give you awesome code highlighting :)

You can check the generated Rocco documentation on the project page.

##Install

In your Gemfile:

gem 'markdownizer'

If you want code highlighting, you should run this generator too:

rails generate markdownizer:install

This will place a markdownizer.css file in your public/stylesheets folder. You will have to require it manually in your layouts, or through jammit, or whatever.

Usage

In your model, let's say, Post:

class Post < ActiveRecord::Base
  markdownize! :body
  # In this case we want to treat :body as markdown.
  # You can pass an options hash to the code renderer, such as:
  #
  #   markdownize! :body, :line_numbers => :table
  #
end

Markdownizer needs an additional field (:rendered_body), which you should generate in a migration. (If the attribute was :some_other_field, it would need :rendered_some_other_field!) All these fields should have the type :text.

You save your posts with markdown text like this:

Post.create body: """
  # My H1 title
  Markdown is awesome!
  ## Some H2 title...

  {% code ruby %}
  {% caption 'This caption will become an h5 and also a property of the enclosing div' %}
  {% highlight [1,2,3] %}  <- this will highlight lines 1, 2 and 3 (it accepts a Range as well)

    # All this code will be highlighted properly! :)
    def my_method(*my_args)
      something do
        . . .
      end
    end

  {% endcode %}
"""

And then, in your view you just have to call @post.rendered_body :)

##Contribute!

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add specs for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull.
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2011-2013 Codegram. See LICENSE for details.

markdownizer's People

Contributors

technomage avatar saurabhbhatia avatar

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.