bengreenberg / markdown_on_rails Goto Github PK
View Code? Open in Web Editor NEWMarkdown templating for Ruby On Rails
License: MIT License
Markdown templating for Ruby On Rails
License: MIT License
markdown_on_rails ========== A Ruby on Rails template handler for the (markdown)[http://daringfireball.net/projects/markdown/] format. Download / Install ================== GitHub: http://github.com/markdown_on_rails script/plugin install git://github.com/bengreenberg/markdown_on_rails.git The BlueCloth gem is required: sudo gem install BlueCloth Usage ===== It is very straight forward to use: in your config/environment.rb file: require 'markdown_on_rails' ActionView::Base.register_template_handler('mdtext', MarkdownOnRails) Optionally, add this: MarkdownOnRails::map_headings_down_by 2 The MarkdownOnRails::map_headings_down_by n tells the handler to map headings by n. For example, if you set MarkdownOnRails::map_headings_down_by 2 and write a document like: # First Heading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ## Second Heading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. The resulting html will feature <h3> and <h4> for the two headings respectively. If you have MarkdownOnRails::map_headings_down_by 0 (this is the default), no mapping of headings takes place and you would get <h1> and <h2>. This feature is there so you can always write your documents starting with a first level heading and then if you include the document in two different places that happen to require headings for content to start at something other than a first level heading, you can do so without having to change your content. The only other thing left to do is to create your views as .text files and use markdown syntax. ERB is available inside the .text files if you are using it as a rails view (as for normal '.rhtml' views). eg: # Thank you Thanks <%= @username %> for... Gracefully Degrading Email ========================== You can use Markdown to create HTML emails that will gracefully degrade for plain text viewing without maintaining separate versions of the email in HTML and text. Simply create your email view and Markdown and save it with the .mdtext extension. In your ActiveMailer model, call the `render_degrading_markdown` method with the name of the view like so: def welcome_message(user) recipients user.email subject "Welcome to my awesome site!" from "[email protected]" render_degrading_markdown('welcome_message', :user => user) end The email will be sent in multipart format, with a rendered HTML part and a plain text part. Credit I gladly give credit to John Gruber of daringfireball.net for creating markdown - it has made my professional life much more fun. I also give credit to Michael Granger for porting John Gruber's code to Ruby in the form of Bluecloth. My code obviously depends heavily (critically) on Bluecloth. Using Bluecloth means the amount of code I had to write is embarrassingly little, and for that embarrassment I give credit to the Ruby language. Copyright (c) 2006 Keith Rowell (http://www.rubygreenblue.com) Copyright (c) 2008 Ben Greenberg (ben at ben[dontspamme]greenberg dot net) Released under the MIT license.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.