aboutsummaryrefslogtreecommitdiffstats
path: root/guides/rails_guides/markdown.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-08-31 12:01:06 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:21 -0400
commit544f6bcb9095cfc826f892e6bfafee6a9bafa494 (patch)
tree39fd19a2097cd42bbc693707797b60e08fc5cbf8 /guides/rails_guides/markdown.rb
parentfd9867c7dea8f030bd712a2e407de25c43b6c400 (diff)
downloadrails-544f6bcb9095cfc826f892e6bfafee6a9bafa494.tar.gz
rails-544f6bcb9095cfc826f892e6bfafee6a9bafa494.tar.bz2
rails-544f6bcb9095cfc826f892e6bfafee6a9bafa494.zip
Start rewriting 4.0 release note into Markdown
Diffstat (limited to 'guides/rails_guides/markdown.rb')
-rw-r--r--guides/rails_guides/markdown.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb
new file mode 100644
index 0000000000..a56d0d2d85
--- /dev/null
+++ b/guides/rails_guides/markdown.rb
@@ -0,0 +1,42 @@
+require 'redcarpet'
+require 'nokogiri'
+require 'rails_guides/markdown/renderer'
+
+module RailsGuides
+ class Markdown
+ def initialize(view, layout)
+ @view = view
+ @layout = layout
+ end
+
+ def render(body)
+ @header, _, @body = body.partition(/^\-{40,}$/)
+ render_header
+ render_body
+ end
+
+ private
+ def engine
+ @engine ||= Redcarpet::Markdown.new(Renderer, {
+ no_intra_emphasis: true,
+ fenced_code_blocks: true,
+ autolink: true,
+ strikethrough: true,
+ superscript: true
+ })
+ end
+
+ def render_header
+ header_content = engine.render(@header)
+ @view.content_for(:header_section) { header_content.html_safe }
+
+ @view.content_for(:page_title) do
+ "Ruby on Rails Guides: #{Nokogiri::HTML(header_content).at(:h2).text}".html_safe
+ end
+ end
+
+ def render_body
+ @view.render(:layout => @layout, :text => engine.render(@body))
+ end
+ end
+end