firefly 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  script: rake spec
2
2
  rvm:
3
3
  - 1.8.7
4
- - 1.9.2
5
4
  - ree
6
5
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- firefly (1.4.1)
4
+ firefly (1.5.0)
5
5
  dm-aggregates (~> 1.0.2)
6
6
  dm-core (~> 1.0.2)
7
7
  dm-migrations (~> 1.0.2)
@@ -9,7 +9,7 @@ PATH
9
9
  dm-transactions (~> 1.0.2)
10
10
  escape_utils (~> 0.2.3)
11
11
  haml (~> 3.0.18)
12
- sinatra (~> 1.0)
12
+ sinatra (~> 1.2.3)
13
13
 
14
14
  GEM
15
15
  remote: http://rubygems.org/
@@ -65,7 +65,15 @@ PLATFORMS
65
65
 
66
66
  DEPENDENCIES
67
67
  database_cleaner (~> 0.6.6)
68
+ dm-aggregates (~> 1.0.2)
69
+ dm-core (~> 1.0.2)
70
+ dm-migrations (~> 1.0.2)
71
+ dm-mysql-adapter (~> 1.0.2)
68
72
  dm-sqlite-adapter (~> 1.0.2)
73
+ dm-transactions (~> 1.0.2)
74
+ escape_utils (~> 0.2.3)
69
75
  firefly!
76
+ haml (~> 3.0.18)
70
77
  rack-test (~> 0.5.4)
71
78
  rspec (~> 2.5.0)
79
+ sinatra (~> 1.2.3)
data/HISTORY CHANGED
@@ -1,3 +1,8 @@
1
+ = 1.5.1 - 2011-04-22
2
+
3
+ * 2011-04-22 Truncate long URLs in the backend to preserve layout (issue #25) [ariejan]
4
+ * 2011-04-22 Accept URL encoded titles when sharing to Twitter and Hyves (issue #28) [ariejan]
5
+
1
6
  = 1.5.0 - 2011-04-21
2
7
 
3
8
  * 2011-04-21 Firefly is now compatible with ruby 1.8.7, 1.9.2 and ree-1.8 [ariejan]
data/firefly.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_runtime_dependency("sinatra", ["~> 1.0"])
22
+ s.add_runtime_dependency("sinatra", ["~> 1.2.3"])
23
23
  s.add_runtime_dependency("dm-core", ["~> 1.0.2"])
24
24
  s.add_runtime_dependency("dm-migrations", ["~> 1.0.2"])
25
25
  s.add_runtime_dependency("dm-transactions", ["~> 1.0.2"])
@@ -1,9 +1,10 @@
1
+ # encoding: UTF-8
1
2
  module Firefly
2
3
  class Base62
3
-
4
+
4
5
  CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split('')
5
6
  BASE = 62
6
-
7
+
7
8
  def self.encode(value)
8
9
  s = []
9
10
  while value >= BASE
@@ -23,4 +24,4 @@ module Firefly
23
24
  total
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Firefly
2
3
  class CodeFactory
3
4
  include DataMapper::Resource
@@ -1,6 +1,7 @@
1
+ # encoding: UTF-8
1
2
  module Firefly
2
3
  class Config < Hash
3
-
4
+
4
5
  DEFAULTS = {
5
6
  :hostname => "localhost:3000",
6
7
  :api_key => "test",
@@ -10,12 +11,12 @@ module Firefly
10
11
  :hyves_title => "Check this out",
11
12
  :hyves_body => "Check this out: %short_url%"
12
13
  }
13
-
14
+
14
15
  def initialize obj
15
16
  self.update DEFAULTS
16
17
  self.update obj
17
- end
18
-
18
+ end
19
+
19
20
  def set key, val = nil, &blk
20
21
  if val.is_a? Hash
21
22
  self[key].update val
@@ -24,4 +25,4 @@ module Firefly
24
25
  end
25
26
  end
26
27
  end
27
- end
28
+ end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'sinatra/base'
2
3
  require 'haml'
3
4
  require 'digest/md5'
@@ -38,6 +39,18 @@ module Firefly
38
39
  session["firefly_session"] = Digest::MD5.hexdigest(key)
39
40
  end
40
41
 
42
+ # Taken from Rails
43
+ def truncate(text, length, options = {})
44
+ options[:omission] ||= "..."
45
+
46
+ length_with_room_for_omission = length - options[:omission].length
47
+ chars = text
48
+ stop = options[:separator] ?
49
+ (chars.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission) : length_with_room_for_omission
50
+
51
+ (chars.length > length ? chars[0...stop] + options[:omission] : text).to_s
52
+ end
53
+
41
54
  def has_valid_api_cookie?
42
55
  key = session["firefly_session"]
43
56
  key == Digest::MD5.hexdigest(config[:api_key])
@@ -191,11 +204,13 @@ module Firefly
191
204
  @code, @result = generate_short_url(@url, nil)
192
205
  invalid = @code.nil?
193
206
 
207
+ title = URI.unescape(params[:title])
208
+
194
209
  case (params[:target].downcase.to_sym)
195
210
  when :twitter
196
- redirect(URI.escape("http://twitter.com/home?status=#{tweet("http://#{config[:hostname]}/#{@code}", params[:title])}"))
211
+ redirect(URI.escape("http://twitter.com/home?status=#{tweet("http://#{config[:hostname]}/#{@code}", title)}"))
197
212
  when :hyves
198
- redirect(URI.escape("http://www.hyves.nl/profielbeheer/toevoegen/tips/?#{hyves_post("http://#{config[:hostname]}/#{@code}", params[:title])}"))
213
+ redirect(URI.escape("http://www.hyves.nl/profielbeheer/toevoegen/tips/?#{hyves_post("http://#{config[:hostname]}/#{@code}", title)}"))
199
214
  when :facebook
200
215
  redirect(URI.escape("http://www.facebook.com/share.php?u=http://#{config[:hostname]}/#{@code}"))
201
216
  end
data/lib/firefly/url.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Firefly
2
3
  class Url
3
4
  include DataMapper::Resource
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  module Firefly
2
- VERSION = "1.5.0"
3
+ VERSION = "1.5.1"
3
4
  end
data/lib/firefly.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'rubygems'
2
3
  require 'open-uri'
3
4
  require 'cgi'
@@ -18,7 +18,7 @@ describe "Sharing" do
18
18
  end
19
19
 
20
20
  [:post, :get].each do |verb|
21
- describe "facebook" do
21
+ describe "facebook via #{verb.to_s.upcase}" do
22
22
  it "should create a shortened URL" do
23
23
  lambda {
24
24
  self.send verb, '/api/share', @params
@@ -1,5 +1,4 @@
1
1
  # encoding: UTF-8
2
- # encoding: UTF-8
3
2
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
4
3
 
5
4
  describe "Sharing" do
@@ -19,7 +18,7 @@ describe "Sharing" do
19
18
  end
20
19
 
21
20
  [:post, :get].each do |verb|
22
- describe "hyves" do
21
+ describe "hyves via #{verb.to_s.upcase}" do
23
22
  it "should create a shortened URL" do
24
23
  lambda {
25
24
  self.send verb, '/api/share', @params
@@ -86,6 +85,14 @@ describe "Sharing" do
86
85
  last_response['Location'].should_not include(URI.escape(title))
87
86
  end
88
87
 
88
+ it "should strip the title from url encoded entities correctly" do
89
+ title = "Test%20post"
90
+ self.send verb, '/api/share', @params.merge(:title => title)
91
+ url = Firefly::Url.first(:url => @params[:url])
92
+
93
+ last_response['Location'].should include(URI.escape("Test post"))
94
+ last_response['Location'].should_not include(URI.escape(title))
95
+ end
89
96
 
90
97
  it "should escape UTF-8 correctly" do
91
98
  title = "Chávez"
@@ -18,7 +18,7 @@ describe "Sharing" do
18
18
  end
19
19
 
20
20
  [:post, :get].each do |verb|
21
- describe "twitter" do
21
+ describe "twitter via #{verb.to_s.upcase}" do
22
22
  it "should create a shortened URL" do
23
23
  lambda {
24
24
  self.send verb, '/api/share', @params
@@ -82,6 +82,15 @@ describe "Sharing" do
82
82
  last_response['Location'].should_not include(URI.escape(title))
83
83
  end
84
84
 
85
+ it "should strip the title from url encoded entities correctly" do
86
+ title = "Test%20post"
87
+ self.send verb, '/api/share', @params.merge(:title => title)
88
+ url = Firefly::Url.first(:url => @params[:url])
89
+
90
+ last_response['Location'].should include(URI.escape("Test post http://test.host/#{url.code}"))
91
+ last_response['Location'].should_not include(URI.escape(title))
92
+ end
93
+
85
94
  it "should escape UTF-8 correctly" do
86
95
  title = "Chávez"
87
96
  self.send verb, '/api/share', @params.merge(:title => title)
data/views/index.haml CHANGED
@@ -32,7 +32,7 @@
32
32
  %tr.highlighted
33
33
  %td.value
34
34
  %input{ :type => "text", :value => short_url(@highlight), :class => 'short_url', :size => 21 }
35
- %td.value.fill <a href="#{@highlight.url}">#{@highlight.url}</a>
35
+ %td.value.fill <a href="#{@highlight.url}">#{truncate @highlight.url, 130}</a>
36
36
  %td.value.center= @highlight.clicks
37
37
  %td.value= @highlight.created_at.strftime("%Y-%m-%d %H:%M")
38
38
  %td.value
@@ -52,7 +52,7 @@
52
52
  %tr{ :class => is_highlighted?(url) ? 'highlighted' : '' }
53
53
  %td.value
54
54
  %input{ :type => "text", :value => short_url(url), :class => 'short_url', :size => 31 }
55
- %td.value.fill <a href="#{url.url}">#{url.url}</a>
55
+ %td.value.fill <a href="#{url.url}">#{truncate url.url, 130}</a>
56
56
  %td.value.center= url.clicks
57
57
  %td.value= url.created_at.strftime("%Y-%m-%d %H:%M")
58
58
  %td.value
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: firefly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
5
- prerelease:
4
+ hash: 1
5
+ prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 0
10
- version: 1.5.0
9
+ - 1
10
+ version: 1.5.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ariejan de Vroom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-21 00:00:00 +02:00
18
+ date: 2011-04-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -26,11 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- hash: 15
29
+ hash: 25
30
30
  segments:
31
31
  - 1
32
- - 0
33
- version: "1.0"
32
+ - 2
33
+ - 3
34
+ version: 1.2.3
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  - !ruby/object:Gem::Dependency
@@ -287,7 +288,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
287
288
  requirements: []
288
289
 
289
290
  rubyforge_project: firefly
290
- rubygems_version: 1.5.0
291
+ rubygems_version: 1.3.7
291
292
  signing_key:
292
293
  specification_version: 3
293
294
  summary: Firefly is your own personal URL shortener for your own domain.