forked from locomotivecms/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
did
committed
Feb 13, 2011
1 parent
3e5e5d5
commit 083debc
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Locomotive | ||
module Liquid | ||
module Tags | ||
class SEOMetadata < ::Liquid::Tag | ||
|
||
def render(context) | ||
%{ | ||
<meta name="description" content="#{sanitized_string(context.registers[:site].meta_description)}" /> | ||
<meta name="keywords" content="#{sanitized_string(context.registers[:site].meta_keywords)}" /> | ||
} | ||
end | ||
|
||
# Removees whitespace and quote charactets from the input | ||
def sanitized_string(string) | ||
string.strip.gsub(/"/, '') | ||
end | ||
|
||
end | ||
|
||
::Liquid::Template.register_tag('seo_metadata', SEOMetadata) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require 'spec_helper' | ||
|
||
describe Locomotive::Liquid::Tags::SEOMetadata do | ||
|
||
before :each do | ||
@site = Factory.build(:site, :meta_description => 'A short site description', :meta_keywords => 'test only cat dog') | ||
end | ||
|
||
context '#rendering' do | ||
|
||
it 'renders a a meta description tag' do | ||
render_seo_metadata.should include '<meta name="description" content="A short site description" />' | ||
end | ||
|
||
it 'strips and removes quote characters from the description' do | ||
@site.meta_description = ' String with " " quotes ' | ||
render_seo_metadata.should include '<meta name="description" content="String with quotes" />' | ||
end | ||
|
||
it 'renders a meta keywords tag' do | ||
render_seo_metadata.should include '<meta name="keywords" content="test only cat dog" />' | ||
end | ||
|
||
it 'strips and removes quote characters from the keywords' do | ||
@site.meta_keywords = ' one " two " three ' | ||
render_seo_metadata.should include '<meta name="keywords" content="one two three" />' | ||
end | ||
|
||
end | ||
|
||
def render_seo_metadata | ||
registers = { :site => @site } | ||
liquid_context = ::Liquid::Context.new({}, {}, registers) | ||
output = Liquid::Template.parse("{% seo_metadata %}").render(liquid_context) | ||
end | ||
|
||
end |