Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure required context values are present #9

Merged
merged 2 commits into from
Oct 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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