snails 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ab3513b9c123ab48d240332a7d065867a37aa1e
4
- data.tar.gz: d0631690d2f6c57636dafea1e5c6a1803f68fa6f
3
+ metadata.gz: d801e91a29c8c095e5f94fdbc15edaec46a0be6e
4
+ data.tar.gz: df0ed66fbd0a2fb2d955a9db41ae85022e9ed8da
5
5
  SHA512:
6
- metadata.gz: 6c74964dd253df391741e6daba7d8dc7e802280a363bc639f2846e92d7e6caaca4e3600ab58724526fafa44042e638d02e9518b2c450f2c6e0b8e4604252cb9a
7
- data.tar.gz: 9840ba4d2517a9396835d732b0a6b46f5da5c4c326f3e52b6d15374075c00178a44e807fa2de9147f9378793dbdb4dd8699e39f87b354625ae17f6b25ee7a4f0
6
+ metadata.gz: aa89a7c352c5aa0d3445fb5e884241cbdb7fa629dff97fef576f90d361f8671bb64b7f8c48aa3d2608b468dbf86d8fb099104d9f0c8ec75b0f48558ce47dd34f
7
+ data.tar.gz: f7b36827e10d29214eef8f8c450011b76f024c1e91a6522709b3f4ecd3f2a0cc2aed3df247cbbfe11e47a1de9730adfd11726108aff1d68d2eaf90e8c47175ec
data/lib/snails/app.rb CHANGED
@@ -1,5 +1,7 @@
1
+ require 'snails' unless defined?(Snails)
2
+
1
3
  %w(
2
- snails
4
+ snails/util
3
5
  active_support/core_ext/hash
4
6
  sinatra/base
5
7
  sinatra/content_for
@@ -317,36 +319,6 @@ module Snails
317
319
 
318
320
  end
319
321
 
320
- module SimpleFormat
321
-
322
- def tag(name, options = nil, open = false)
323
- attributes = tag_attributes(options)
324
- "<#{name}#{attributes}#{open ? '>' : ' />'}"
325
- end
326
-
327
- def tag_attributes(options)
328
- return '' unless options
329
- options.inject('') do |all,(key,value)|
330
- next all unless value
331
- all << ' ' if all.empty?
332
- all << %(#{key}="#{value}" )
333
- end.chomp!(' ')
334
- end
335
-
336
- def simple_format(text, options = {})
337
- t = options.delete(:tag) || :p
338
- start_tag = tag(t, options, true)
339
- text = text.to_s.dup
340
- text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
341
- text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
342
- text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
343
- text.insert 0, start_tag
344
- text << "</#{t}>"
345
- text
346
- end
347
-
348
- end
349
-
350
322
  module ViewHelpers
351
323
 
352
324
  def self.included(base)
@@ -394,46 +366,6 @@ module Snails
394
366
 
395
367
  end
396
368
 
397
- module RelativeTime
398
-
399
- def self.minutes_in_words(min)
400
- case min.to_i
401
- when 0..1 then 'menos de un min'
402
- when 2..4 then 'menos de 5 min'
403
- when 5..14 then 'menos de 15 min'
404
- when 15..29 then "media hora"
405
- when 30..59 then "#{min} minutos"
406
- when 60..119 then '1 hora'
407
- when 120..239 then '2 horas'
408
- when 240..479 then '4 horas'
409
- when 480..719 then '8 horas'
410
- when 720..1439 then '12 horas'
411
- when 1440..11519 then "#{(min/1440).floor} días"
412
- when 11520..43199 then "#{(min/11520).floor} semanas"
413
- when 43200..525599 then "#{(min/43200).floor} meses"
414
- else "#{(min/525600).floor} años"
415
- end
416
- end
417
-
418
- def in_words
419
- minutes = (((Time.now - self).abs)/60).round
420
- return nil if minutes < 0
421
- RelativeTime.minutes_in_words(minutes)
422
- end
423
-
424
- def relative
425
- if str = in_words
426
- if Time.now < self
427
- # "#{str} más"
428
- "en #{str}"
429
- else
430
- "hace #{str}"
431
- end
432
- end
433
- end
434
-
435
- end
436
-
437
369
  class App < Sinatra::Base
438
370
 
439
371
  def self.inherited(base)
data/lib/snails/mailer.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'snails/util'
1
2
  require 'erb'
2
3
  require 'tilt/erb'
3
4
  require 'tuktuk'
@@ -0,0 +1,75 @@
1
+ # used both in app and mailer, so we put them here
2
+
3
+ module Snails
4
+
5
+ module RelativeTime
6
+
7
+ def self.minutes_in_words(min)
8
+ case min.to_i
9
+ when 0..1 then 'menos de un min'
10
+ when 2..4 then 'menos de 5 min'
11
+ when 5..14 then 'menos de 15 min'
12
+ when 15..29 then "media hora"
13
+ when 30..59 then "#{min} minutos"
14
+ when 60..119 then '1 hora'
15
+ when 120..239 then '2 horas'
16
+ when 240..479 then '4 horas'
17
+ when 480..719 then '8 horas'
18
+ when 720..1439 then '12 horas'
19
+ when 1440..11519 then "#{(min/1440).floor} días"
20
+ when 11520..43199 then "#{(min/11520).floor} semanas"
21
+ when 43200..525599 then "#{(min/43200).floor} meses"
22
+ else "#{(min/525600).floor} años"
23
+ end
24
+ end
25
+
26
+ def in_words
27
+ minutes = (((Time.now - self).abs)/60).round
28
+ return nil if minutes < 0
29
+ RelativeTime.minutes_in_words(minutes)
30
+ end
31
+
32
+ def relative
33
+ if str = in_words
34
+ if Time.now < self
35
+ # "#{str} más"
36
+ "en #{str}"
37
+ else
38
+ "hace #{str}"
39
+ end
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ module SimpleFormat
46
+
47
+ def tag(name, options = nil, open = false)
48
+ attributes = tag_attributes(options)
49
+ "<#{name}#{attributes}#{open ? '>' : ' />'}"
50
+ end
51
+
52
+ def tag_attributes(options)
53
+ return '' unless options
54
+ options.inject('') do |all,(key,value)|
55
+ next all unless value
56
+ all << ' ' if all.empty?
57
+ all << %(#{key}="#{value}" )
58
+ end.chomp!(' ')
59
+ end
60
+
61
+ def simple_format(text, options = {})
62
+ t = options.delete(:tag) || :p
63
+ start_tag = tag(t, options, true)
64
+ text = text.to_s.dup
65
+ text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
66
+ text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
67
+ text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
68
+ text.insert 0, start_tag
69
+ text << "</#{t}>"
70
+ text
71
+ end
72
+
73
+ end
74
+
75
+ end
data/lib/snails.rb CHANGED
@@ -30,5 +30,5 @@ module Snails
30
30
  end
31
31
  end
32
32
 
33
- # require 'snails/app'
33
+ require 'snails/app'
34
34
  puts "Loaded #{Snails.env} environment."
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.2.0'
6
+ s.version = '0.2.1'
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomás Pollak
@@ -160,6 +160,7 @@ files:
160
160
  - lib/snails/mailer.rb
161
161
  - lib/snails/rspec.rb
162
162
  - lib/snails/tasks.rb
163
+ - lib/snails/util.rb
163
164
  - snails.gemspec
164
165
  homepage:
165
166
  licenses: []