mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-04-30 11:57:07 -04:00
Make growstuff HAML extensions case insensitive
This commit is contained in:
@@ -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})"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user