public
Created

  • Download Gist
rss_tag.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
class RenderRSS < Liquid::Block
 
def initialize(tag_name, markup, tokens)
super
@markup = markup
@attributes = {}
markup.scan(Liquid::TagAttributes) do |key, value|
@attributes[key] = value
end
 
RestClient.get(@attributes['source']).force_encoding('UTF-8')
@parsed_rss = SimpleRSS.parse(rss_data)
end
 
def render(context)
rss_reg = {
"title" => @parsed_rss.title,
"items" => @parsed_rss.items.map{|u| u.stringify_keys}
}
context.stack do
context['feed'] = rss_reg
render_all(@nodelist, context)
end
end
end
 
Liquid::Template.register_tag('rss', RenderRSS)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.