Module: Jekyll::FlattrFilters
- Defined in:
- lib/jekyll/flattr_filters.rb
Instance Method Summary collapse
-
#flattr_atom(site, page = nil) ⇒ Object
Returns a ATOM payment link.
-
#flattr_button(site, page = nil) ⇒ Object
Returns a flattr button.
- #flattr_feed_options(site, page) ⇒ Object
-
#flattr_loader_options(site) ⇒ Object
Generates the query string part for the flattr load.js from the configurations in _config.yml.
- #flattr_options(site, page, keys) ⇒ Object
-
#flattr_rss(site, page = nil) ⇒ Object
Returns a RSS payment link.
-
#flattrize(hsh) ⇒ Object
Removes all leading “flattr_” from the keys of the given hash.
Instance Method Details
#flattr_atom(site, page = nil) ⇒ Object
Returns a ATOM payment link.
{{ site | flattr_atom:post }}
46 47 48 49 50 |
# File 'lib/jekyll/flattr_filters.rb', line 46 def flattr_atom(site, page = nil) return if site['flattr_uid'].nil? link = '<link rel="payment" href="https://flattr.com/submit/auto?' link << %Q{#{(site, page)}" type="text/html" />} end |
#flattr_button(site, page = nil) ⇒ Object
Returns a flattr button
{{ site | flattr_button:page }}
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll/flattr_filters.rb', line 20 def (site, page = nil) return if site['flattr_uid'].nil? keys = %w[url title description uid popout button category language tags] = (site, page, keys) = '<a class="FlattrButton" style="display:none;" ' << %Q{title="#{.delete('title')}" href="#{.delete('url')}" } << .map { |k, v| %Q{data-flattr-#{k}="#{v}"} unless k == 'description' }.join(' ') << ">\n\n#{['description'].gsub(/<\/?[^>]*>/, "")}\n</a>" end |
#flattr_feed_options(site, page) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/jekyll/flattr_filters.rb', line 97 def (site, page) keys = %w[url uid] = (site, page, keys).map { |k, v| "#{k == 'uid' ? 'user_id' : k}=#{ERB::Util.url_encode(v)}" }.join('&') end |
#flattr_loader_options(site) ⇒ Object
Generates the query string part for the flattr load.js from the configurations in _config.yml
{{ site | flattr_loader_options }}
9 10 11 12 13 14 15 |
# File 'lib/jekyll/flattr_filters.rb', line 9 def (site) return if site['flattr_uid'].nil? keys = %w[mode https popout uid button language category] = (site, nil, keys).delete_if { |_, v| v.to_s.empty? } .map { |k, v| "#{k}=#{ERB::Util.url_encode(v)}" }.join('&') end |
#flattr_options(site, page, keys) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/jekyll/flattr_filters.rb', line 69 def (site, page, keys) page = {} if page.nil? site = flattrize(site) page = flattrize(page) = {} keys.each { |k| case k when 'https' [k] = 1 when 'url' [k] = "#{site['url']}#{page['url']}" when 'description' [k] = page['content'] || site['description'] || site['title'] when 'category' [k] = page['category'] || site['category'] || 'audio' when 'language' [k] = page['language'] || site['language'] || 'en_GB' when 'tags' [k] = page['tags'].join(', ') if page['tags'] else [k] = page[k] || site[k] end } end |
#flattr_rss(site, page = nil) ⇒ Object
Returns a RSS payment link.
{{ site | flattr_rss:post }}
37 38 39 40 41 |
# File 'lib/jekyll/flattr_filters.rb', line 37 def flattr_rss(site, page = nil) return if site['flattr_uid'].nil? link = '<atom:link rel="payment" href="https://flattr.com/submit/auto?' link << %Q{#{(site, page)}" type="text/html" />} end |
#flattrize(hsh) ⇒ Object
Removes all leading “flattr_” from the keys of the given hash.
flattrize({ 'octopod' => 'awesome', 'flattr_uid' => 'pattex' })
=> { "octopod" => "awesome", "uid" => "pattex" }
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/jekyll/flattr_filters.rb', line 56 def flattrize(hsh) config = {} hsh.to_hash.each { |k, v| if new_key = k.to_s.match(/\Aflattr_(.*)\z/) config[new_key[1]] = v else config[k] = v end } config end |