Technology in Vino: RedCloth
When I started writing Vino I knew I wanted to make it open source. Important among several reasons is I have gained a lot of knowledge from open source projects and want to contribute to the community in the same respect. In addition this project is a learning endeavor for me; so why should I keep it to myself?
One of the technologies I’m using in Vino is RedCloth.
RedCloth is a gem built for Ruby that parses Textile into HTML. This is super helpful for blogging because it allows me to write posts in plain text, store them in my database in plain text, but in the Rails view layer show rendered HTML to the browser.
bq. A block quote becomes
A block quote
"Link to Wikipedia":http://www.wikipedia.org becomes
In app/views/posts/show.html.erb Vino takes the Post.content (a string of Textile) and parses the string to HTML.
<% if @post.content %> <%= sanitize RedCloth.new(@post.content).to_html %> <% end %>
RedCloth returns an HTML string and is sanitized so the browser will render it as if the HTML was included in the view itself. (Because Vino can publish a post that does not have any content, I am checking that content exists before passing @post.content to RedCloth. Otherwise RedCloth will raise a TypeError exception.)
That’s it for my simple implementation of RedCloth parsing in Vino! Stay tuned for more posts in this series.
This is the first post in a series of Technology in Vino. Check out the Vino source code on Github: whargrove/Vino.∞ | Posted by Wes at 2014-03-10 6:04:05 PM