implement the auto_discovery_link_tag liquid filter (feature #206)
This commit is contained in:
parent
a9aeffba9b
commit
b7424b1fd4
@ -3,6 +3,20 @@ module Locomotive
|
||||
module Filters
|
||||
module Html
|
||||
|
||||
# Returns a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.
|
||||
# input: url of the feed
|
||||
# example:
|
||||
# {{ '/foo/bar' | auto_discovery_link_tag: 'rel:alternate', 'type:atom', 'title:A title' }}
|
||||
def auto_discovery_link_tag(input, *args)
|
||||
options = args_to_options(args)
|
||||
|
||||
rel = options[:rel] || 'alternate'
|
||||
type = options[:type] || Mime::Type.lookup_by_extension('rss').to_s
|
||||
title = options[:title] || 'RSS'
|
||||
|
||||
%{<link rel="#{rel}" type="#{type}" title="#{title}" href="#{input}" />}
|
||||
end
|
||||
|
||||
# Write the url to a stylesheet resource
|
||||
# input: name of the css file
|
||||
def stylesheet_url(input)
|
||||
|
@ -8,6 +8,16 @@ describe Locomotive::Liquid::Filters::Html do
|
||||
@context = build_context
|
||||
end
|
||||
|
||||
it 'writes the tag to display a rss/atom feed' do
|
||||
auto_discovery_link_tag('/foo/bar').should == %(
|
||||
<link rel="alternate" type="application/rss+xml" title="RSS" href="/foo/bar" />
|
||||
).strip
|
||||
|
||||
auto_discovery_link_tag('/foo/bar', 'rel:alternate2', 'type:atom', 'title:Hello world').should == %(
|
||||
<link rel="alternate2" type="atom" title="Hello world" href="/foo/bar" />
|
||||
).strip
|
||||
end
|
||||
|
||||
it 'should return a url for a stylesheet file' do
|
||||
result = "/sites/000000000000000000000042/theme/stylesheets/main.css"
|
||||
stylesheet_url('main.css').should == result
|
||||
|
Loading…
Reference in New Issue
Block a user