From 90a46f14446eb03dd9c3e89a427249de9a1236ad Mon Sep 17 00:00:00 2001 From: elijah Date: Wed, 20 Feb 2013 03:17:48 -0800 Subject: remove stupid pandoc for now, use rdiscount and RbST instead. --- lib/static_page.rb | 89 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 28 deletions(-) (limited to 'lib') diff --git a/lib/static_page.rb b/lib/static_page.rb index 91032c7..7ef529b 100644 --- a/lib/static_page.rb +++ b/lib/static_page.rb @@ -9,8 +9,11 @@ require 'property_set' require 'i18n' require 'pathname' require 'RedCloth' -require 'pandoc-ruby' -require 'iconv' +require 'rbst' +require 'rdiscount' + +#require 'pandoc-ruby' +#require 'iconv' class StaticPage attr_accessor :path, :children, :name, :file_path, :props, :parent, :mount_point, :locales @@ -326,10 +329,14 @@ class StaticPage def render_content_file(content_file, locale) content = File.read(content_file).sub(PROPERTY_HEADER, '') suffix = File.extname(content_file) - if PANDOC_FORMATS[suffix] - render_pandoc(content, suffix, locale) - elsif REDCLOTH_FORMATS[suffix] + #if PANDOC_FORMATS[suffix] + # render_pandoc(content, suffix, locale) + if REDCLOTH_FORMATS[suffix] render_redcloth(content, suffix, locale) + elsif RBST_FORMATS[suffix] + render_rbst(content, suffix, locale) + elsif RDISCOUNT_FORMATS[suffix] + render_rdiscount(content, suffix, locale) else "sorry, i don't understand how to render #{suffix}" end @@ -339,45 +346,71 @@ class StaticPage @suffix == '.haml' || File.exists?(self.absolute_template_path(locale) + '.haml') end - PANDOC_FORMATS = { - '.md' => :markdown, - '.markdown' => :markdown, - #'.txt' => :textile, - #'.textile' => :textile, - '.rst' => :rst, - '.latex' => :latex, - '.pandoc' => :pandoc, + #PANDOC_FORMATS = { + # '.md' => :markdown, + # '.markdown' => :markdown, + # #'.txt' => :textile, + # #'.textile' => :textile, + # '.rst' => :rst, + # '.latex' => :latex, + # '.pandoc' => :pandoc, + #} + + #def render_pandoc(string, suffix, locale) + # string = Iconv.conv("UTF-8//IGNORE", "UTF-8", string) # remove illegal utf-8 + # args = [string, {:from => PANDOC_FORMATS[suffix], :to => :html}, "smart"] + # if props.locale(locale).toc != false + # args << "table_of_contents" + # args << {"template" => "'#{File.dirname(__FILE__) + '/template.html'}'"} + # end + # unless (title = explicit_title(locale)).nil? + # args << {"variable" => "title:'#{title}'"} + # end + # renderer = PandocRuby.new(*args) + # renderer.convert + #end + + RBST_FORMATS = { + '.rst' => :rst } - def render_pandoc(string, suffix, locale) - string = Iconv.conv("UTF-8//IGNORE", "UTF-8", string) # remove illegal utf-8 - args = [string, {:from => PANDOC_FORMATS[suffix], :to => :html}, "smart"] - if props.locale(locale).toc != false - args << "table_of_contents" - args << {"template" => "'#{File.dirname(__FILE__) + '/template.html'}'"} - end + def render_rbst(string, suffix, locale) + html = RbST.new(string).to_html unless (title = explicit_title(locale)).nil? - args << {"variable" => "title:'#{title}'"} + html = "

#{title}

\n\n" + html end - renderer = PandocRuby.new(*args) - renderer.convert + return html end - # - # pandoc can do textile, but it does it HORRIBLY - # REDCLOTH_FORMATS = { '.txt' => :textile, - '.textile' => :textile, + '.textile' => :textile } def render_redcloth(string, suffix, locale) unless (title = explicit_title(locale)).nil? - string = "h1. #{title}\n\n" + string + string = "h1(first). #{title}\n\n" + string end RedCloth.new(string).to_html end + RDISCOUNT_FORMATS = { + '.md' => :markdown, + '.markdown' => :markdown + } + + def render_rdiscount(string, suffix, locale) + rd = RDiscount.new(string, :smart, :generate_toc, :autolink) + html = rd.to_html + if props.locale(locale).toc != false && rd.toc_content + html = "
%s
\n\n%s" % [rd.toc_content, html] + end + unless (title = explicit_title(locale)).nil? + html = "

#{title}

\n\n" + html + end + return html + end + # # returns title iff explicitly set. # -- cgit v1.2.3