tmin 0.0.9 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tmin (0.0.8)
4
+ tmin (0.0.9)
5
5
  dm-aggregates (~> 1.2.0)
6
6
  dm-core (~> 1.2.0)
7
7
  dm-migrations (~> 1.2.0)
data/firefly.sqlite3 ADDED
Binary file
data/lib/tmin/server.rb CHANGED
@@ -158,22 +158,49 @@ module Firefly
158
158
  @authenticated = has_valid_api_cookie?
159
159
  @config = config
160
160
  @highlight = nil
161
- @title = "tminus.it at http://#{@config[:hostname]}"
161
+ @title = "tminus.it"
162
162
 
163
163
  set :session_secret, @config[:session_secret]
164
164
  end
165
165
 
166
166
  get '/' do
167
+ if @authenticated
167
168
  @highlight = Firefly::Url.first(:code => params[:highlight])
168
169
  @error = params[:highlight] == "error"
169
170
 
170
171
  sort_column = params[:s] || 'created_at'
171
172
  sort_order = params[:d] || 'desc'
173
+
172
174
 
173
175
  @urls = Firefly::Url.all(:limit => config[:recent_urls], :order => [ sort_column.to_sym.send(sort_order.to_sym) ] )
174
176
 
177
+
178
+ haml :admin
179
+ else
175
180
  haml :index
176
181
  end
182
+ end
183
+
184
+
185
+ get '/admin' do
186
+
187
+ if @unthenticated
188
+ redirect "/", 301
189
+ else
190
+ @highlight = Firefly::Url.first(:code => params[:highlight])
191
+ @error = params[:highlight] == "error"
192
+
193
+ sort_column = params[:s] || 'created_at'
194
+ sort_order = params[:d] || 'desc'
195
+
196
+
197
+ @urls = Firefly::Url.all(:limit => config[:recent_urls], :order => [ sort_column.to_sym.send(sort_order.to_sym) ] )
198
+
199
+
200
+ haml :admin
201
+ end
202
+ end
203
+
177
204
 
178
205
  post '/api/set' do
179
206
  store_api_key(params[:api_key])
@@ -269,15 +296,26 @@ module Firefly
269
296
  get '/:code' do
270
297
  @url = Firefly::Url.first(:code => params[:code])
271
298
 
299
+
300
+
272
301
  if @url.nil?
273
302
  status 404
274
303
  "Sorry, that code is unknown."
304
+
305
+ else
306
+ if @url.code == 'ec'
307
+ @short_url = "http://#{config[:hostname]}/#{@url.code}"
308
+ @url.register_click!
309
+ haml :ec
275
310
  else
276
311
  @short_url = "http://#{config[:hostname]}/#{@url.code}"
277
312
  @url.register_click!
278
313
  haml :redirect
279
314
  end
280
315
  end
316
+ end
317
+
318
+
281
319
 
282
320
  def initialize config = {}, &blk
283
321
  super
data/lib/tmin/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module Tminus
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
  end
Binary file
data/tmin-0.0.9.gem ADDED
Binary file
data/views/admin.haml ADDED
@@ -0,0 +1,92 @@
1
+ - if @authenticated
2
+ .sidebox
3
+ %h2 Bookmarklet
4
+
5
+ %p
6
+ Drag the following link to your bookmarks. Click it to shorten the URL to the page you're currently viewing.
7
+ %p
8
+ %a{ :href => "javascript:var%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:('%22'+enc(s)+'%22')),key=enc('#{@config[:api_key]}'),f='http://#{@config[:hostname]}/api/add',l=d.location,p='?visual=1&api_key='+key+'&url='+enc(l.href),u=f+p;try{if(!/^(.*\.)?tumblrzzz[^.]*$/.test(l.host))throw(0);tstbklt();}catch(z){a%20=function(){if(!w.open(u))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();}void(0)" } Shorten with #{@config[:hostname]}
9
+
10
+ %h1 How about shortening a URL?
11
+
12
+ .the_form
13
+ %form{ :action => '/api/add', :method => 'post' }
14
+ %input{ :type => "hidden", :name => "visual", :value => "1" }
15
+ %p
16
+ %input.big_url{ :type => 'text', :placeholder => "Paste your long URL here...", :name => 'url', :id => 'url', :size => 40, :autocomplete => "off", :spellcheck => 'false' }
17
+ %span{ :style => "font-size: 1.8em;" }= '>'
18
+ %input.big_url{ :type => 'text', :placeholder => "Optional short code", :name => 'short', :id => 'short', :size => 20, :autocomplete => "off", :spellcheck => 'false' }
19
+ %p
20
+ %input.big_url{ :type => 'submit', :name => 'submit', :id => 'submit', :value => "Make it short!" }
21
+
22
+ - if @highlight
23
+ %h2 Your short URL
24
+
25
+ %table
26
+ %tr
27
+ %td.label Short URL
28
+ %td.label Full URL
29
+ %td.label Clicks
30
+ %td.label Shortened at
31
+ %td.label  
32
+ %tr.highlighted
33
+ %td.value
34
+ %input{ :type => "text", :value => short_url(@highlight), :class => 'short_url', :size => 21 }
35
+ %td.value.fill <a href="#{@highlight.url}">#{truncate @highlight.url, 130}</a>
36
+ %td.value.center= @highlight.clicks
37
+ %td.value= @highlight.created_at.strftime("%Y-%m-%d %H:%M")
38
+ %td.value
39
+ %a{ :href => "http://twitter.com/home?status=#{tweet(short_url(@highlight))}" }
40
+ %img.twitter{ :src => "/images/twitter.png", :width => "16", :height => "16" }
41
+
42
+ %h2 Recently shortened
43
+
44
+ %table
45
+ %tr
46
+ %td.label(nowrap='nowrap') Short URL <a href="/?s=code&d=asc">▲</a> <a href="/?s=code&d=desc">▼</a>
47
+ %td.label(nowrap='nowrap') Full URL <a href="/?s=url&d=asc">▲</a> <a href="/?s=url&d=desc">▼</a>
48
+ %td.label(nowrap='nowrap') Clicks <a href="/?s=clicks&d=asc">▲</a> <a href="/?s=clicks&d=desc">▼</a>
49
+ %td.label(nowrap='nowrap') Shortened At <a href="/?s=created_at&d=asc">▲</a> <a href="/?s=created_at&d=desc">▼</a>
50
+ %td.label &nbsp;
51
+ - @urls.each do |url|
52
+ %tr{ :class => is_highlighted?(url) ? 'highlighted' : '' }
53
+ %td.value
54
+ %input{ :type => "text", :value => short_url(url), :class => 'short_url', :size => 31 }
55
+ %td.value.fill <a href="#{url.url}">#{truncate url.url, 95}</a>
56
+ %td.value.center= url.clicks
57
+ %td.value= url.created_at.strftime("%Y-%m-%d %H:%M")
58
+ %td.value
59
+ %a{ :href => "http://twitter.com/home?status=#{tweet(short_url(url))}" }
60
+ %img.twitter{ :src => "/images/twitter.png", :width => "16", :height => "16" }
61
+
62
+
63
+ :javascript
64
+ $(document).ready(function() {
65
+ $('input.short_url').each(function(index) {
66
+ $(this).mouseup(function() { $(this).select(); });
67
+ });
68
+
69
+ if (window.location.search == "") {
70
+ var pathname = window.location.pathname + '?s=created_at&d=desc';
71
+ } else {
72
+ var pathname = window.location.pathname + window.location.search;
73
+ }
74
+
75
+ $('#main table tr td.label a').each(function(index) {
76
+ if ($(this).attr('href') == pathname) {
77
+ $(this).addClass('highlight');
78
+ }
79
+ });
80
+ });
81
+ - else
82
+ %h1 Please enter your API key
83
+
84
+ %p
85
+ Please enter your API key below to make sure only you can shorten URLs here.
86
+
87
+ %form{ :action => '/api/set', :method => 'post' }
88
+ %p
89
+ %label{ :for => 'api_key' } API Key
90
+ %input{ :type => 'password', :name => 'api_key', :id => 'api_key' }
91
+ %p
92
+ %input{ :type => 'submit', :name => 'submit', :id => 'submit', :value => "Let me in" }
data/views/ec.haml ADDED
@@ -0,0 +1,35 @@
1
+ %a#applink1{:href => "#{@url.url}"}
2
+ %img#thumb{:src => "/images/ec_background.gif", :alt => "My Pic"}
3
+ %p Download tminus now
4
+
5
+
6
+ :javascript
7
+ var ref = document.referrer;
8
+ if(ref && ref.toLowerCase().indexOf("twitter.com")!==-1){
9
+ window.location.href="/";
10
+ }
11
+ var appstorefail = "itms://itunes.apple.com/us/app/tminus-make-share-countdown/id507726329?mt=8";
12
+ function applink(fail){
13
+ return function(){
14
+ var clickedAt = +new Date;
15
+ // During tests on 3g/3gs this timeout fires immediately if less than 500ms.
16
+ setTimeout(function(){
17
+ // To avoid failing on return to MobileSafari, ensure freshness!
18
+ if (+new Date - clickedAt < 2000){
19
+ window.location = fail;
20
+ }
21
+ }, 500);
22
+ };
23
+ }
24
+ document.getElementById("applink1").onclick = applink(appstorefail);
25
+ var button = document.getElementById("applink1")
26
+ simulateClick("applink1");
27
+ function simulateClick(elId) {
28
+ var evt;
29
+ var el = document.getElementById(elId);
30
+ if (document.createEvent) {
31
+ evt = document.createEvent("MouseEvents");
32
+ evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
33
+ }
34
+ (evt) ? el.dispatchEvent(evt) : (el.click && el.click());
35
+ }
data/views/index.haml CHANGED
@@ -1,91 +1 @@
1
- - if @authenticated
2
- .sidebox
3
- %h2 Bookmarklet
4
-
5
- %p
6
- Drag the following link to your bookmarks. Click it to shorten the URL to the page you're currently viewing.
7
- %p
8
- %a{ :href => "javascript:var%20d=document,w=window,enc=encodeURIComponent,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),s2=((s.toString()=='')?s:('%22'+enc(s)+'%22')),key=enc('#{@config[:api_key]}'),f='http://#{@config[:hostname]}/api/add',l=d.location,p='?visual=1&api_key='+key+'&url='+enc(l.href),u=f+p;try{if(!/^(.*\.)?tumblrzzz[^.]*$/.test(l.host))throw(0);tstbklt();}catch(z){a%20=function(){if(!w.open(u))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();}void(0)" } Shorten with #{@config[:hostname]}
9
-
10
- %h1 How about shortening a URL?
11
-
12
- .the_form
13
- %form{ :action => '/api/add', :method => 'post' }
14
- %input{ :type => "hidden", :name => "visual", :value => "1" }
15
- %p
16
- %input.big_url{ :type => 'text', :placeholder => "Paste your long URL here...", :name => 'url', :id => 'url', :size => 40, :autocomplete => "off", :spellcheck => 'false' }
17
- %span{ :style => "font-size: 1.8em;" }= '>'
18
- %input.big_url{ :type => 'text', :placeholder => "Optional short code", :name => 'short', :id => 'short', :size => 20, :autocomplete => "off", :spellcheck => 'false' }
19
- %p
20
- %input.big_url{ :type => 'submit', :name => 'submit', :id => 'submit', :value => "Make it short!" }
21
-
22
- - if @highlight
23
- %h2 Your short URL
24
-
25
- %table
26
- %tr
27
- %td.label Short URL
28
- %td.label Full URL
29
- %td.label Clicks
30
- %td.label Shortened at
31
- %td.label &nbsp;
32
- %tr.highlighted
33
- %td.value
34
- %input{ :type => "text", :value => short_url(@highlight), :class => 'short_url', :size => 21 }
35
- %td.value.fill <a href="#{@highlight.url}">#{truncate @highlight.url, 130}</a>
36
- %td.value.center= @highlight.clicks
37
- %td.value= @highlight.created_at.strftime("%Y-%m-%d %H:%M")
38
- %td.value
39
- %a{ :href => "http://twitter.com/home?status=#{tweet(short_url(@highlight))}" }
40
- %img.twitter{ :src => "/images/twitter.png", :width => "16", :height => "16" }
41
-
42
- %h2 Recently shortened
43
-
44
- %table
45
- %tr
46
- %td.label(nowrap='nowrap') Short URL <a href="/?s=code&d=asc">▲</a> <a href="/?s=code&d=desc">▼</a>
47
- %td.label(nowrap='nowrap') Full URL <a href="/?s=url&d=asc">▲</a> <a href="/?s=url&d=desc">▼</a>
48
- %td.label(nowrap='nowrap') Clicks <a href="/?s=clicks&d=asc">▲</a> <a href="/?s=clicks&d=desc">▼</a>
49
- %td.label(nowrap='nowrap') Shortened At <a href="/?s=created_at&d=asc">▲</a> <a href="/?s=created_at&d=desc">▼</a>
50
- %td.label &nbsp;
51
- - @urls.each do |url|
52
- %tr{ :class => is_highlighted?(url) ? 'highlighted' : '' }
53
- %td.value
54
- %input{ :type => "text", :value => short_url(url), :class => 'short_url', :size => 31 }
55
- %td.value.fill <a href="#{url.url}">#{truncate url.url, 130}</a>
56
- %td.value.center= url.clicks
57
- %td.value= url.created_at.strftime("%Y-%m-%d %H:%M")
58
- %td.value
59
- %a{ :href => "http://twitter.com/home?status=#{tweet(short_url(url))}" }
60
- %img.twitter{ :src => "/images/twitter.png", :width => "16", :height => "16" }
61
-
62
- :javascript
63
- $(document).ready(function() {
64
- $('input.short_url').each(function(index) {
65
- $(this).mouseup(function() { $(this).select(); });
66
- });
67
-
68
- if (window.location.search == "") {
69
- var pathname = window.location.pathname + '?s=created_at&d=desc';
70
- } else {
71
- var pathname = window.location.pathname + window.location.search;
72
- }
73
-
74
- $('#main table tr td.label a').each(function(index) {
75
- if ($(this).attr('href') == pathname) {
76
- $(this).addClass('highlight');
77
- }
78
- });
79
- });
80
- - else
81
- %h1 Please enter your API key
82
-
83
- %p
84
- Please enter your API key below to make sure only you can shorten URLs here.
85
-
86
- %form{ :action => '/api/set', :method => 'post' }
87
- %p
88
- %label{ :for => 'api_key' } API Key
89
- %input{ :type => 'password', :name => 'api_key', :id => 'api_key' }
90
- %p
91
- %input{ :type => 'submit', :name => 'submit', :id => 'submit', :value => "Let me in" }
1
+ %h3 Nothing to see here!
data/views/redirect.haml CHANGED
@@ -1,6 +1,12 @@
1
1
  <a id="applink1" href="#{@url.url}">Opening the awesome event now!</a>
2
2
 
3
+
4
+
3
5
  :javascript
6
+ var ref = document.referrer;
7
+ if(ref && ref.toLowerCase().indexOf("twitter.com")!==-1){
8
+ window.location.href="/";
9
+ }
4
10
  var appstorefail = "itms://itunes.apple.com/us/app/tminus-make-share-countdown/id507726329?mt=8";
5
11
  function applink(fail){
6
12
  return function(){
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tmin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 9
10
- version: 0.0.9
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - drobs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-15 00:00:00 -05:00
18
+ date: 2012-03-22 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -228,6 +228,7 @@ files:
228
228
  - README.rdoc
229
229
  - Rakefile
230
230
  - config.ru.example
231
+ - firefly.sqlite3
231
232
  - lib/tmin.rb
232
233
  - lib/tmin/base62.rb
233
234
  - lib/tmin/code_factory.rb
@@ -236,6 +237,7 @@ files:
236
237
  - lib/tmin/url.rb
237
238
  - lib/tmin/version.rb
238
239
  - public/favicon.ico
240
+ - public/images/ec_background.gif
239
241
  - public/images/twitter.png
240
242
  - public/jquery-1.4.2.min.js
241
243
  - public/reset.css
@@ -261,7 +263,11 @@ files:
261
263
  - tmin-0.0.6.gem
262
264
  - tmin-0.0.7.gem
263
265
  - tmin-0.0.8.gem
266
+ - tmin-0.0.9.gem
267
+ - tmin-0.1.0.gem
264
268
  - tmin.gemspec
269
+ - views/admin.haml
270
+ - views/ec.haml
265
271
  - views/error.haml
266
272
  - views/index.haml
267
273
  - views/info.haml