Module: Loco::Liquid::Filters
- Defined in:
- lib/loco/liquid/filters.rb,
lib/loco/liquid/filters/version.rb
Constant Summary collapse
- VERSION =
"0.0.13"
Instance Method Summary collapse
- #gravatar(email, default) ⇒ Object
- #httpsRestGet(domain, method, user, password) ⇒ Object
- #random(max, min = 1) ⇒ Object
- #replaceURLStringWithHref(string) ⇒ Object
- #teaser(html) ⇒ Object
- #trim(string) ⇒ Object
- #twitter(handle) ⇒ Object
- #url_decode(string) ⇒ Object
- #url_encode(string) ⇒ Object
Instance Method Details
#gravatar(email, default) ⇒ Object
13 14 15 16 17 |
# File 'lib/loco/liquid/filters.rb', line 13 def gravatar(email, default) email = default if email.nil? || email.empty? hash = Digest::MD5.hexdigest(email) "http://www.gravatar.com/avatar/#{hash}" end |
#httpsRestGet(domain, method, user, password) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/loco/liquid/filters.rb', line 47 def httpsRestGet(domain,method, user, password) http = Net::HTTP.new(domain, 443) http.use_ssl = true http.start do |http| req = Net::HTTP::Get.new(method) # we make an HTTP basic auth by passing the # username and password req.basic_auth user, password resp = http.request(req) JSON.parse(resp.body) end end |
#random(max, min = 1) ⇒ Object
43 44 45 |
# File 'lib/loco/liquid/filters.rb', line 43 def random(max, min = 1) rand(min..max) end |
#replaceURLStringWithHref(string) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/loco/liquid/filters.rb', line 62 def replaceURLStringWithHref(string) urls = URI.extract(string) urls = urls.uniq urls.each do[u] string.gsub(u,"<a href="+u+">"+u+"</a>") end return string end |
#teaser(html) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/loco/liquid/filters.rb', line 23 def (html) if html.nil? || html.empty? "" else Sanitize.clean(html)[0..400] + "..." end end |
#trim(string) ⇒ Object
39 40 41 |
# File 'lib/loco/liquid/filters.rb', line 39 def trim(string) string.strip end |
#twitter(handle) ⇒ Object
19 20 21 |
# File 'lib/loco/liquid/filters.rb', line 19 def twitter(handle) "<a href='http://twitter.com/#{handle}' target='_blank'>@#{handle}</a>" end |
#url_decode(string) ⇒ Object
35 36 37 |
# File 'lib/loco/liquid/filters.rb', line 35 def url_decode(string) URI.unescape string end |
#url_encode(string) ⇒ Object
31 32 33 |
# File 'lib/loco/liquid/filters.rb', line 31 def url_encode(string) URI.escape string end |