Permalink
Browse files
Add Textile support. Requires RedCloth gem.
- Loading branch information...
Showing
with
30 additions
and
4 deletions.
-
+9
−1
lib/models.rb
-
+1
−1
spec/app_spec.rb
-
+7
−2
spec/model_factory.rb
-
+13
−0
spec/models_spec.rb
|
@@ -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
|
|
|
|
|
|
|
@@ -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
|
|
|
|
@@ -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
|
|
|
|
@@ -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