Make growstuff HAML extensions case insensitive

This commit is contained in:
Skud
2013-11-11 11:18:14 +11:00
parent 11e7055497
commit 9da92c8f71
2 changed files with 14 additions and 3 deletions

View File

@@ -9,7 +9,8 @@ module Haml::Filters
# turn [tomato](crop) into [tomato](http://growstuff.org/crops/tomato)
expanded = text.gsub(/\[(.*?)\]\(crop\)/) do |m|
crop_str = $1
crop = Crop.find_by_name(crop_str)
# find crop case-insensitively
crop = Crop.where('lower(name) = ?', crop_str.downcase).first
if crop
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
"[#{crop_str}](#{url})"

View File

@@ -6,9 +6,13 @@ def input_link(name)
return "[#{name}](crop)"
end
def output_link(crop)
def output_link(crop, name=nil)
url = Rails.application.routes.url_helpers.crop_url(crop, :host => Growstuff::Application.config.host)
return "<a href=\"#{url}\">#{crop.name}</a>"
if name
return "<a href=\"#{url}\">#{name}</a>"
else
return "<a href=\"#{url}\">#{crop.name}</a>"
end
end
describe 'Haml::Filters::Growstuff_Markdown' do
@@ -42,4 +46,10 @@ describe 'Haml::Filters::Growstuff_Markdown' do
rendered.should match /<strong>foo<\/strong>/
end
it "finds crops case insensitively" do
@crop = FactoryGirl.create(:crop, :name => 'tomato')
rendered = Haml::Filters::GrowstuffMarkdown.render(input_link('ToMaTo'))
rendered.should match /#{output_link(@crop, 'ToMaTo')}/
end
end