Skip to content
Browse files

support page bodies in markdown

  • Loading branch information...
1 parent 2b99efe commit a8292e86930246f7ad2a78b9c5dd3b1431313710 @xla xla committed Feb 26, 2011
Showing with 27 additions and 7 deletions.
  1. +1 −0 Gemfile
  2. +4 −1 lib/page_template.html.haml
  3. +8 −3 lib/soywiki.rb
  4. +13 −3 lib/soywiki/html.rb
  5. +1 −0 soywiki.gemspec
View
1 Gemfile
@@ -1,2 +1,3 @@
source :rubygems
gem "haml"
+gem "rdiscount"
View
5 lib/page_template.html.haml
@@ -24,4 +24,7 @@
%a{:href => "#{page}.html"}= page
.main
%h2= title
- %pre= body
+ - if markdown
+ != body.to_html
+ - else
+ %pre= body
View
11 lib/soywiki.rb
@@ -22,7 +22,12 @@ def self.run
END
exit
elsif ARGV.first == '--html'
- self.html_export
+ if ARGV[1] == '--markdown'
+ puts "got true"
+ self.html_export(true)
+ else
+ self.html_export
+ end
exit
elsif ARGV.first == '--install-plugin'
require 'erb'
@@ -39,9 +44,9 @@ def self.run
end
end
- def self.html_export
+ def self.html_export(markdown=false)
require 'soywiki/html'
- Html.export
+ Html.export(markdown)
end
end
View
16 lib/soywiki/html.rb
@@ -1,4 +1,5 @@
require 'haml'
+require 'rdiscount'
module Soywiki
module Html
@@ -29,11 +30,18 @@ def self.process(t)
def self.generate_page(text, namespace, pages, namespaces)
title = text.split("\n")[0]
- body = process(text.split("\n")[1..-1].join("\n").strip)
+ body = if @markdown
+ RDiscount.new(text.split("\n")[1..-1].join("\n").strip)
+ else
+ process(text.split("\n")[1..-1].join("\n").strip)
+ end
+
Haml::Engine.new(PAGE_TEMPLATE).render(nil, :body => body,
:title => title,
:namespace => namespace,
- :namespaces => namespaces, :pages => pages)
+ :namespaces => namespaces,
+ :pages => pages,
+ :markdown => @markdown)
end
@@ -82,7 +90,9 @@ def self.make_root_index_page(namespaces)
# puts "=> Writing #{outfile}"
end
- def self.export
+ def self.export(markdown)
+ @markdown = markdown
+
`rm -rf #{HTML_DIR}/*`
namespaces = Dir["*"].select {|f|
File.directory?(f) && f != HTML_DIR
View
1 soywiki.gemspec
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.add_dependency 'haml'
+ s.add_dependency 'rdiscount'
end

0 comments on commit a8292e8

Please sign in to comment.
Something went wrong with that request. Please try again.