Sha256: eff1be1950df40ff24079edf4b7f026559b5874b90f6cd22fba8e7a6b5a61640
Contents?: true
Size: 880 Bytes
Versions: 2
Compression:
Stored size: 880 Bytes
Contents
require 'uri' require 'net/http' require 'rexml/document' AutoHtml.add_filter(:flickr).with(:maxwidth => nil, :maxheight => nil, :link_options => {}) do |text, options| regex = %r{http://(www\.)?flickr\.com/photos/[^\s<]*} text.gsub(regex) do |match| params = { :url => match, :format => "json" } [:maxwidth, :maxheight].each { |p| params[p] = options[p] unless options[p].nil? or not options[p] > 0 } uri = URI("http://www.flickr.com/services/oembed") uri.query = URI.encode_www_form(params) response = JSON.parse(Net::HTTP.get(uri)) link_options = Array(options[:link_options]).reject { |k,v| v.nil? }.map { |k, v| %{#{k}="#{REXML::Text::normalize(v)}"} }.join(' ') %{<a href="#{match}"#{ ' ' + link_options unless link_options.empty? }><img src="#{response["url"]}" alt="#{response["title"]}" title="#{response["title"]}" /></a>} end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
auto_html-1.6.1 | lib/auto_html/filters/flickr.rb |
auto_html-1.6.0 | lib/auto_html/filters/flickr.rb |