wordnik_ruby_helpers 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- wordnik_ruby_helpers (0.1.6)
4
+ wordnik_ruby_helpers (0.1.7)
5
5
  RedCloth (>= 4.2.3)
6
6
  rails
7
7
 
@@ -1,3 +1,3 @@
1
1
  module WordnikRubyHelpers
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -256,7 +256,7 @@ class String
256
256
  # Extracts domain name from a URL
257
257
  def domain
258
258
  url = self.dup
259
- url=~(/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : url
259
+ url =~ (/^(?:\w+:\/\/)?([^\/?]+)(?:\/|\?|$)/) ? $1 : url
260
260
  end
261
261
 
262
262
  # Extracts domain name (sans 'www.') from a URL string
@@ -271,6 +271,13 @@ class String
271
271
  rescue
272
272
  false
273
273
  end
274
+
275
+ # Given a URL string, return a URL to a google-hosted PNG favicon for the URL's domain
276
+ def favicon_url_for_domain(options={})
277
+ base_url = "http://www.google.com/s2/favicons?domain="
278
+ options[:fallback] ||= base_url
279
+ self.valid_url? ? [base_url, self.domain].join : options[:fallback]
280
+ end
274
281
 
275
282
  # Returns true or false depending on whether a string appears to be an email address
276
283
  def valid_email?
@@ -2,6 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  describe WordnikRubyHelpers do
4
4
 
5
+
6
+ context "favicon_url_for_domain" do
7
+
8
+
9
+ it "should return a URL for a google favicon, given the string's domain" do
10
+ url = "http://nytimes.com/we-love-wordnik"
11
+ url.favicon_url_for_domain.should == 'http://www.google.com/s2/favicons?domain=nytimes.com'
12
+ end
13
+
14
+ it "should use the provided fallback if string is not a valid URL" do
15
+ url = "we love wordnik yes we do"
16
+ url.favicon_url_for_domain(:fallback => "my_favicon.png").should == 'my_favicon.png'
17
+ end
18
+
19
+ it "should render google's default icon if supplied string is not a valid URL and no fallback was provided" do
20
+ url = "this is not -- a U! R! L!"
21
+ url.favicon_url_for_domain.should == 'http://www.google.com/s2/favicons?domain='
22
+ end
23
+
24
+ end
25
+
5
26
  context "permalinkify" do
6
27
 
7
28
  it "doesn't alter the original object" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wordnik_ruby_helpers
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.7
5
+ version: 0.1.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zeke Sikelianos
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-08-08 00:00:00 -07:00
14
+ date: 2011-08-12 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency