Skip to content

Commit

Permalink
Recipe wiki links in menu items.
Browse files Browse the repository at this point in the history
  • Loading branch information
eee-c committed May 24, 2009
1 parent a7ac8a2 commit 7829342
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
5 changes: 3 additions & 2 deletions helpers.rb
Expand Up @@ -25,6 +25,7 @@ def wiki(original)
text.gsub!(/\b(\d+)F/, "\\1° F")
text.gsub!(/\[kid:(\w+)\]/m) { |kid| kid_nicknames[$1] }
text.gsub!(/\[recipe:(\S+)\]/m) { |r| recipe_link($1) }
text.gsub!(/\[recipe:(\S+)\s(.+?)\]/m) { |r| recipe_link($1, $2) }
RedCloth.new(text).to_html
end

Expand All @@ -36,9 +37,9 @@ def _db
@@db
end

def recipe_link(permalink)
def recipe_link(permalink, title=nil)
recipe = JSON.parse(RestClient.get("#{_db}/#{permalink}"))
%Q|<a href="/recipes/#{recipe['_id']}">#{recipe['title']}</a>|
%Q|<a href="/recipes/#{recipe['_id']}">#{title || recipe['title']}</a>|
end

def image_link(doc, options={ })
Expand Down
10 changes: 10 additions & 0 deletions spec/eee_helpers_spec.rb
Expand Up @@ -45,6 +45,16 @@
:href => "/recipes/id-123",
:content => "Title")
end

it "should wikify recipe URIs, using supplied text for the link" do
RestClient.stub!(:get).
and_return('{"_id":"id-123","title":"Title"}')

wiki("[recipe:id-123 Different Title]").
should have_selector("a",
:href => "/recipes/id-123",
:content => "Different Title")
end
end
end

Expand Down
16 changes: 15 additions & 1 deletion spec/views/meal_by_month.haml_spec.rb
Expand Up @@ -57,5 +57,19 @@
:content => "foo, bar, baz")
end

it "should include recipe titles in the menu items"
it "should include recipe titles in the menu items" do
assigns[:meals]['rows'][0]['value'][0]["menu"] =
[" Salad with [recipe:2009/05/23/lemon_dressing] "]

self.stub!(:_db).and_return("")

RestClient.
stub!(:get).
and_return('{"title":"Lemon Dressing"}')

render("/views/meal_by_month.haml")
response.should have_selector(".menu",
:content => "Salad with Lemon Dressing")
end

end
3 changes: 1 addition & 2 deletions views/meal_by_month.haml
Expand Up @@ -7,5 +7,4 @@
%span.date= meal['value'][0]['date']
%span.title= meal['value'][0]['title']
%p= meal['value'][0]['summary']
.menu= meal['value'][0]['menu'].join(', ')

.menu= wiki(meal['value'][0]['menu'].join(', '))

0 comments on commit 7829342

Please sign in to comment.