mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
Make growstuff markdown actually work
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
= post.created_at
|
||||
|
||||
.post-body
|
||||
:markdown
|
||||
:growstuff_markdown
|
||||
#{ strip_tags post.body }
|
||||
|
||||
- unless defined?(hide_comments)
|
||||
|
||||
@@ -5,11 +5,9 @@ module Haml::Filters
|
||||
include Haml::Filters::Base
|
||||
|
||||
def render(text)
|
||||
bc = BlueCloth.new(text)
|
||||
orig = bc.text
|
||||
|
||||
# turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato)
|
||||
return orig.gsub(/\[(.*?)\]\(crop\)/) do |m|
|
||||
expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m|
|
||||
crop_str = $1
|
||||
crop = Crop.find_by_name(crop_str)
|
||||
if crop
|
||||
@@ -19,6 +17,9 @@ module Haml::Filters
|
||||
crop_str
|
||||
end
|
||||
end
|
||||
|
||||
return BlueCloth.new(expanded).to_html
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ def input_link(name)
|
||||
end
|
||||
|
||||
def output_link(crop)
|
||||
return "[#{crop.name}](#{Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)})"
|
||||
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
|
||||
return "<a href=\"#{url}\">#{crop.name}</a>"
|
||||
end
|
||||
|
||||
describe 'Haml::Filters::Growstuff_Markdown' do
|
||||
@@ -19,12 +20,12 @@ describe 'Haml::Filters::Growstuff_Markdown' do
|
||||
it 'converts quick crop links' do
|
||||
@crop = FactoryGirl.create(:crop)
|
||||
rendered = Haml::Filters::GrowstuffMarkdown.render(input_link(@crop.name))
|
||||
rendered.should eq output_link(@crop)
|
||||
rendered.should match /#{output_link(@crop)}/
|
||||
end
|
||||
|
||||
it "doesn't convert nonexistent crops" do
|
||||
rendered = Haml::Filters::GrowstuffMarkdown.render(input_link("not a crop"))
|
||||
rendered.should eq "not a crop"
|
||||
rendered.should match /not a crop/
|
||||
end
|
||||
|
||||
it "handles multiple crop links" do
|
||||
@@ -32,7 +33,13 @@ describe 'Haml::Filters::Growstuff_Markdown' do
|
||||
maize = FactoryGirl.create(:maize)
|
||||
string = "#{input_link(tomato)} #{input_link(maize)}"
|
||||
rendered = Haml::Filters::GrowstuffMarkdown.render(string)
|
||||
rendered.should eq "#{output_link(tomato)} #{output_link(maize)}"
|
||||
rendered.should match /#{output_link(tomato)} #{output_link(maize)}/
|
||||
end
|
||||
|
||||
it "converts normal markdown" do
|
||||
string = "**foo**"
|
||||
rendered = Haml::Filters::GrowstuffMarkdown.render(string)
|
||||
rendered.should match /<strong>foo<\/strong>/
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user