Permalink
Browse files

Add Textile support. Requires RedCloth gem.

  • Loading branch information...
tuupola authored and gma committed Feb 25, 2010
1 parent d581277 commit d86ab150adc0c003a8f8d2d73615e22daa860f17
Showing with 30 additions and 4 deletions.
  1. +9 −1 lib/models.rb
  2. +1 −1 spec/app_spec.rb
  3. +7 −2 spec/model_factory.rb
  4. +13 −0 spec/models_spec.rb
View
@@ -2,9 +2,10 @@
require "rubygems"
require "maruku"
+require "redcloth"
class FileModel
- FORMATS = [:mdown, :haml]
+ FORMATS = [:mdown, :haml, :textile]
@@cache = {}
attr_reader :filename, :mtime
@@ -66,6 +67,8 @@ def to_html
Maruku.new(markup).to_html
when :haml
Haml::Engine.new(markup).to_html
+ when :textile
+ RedCloth.new(markup).to_html
end
end
@@ -147,6 +150,8 @@ def heading
/^#\s*(.*)/
when :haml
/^\s*%h1\s+(.*)/
+ when :textile
+ /^\s*h1\.\s+(.*)/
end
markup =~ regex
Regexp.last_match(1)
@@ -182,6 +187,9 @@ def body
when :haml
body_text = markup.sub(/^\s*%h1\s+.*$\r?\n(\r?\n)?/, "")
Haml::Engine.new(body_text).render
+ when :textile
+ body_text = markup.sub(/^\s*h1\.\s+.*$\r?\n(\r?\n)?/, "")
+ RedCloth.new(body_text).to_html
end
end
View
@@ -292,7 +292,7 @@
end
describe "that is configured to show Disqus comments" do
- setup do
+ before(:each) do
stub_config_key("disqus_short_name", "mysite")
@category = create_category
get @category.abspath
View
@@ -87,14 +87,19 @@ def create_file(path, options = {})
create_content_directories
metadata = options[:metadata] || {}
metatext = metadata.map { |key, value| "#{key}: #{value}" }.join("\n")
- prefix = (options[:ext] == :haml) ? "%div\n %h1" : '# '
+ if options[:ext] == :haml
+ prefix = "%div\n %h1"
+ elsif options[:ext] == :textile
+ prefix = "<div>\nh1."
+ else
+ prefix = '# '
+ end
heading = options[:heading] ? "#{prefix} #{options[:heading]}\n\n" : ""
contents =<<-EOF
#{metatext}
#{heading}#{options[:content]}
EOF
-
FileUtils.mkdir_p(File.dirname(path))
File.open(path, "w") { |file| file.write(contents) }
end
View
@@ -297,3 +297,16 @@ def create_page(options)
it_should_behave_like "Page"
end
+
+describe "Textile page" do
+ before(:each) do
+ @extension = :textile
+ end
+
+ it "should set heading from first h1 tag" do
+ create_article(:path => "headings", :content => 'h1. Second heading')
+ Page.find_by_path("headings").heading.should == "My article"
+ end
+
+ it_should_behave_like "Page"
+end

0 comments on commit d86ab15

Please sign in to comment.