summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-02-20 03:17:48 -0800
committerelijah <elijah@riseup.net>2013-02-20 03:17:48 -0800
commit90a46f14446eb03dd9c3e89a427249de9a1236ad (patch)
treee31033e06da897c7177184769f910145b1403f09 /lib
parentdb22c6c5dabac89b66aab8dd0710636d9be75a67 (diff)
remove stupid pandoc for now, use rdiscount and RbST instead.
Diffstat (limited to 'lib')
-rw-r--r--lib/static_page.rb89
1 files changed, 61 insertions, 28 deletions
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 = "<h1 class=\"first\">#{title}</h1>\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 = "<div id=\"TOC\">%s</div>\n\n%s" % [rd.toc_content, html]
+ end
+ unless (title = explicit_title(locale)).nil?
+ html = "<h1 class=\"first\">#{title}</h1>\n\n" + html
+ end
+ return html
+ end
+
#
# returns title iff explicitly set.
#