snails 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/snails.rb +72 -6
  3. data/snails.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9e946b88b3bdb2b3eefe77e280c749762dbe7d4
4
- data.tar.gz: 90b0d741fc5275db8ce7e8bf69b15d1d2c91f5bc
3
+ metadata.gz: 4400d3577ffe665951a185e806b60dfc17d4df1f
4
+ data.tar.gz: 7c3b08235ab641c057492e1b947ea00b6c8e2ea4
5
5
  SHA512:
6
- metadata.gz: cb0cb3f776a4af75305765b8bc8589342268e08d2b4b8dd1fe4cc08b22325625ceaeae1ef4e802d46440461e2fd9de4ea1982467ee10716e4c33e17e95b0433d
7
- data.tar.gz: cd57113fecfe119d3b76f94e85fe9859f4454e385474bc39a19b5b8a90555640514357c113a74a56187653ff16e462bdbe1d00c127298f432a6c97975338808e
6
+ metadata.gz: 427ca357316bc92b3bb1ecdfbeda822e872e0e5c958496c8bcd431c43fe10071c8fb5f080fed5e34a013a6da62f7b2daa5cb6294279a505f81c3f8ebe92c1e9b
7
+ data.tar.gz: 803ee94a83c7c8740c0788742f85389ef522a5b6596542e4c26124b9a4fd8d04e67a4c27bd623c8481137800bf3c64cd75f830c23a9b93bb468b01821c3f2b13
data/lib/snails.rb CHANGED
@@ -49,19 +49,21 @@ module Snails
49
49
  super
50
50
  end
51
51
 
52
- LOGGER = Logger.new(File.exist?("#{Dir.pwd}/log") ? "#{Dir.pwd}/log/#{Snails.env}.log" : nil)
53
-
54
52
  cwd = Pathname.new(Dir.pwd) # settings.root
53
+ LOGGER = Logger.new(File.exist?(cwd.join('log')) ? cwd.join('log', "#{Snails.env}.log") : nil)
54
+
55
55
  set :protection, except: :frame_options
56
56
  set :views, cwd.join('lib', 'views')
57
57
  set :session_secret, ENV.fetch('SESSION_SECRET') { SecureRandom.hex }
58
+ set :static_paths, %w(/css /img /js /files /fonts favicon.ico)
59
+
58
60
  enable :sessions
59
61
  enable :method_override
60
62
  enable :logging
61
63
 
62
64
  register Sinatra::Flash
63
65
  use Rack::CommonLogger, LOGGER
64
- use Rack::Static, urls: %w(/css /img /js /files /fonts favicon.ico), root: 'public'
66
+ use Rack::Static, urls: static_paths, root: 'public'
65
67
 
66
68
  configure :production, :staging do
67
69
  set :raise_errors, true
@@ -100,7 +102,7 @@ module Snails
100
102
  end
101
103
 
102
104
  def show_error(code)
103
- erb :"errors/#{code}", :layout => false
105
+ erb :"errors/#{code}", layout: false
104
106
  end
105
107
 
106
108
  end
@@ -183,7 +185,7 @@ module Snails
183
185
  cwd = Pathname.new(Dir.pwd)
184
186
  app.set :sprockets, Sprockets::Environment.new(cwd)
185
187
  app.set :assets_prefix, '/assets' # URL
186
- # app.set :digest_assets, false
188
+ app.set :digest_assets, false
187
189
  app.set :assets_public_path, -> { cwd.join('public', 'assets') } # output dir
188
190
  app.set :assets_paths, %w(assets) # source files
189
191
  app.set :assets_precompile, %w(js/main.js css/main.css)
@@ -202,7 +204,7 @@ module Snails
202
204
 
203
205
  app.configure :development do
204
206
  # allow asset requests to pass
205
- # app.allow_paths.push /^#{app.assets_prefix}(\/\w+)?\/([\w\.-]+)/
207
+ app.allow_paths.push /^#{app.assets_prefix}(\/\w+)?\/([\w\.-]+)/
206
208
 
207
209
  # and serve them
208
210
  app.get "#{app.assets_prefix}/*" do |path|
@@ -279,6 +281,10 @@ module Snails
279
281
 
280
282
  module ViewHelpers
281
283
 
284
+ def self.included(base)
285
+ Time.include(RelativeTime) unless Time.instance_methods.include?(:relative)
286
+ end
287
+
282
288
  def action
283
289
  request.path_info.gsub('/','').blank? ? 'home' : request.path_info.gsub('/',' ')
284
290
  end
@@ -293,6 +299,29 @@ module Snails
293
299
  erb(view_name.to_sym, { layout: layout }.merge(opts))
294
300
  end
295
301
 
302
+ #########################################
303
+ # pagination
304
+
305
+ def get_page(counter)
306
+ curr = params[:page].to_i
307
+ i = (curr == 0 && counter == 1) ? 2
308
+ : (curr == 2 && counter == -1) ? 0
309
+ : curr + counter
310
+ i == 0 ? "" : "/page/#{i}"
311
+ end
312
+
313
+ def show_pager(array, path)
314
+ # remove page from path
315
+ path = (env['SCRIPT_NAME'] + path.gsub(/[?|&|\/]page[=|\/]\d+/,''))
316
+
317
+ prevlink = '<li>' + link_to("#{path}#{get_page(-1)}", '&larr; Prev').sub('//', '/') + '</li>'
318
+ nextlink = array.count != Routes::PER_PAGE ? ""
319
+ : '<li>' + link_to("#{path}#{get_page(1)}", 'Next &rarr;').sub('//', '/') + '</li>'
320
+
321
+ str = params[:page] ? prevlink + nextlink : nextlink
322
+ str != "" ? "<ul class='pager'>" + str + "</ul>" : ''
323
+ end
324
+
296
325
  #########################################
297
326
  # formatting
298
327
 
@@ -426,4 +455,41 @@ module Snails
426
455
 
427
456
  end
428
457
 
458
+ module RelativeTime
459
+
460
+ def in_words
461
+ minutes = (((Time.now - self).abs)/60).round
462
+ return nil if minutes < 0
463
+
464
+ case minutes
465
+ when 0..1 then 'menos de un min'
466
+ when 2..4 then 'menos de 5 min'
467
+ when 5..14 then 'menos de 15 min'
468
+ when 15..29 then "media hora"
469
+ when 30..59 then "#{minutes} minutos"
470
+ when 60..119 then '1 hora'
471
+ when 120..239 then '2 horas'
472
+ when 240..479 then '4 horas'
473
+ when 480..719 then '8 horas'
474
+ when 720..1439 then '12 horas'
475
+ when 1440..11519 then "#{(minutes/1440).floor} días"
476
+ when 11520..43199 then "#{(minutes/11520).floor} semanas"
477
+ when 43200..525599 then "#{(minutes/43200).floor} meses"
478
+ else "#{(minutes/525600).floor} años"
479
+ end
480
+ end
481
+
482
+ def relative
483
+ if str = in_words
484
+ if Time.now < self
485
+ # "#{str} más"
486
+ "en #{str}"
487
+ else
488
+ "hace #{str}"
489
+ end
490
+ end
491
+ end
492
+
493
+ end
494
+
429
495
  end
data/snails.gemspec CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "snails"
6
- s.version = '0.0.5'
6
+ s.version = '0.0.6'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Tomás Pollak']
9
9
  s.email = ['tomas@forkhq.com']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak