Skip to content

Commit

Permalink
Merge pull request #9 from github/required-contexts
Browse files Browse the repository at this point in the history
Ensure required context values are present
  • Loading branch information
atmos committed Oct 3, 2012
2 parents b11d22b + c9ebc62 commit fe7557b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/html/pipeline/emoji_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def emoji_image_filter(text)

text.gsub EmojiPattern do |match|
name = $1
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{File.join(context[:asset_root], "emoji", "#{name}.png")}' height='20' width='20' align='absmiddle' />"
"<img class='emoji' title=':#{name}:' alt=':#{name}:' src='#{File.join(asset_root, "emoji", "#{name}.png")}' height='20' width='20' align='absmiddle' />"
end
end

# The base url to link emoji sprites
#
# Raises ArgumentError if context option has not been provided.
# Returns the context's asset_root.
def asset_root
context[:asset_root] or raise ArgumentError, "Missing context :asset_root"
end
end
end
2 changes: 1 addition & 1 deletion lib/html/pipeline/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module HTML
module Pipeline
VERSION = "0.0.2"
VERSION = "0.0.3"
end
end
7 changes: 7 additions & 0 deletions test/html/pipeline/emoji_filter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,11 @@ def test_emojify
doc = filter.call
assert_match "https://foo.com/emoji/shipit.png", doc.search('img').attr('src').value
end

def test_missing_context
filter = HTML::Pipeline::EmojiFilter.new("<p>:shipit:</p>", {})
assert_raises ArgumentError do
filter.call
end
end
end

0 comments on commit fe7557b

Please sign in to comment.