padrino-helpers 0.2.9 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/padrino-helpers.rb +3 -0
- data/lib/padrino-helpers/asset_tag_helpers.rb +1 -1
- data/lib/padrino-helpers/form_helpers.rb +2 -2
- data/lib/padrino-helpers/format_helpers.rb +95 -31
- data/lib/padrino-helpers/locale/en.yml +117 -0
- data/lib/padrino-helpers/render_helpers.rb +3 -34
- data/padrino-helpers.gemspec +3 -2
- data/test/fixtures/render_app/app.rb +6 -32
- data/test/helper.rb +1 -3
- data/test/support_helpers.rb +16 -1
- data/test/test_format_helpers.rb +18 -21
- data/test/test_render_helpers.rb +2 -30
- metadata +3 -2
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.5
|
data/lib/padrino-helpers.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'padrino-core/support_lite'
|
2
2
|
Dir[File.dirname(__FILE__) + '/padrino-helpers/**/*.rb'].each {|file| require file }
|
3
3
|
|
4
|
+
# Load our locales
|
5
|
+
I18n.load_path += Dir["#{File.dirname(__FILE__)}/padrino-helpers/locale/*.yml"]
|
6
|
+
|
4
7
|
module Padrino
|
5
8
|
module Helpers
|
6
9
|
def self.registered(app)
|
@@ -45,7 +45,7 @@ module Padrino
|
|
45
45
|
# meta_tag "text/html; charset=UTF-8", :http-equiv => "Content-Type" => <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
46
46
|
def meta_tag(content, options={})
|
47
47
|
options.reverse_merge!("content" => content)
|
48
|
-
|
48
|
+
tag(:meta, options)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Creates an image element with given url and options
|
@@ -174,8 +174,8 @@ module Padrino
|
|
174
174
|
# 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
|
175
175
|
# hidden_form_method_field('delete') => <input name="_method" value="delete" />
|
176
176
|
def hidden_form_method_field(desired_method)
|
177
|
-
return '' if (desired_method =~ /get|post/)
|
178
|
-
original_method = desired_method.dup
|
177
|
+
return '' if (desired_method.to_s =~ /get|post/)
|
178
|
+
original_method = desired_method.to_s.dup
|
179
179
|
desired_method.replace('post')
|
180
180
|
hidden_field_tag(:_method, :value => original_method)
|
181
181
|
end
|
@@ -65,42 +65,106 @@ module Padrino
|
|
65
65
|
end * "\n"
|
66
66
|
end
|
67
67
|
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
# Reports the approximate distance in time between two Time or Date objects or integers as seconds.
|
69
|
+
# Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs
|
70
|
+
# Distances are reported based on the following table:
|
71
|
+
#
|
72
|
+
# 0 <-> 29 secs # => less than a minute
|
73
|
+
# 30 secs <-> 1 min, 29 secs # => 1 minute
|
74
|
+
# 1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] minutes
|
75
|
+
# 44 mins, 30 secs <-> 89 mins, 29 secs # => about 1 hour
|
76
|
+
# 89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => about [2..24] hours
|
77
|
+
# 23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1 day
|
78
|
+
# 47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] days
|
79
|
+
# 29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => about 1 month
|
80
|
+
# 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] months
|
81
|
+
# 1 yr <-> 1 yr, 3 months # => about 1 year
|
82
|
+
# 1 yr, 3 months <-> 1 yr, 9 months # => over 1 year
|
83
|
+
# 1 yr, 9 months <-> 2 yr minus 1 sec # => almost 2 years
|
84
|
+
# 2 yrs <-> max time or date # => (same rules as 1 yr)
|
85
|
+
#
|
86
|
+
# With <tt>include_seconds</tt> = true and the difference < 1 minute 29 seconds:
|
87
|
+
# 0-4 secs # => less than 5 seconds
|
88
|
+
# 5-9 secs # => less than 10 seconds
|
89
|
+
# 10-19 secs # => less than 20 seconds
|
90
|
+
# 20-39 secs # => half a minute
|
91
|
+
# 40-59 secs # => less than a minute
|
92
|
+
# 60-89 secs # => 1 minute
|
93
|
+
#
|
94
|
+
# ==== Examples
|
95
|
+
# from_time = Time.now
|
96
|
+
# distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
|
97
|
+
# distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour
|
98
|
+
# distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute
|
99
|
+
# distance_of_time_in_words(from_time, from_time + 15.seconds, true) # => less than 20 seconds
|
100
|
+
# distance_of_time_in_words(from_time, 3.years.from_now) # => about 3 years
|
101
|
+
# distance_of_time_in_words(from_time, from_time + 60.hours) # => about 3 days
|
102
|
+
# distance_of_time_in_words(from_time, from_time + 45.seconds, true) # => less than a minute
|
103
|
+
# distance_of_time_in_words(from_time, from_time - 45.seconds, true) # => less than a minute
|
104
|
+
# distance_of_time_in_words(from_time, 76.seconds.from_now) # => 1 minute
|
105
|
+
# distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year
|
106
|
+
# distance_of_time_in_words(from_time, from_time + 3.years + 6.months) # => over 3 years
|
107
|
+
# distance_of_time_in_words(from_time, from_time + 4.years + 9.days + 30.minutes + 5.seconds) # => about 4 years
|
108
|
+
#
|
109
|
+
# to_time = Time.now + 6.years + 19.days
|
110
|
+
# distance_of_time_in_words(from_time, to_time, true) # => about 6 years
|
111
|
+
# distance_of_time_in_words(to_time, from_time, true) # => about 6 years
|
112
|
+
# distance_of_time_in_words(Time.now, Time.now) # => less than a minute
|
113
|
+
#
|
114
|
+
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
|
115
|
+
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
116
|
+
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
117
|
+
distance_in_minutes = (((to_time - from_time).abs)/60).round
|
118
|
+
distance_in_seconds = ((to_time - from_time).abs).round
|
75
119
|
|
76
|
-
|
77
|
-
|
78
|
-
|
120
|
+
I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
|
121
|
+
case distance_in_minutes
|
122
|
+
when 0..1
|
123
|
+
return distance_in_minutes == 0 ?
|
124
|
+
locale.t(:less_than_x_minutes, :count => 1) :
|
125
|
+
locale.t(:x_minutes, :count => distance_in_minutes) unless include_seconds
|
79
126
|
|
80
|
-
|
81
|
-
|
127
|
+
case distance_in_seconds
|
128
|
+
when 0..4 then locale.t :less_than_x_seconds, :count => 5
|
129
|
+
when 5..9 then locale.t :less_than_x_seconds, :count => 10
|
130
|
+
when 10..19 then locale.t :less_than_x_seconds, :count => 20
|
131
|
+
when 20..39 then locale.t :half_a_minute
|
132
|
+
when 40..59 then locale.t :less_than_x_minutes, :count => 1
|
133
|
+
else locale.t :x_minutes, :count => 1
|
134
|
+
end
|
82
135
|
|
83
|
-
|
84
|
-
|
136
|
+
when 2..44 then locale.t :x_minutes, :count => distance_in_minutes
|
137
|
+
when 45..89 then locale.t :about_x_hours, :count => 1
|
138
|
+
when 90..1439 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round
|
139
|
+
when 1440..2529 then locale.t :x_days, :count => 1
|
140
|
+
when 2530..43199 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round
|
141
|
+
when 43200..86399 then locale.t :about_x_months, :count => 1
|
142
|
+
when 86400..525599 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round
|
143
|
+
else
|
144
|
+
distance_in_years = distance_in_minutes / 525600
|
145
|
+
minute_offset_for_leap_year = (distance_in_years / 4) * 1440
|
146
|
+
remainder = ((distance_in_minutes - minute_offset_for_leap_year) % 525600)
|
147
|
+
if remainder < 131400
|
148
|
+
locale.t(:about_x_years, :count => distance_in_years)
|
149
|
+
elsif remainder < 394200
|
150
|
+
locale.t(:over_x_years, :count => distance_in_years)
|
151
|
+
else
|
152
|
+
locale.t(:almost_x_years, :count => distance_in_years + 1)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
85
156
|
end
|
86
|
-
alias time_ago time_in_words
|
87
157
|
|
88
|
-
#
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
|
99
|
-
when 43200..86399 then 'about 1 month'
|
100
|
-
when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
|
101
|
-
when 525600..1051199 then 'about 1 year'
|
102
|
-
else "over #{(distance_in_minutes / 525600).round} years"
|
103
|
-
end
|
158
|
+
# Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
|
159
|
+
#
|
160
|
+
# ==== Examples
|
161
|
+
# time_ago_in_words(3.minutes.from_now) # => 3 minutes
|
162
|
+
# time_ago_in_words(Time.now - 15.hours) # => 15 hours
|
163
|
+
# time_ago_in_words(Time.now) # => less than a minute
|
164
|
+
#
|
165
|
+
# from_time = Time.now - 3.days - 14.minutes - 25.seconds # => 3 days
|
166
|
+
def time_ago_in_words(from_time, include_seconds = false)
|
167
|
+
distance_of_time_in_words(from_time, Time.now, include_seconds)
|
104
168
|
end
|
105
169
|
|
106
170
|
# Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino
|
@@ -0,0 +1,117 @@
|
|
1
|
+
en:
|
2
|
+
number:
|
3
|
+
# Used in number_with_delimiter()
|
4
|
+
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
5
|
+
format:
|
6
|
+
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
|
7
|
+
separator: "."
|
8
|
+
# Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
|
9
|
+
delimiter: ","
|
10
|
+
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
11
|
+
precision: 3
|
12
|
+
|
13
|
+
# Used in number_to_currency()
|
14
|
+
currency:
|
15
|
+
format:
|
16
|
+
# Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
|
17
|
+
format: "%u%n"
|
18
|
+
unit: "$"
|
19
|
+
# These three are to override number.format and are optional
|
20
|
+
separator: "."
|
21
|
+
delimiter: ","
|
22
|
+
precision: 2
|
23
|
+
|
24
|
+
# Used in number_to_percentage()
|
25
|
+
percentage:
|
26
|
+
format:
|
27
|
+
# These three are to override number.format and are optional
|
28
|
+
# separator:
|
29
|
+
delimiter: ""
|
30
|
+
# precision:
|
31
|
+
|
32
|
+
# Used in number_to_precision()
|
33
|
+
precision:
|
34
|
+
format:
|
35
|
+
# These three are to override number.format and are optional
|
36
|
+
# separator:
|
37
|
+
delimiter: ""
|
38
|
+
# precision:
|
39
|
+
|
40
|
+
# Used in number_to_human_size()
|
41
|
+
human:
|
42
|
+
format:
|
43
|
+
# These three are to override number.format and are optional
|
44
|
+
# separator:
|
45
|
+
delimiter: ""
|
46
|
+
precision: 1
|
47
|
+
storage_units:
|
48
|
+
# Storage units output formatting.
|
49
|
+
# %u is the storage unit, %n is the number (default: 2 MB)
|
50
|
+
format: "%n %u"
|
51
|
+
units:
|
52
|
+
byte:
|
53
|
+
one: "Byte"
|
54
|
+
other: "Bytes"
|
55
|
+
kb: "KB"
|
56
|
+
mb: "MB"
|
57
|
+
gb: "GB"
|
58
|
+
tb: "TB"
|
59
|
+
|
60
|
+
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
|
61
|
+
datetime:
|
62
|
+
distance_in_words:
|
63
|
+
half_a_minute: "half a minute"
|
64
|
+
less_than_x_seconds:
|
65
|
+
one: "less than 1 second"
|
66
|
+
other: "less than {{count}} seconds"
|
67
|
+
x_seconds:
|
68
|
+
one: "1 second"
|
69
|
+
other: "{{count}} seconds"
|
70
|
+
less_than_x_minutes:
|
71
|
+
one: "less than a minute"
|
72
|
+
other: "less than {{count}} minutes"
|
73
|
+
x_minutes:
|
74
|
+
one: "1 minute"
|
75
|
+
other: "{{count}} minutes"
|
76
|
+
about_x_hours:
|
77
|
+
one: "about 1 hour"
|
78
|
+
other: "about {{count}} hours"
|
79
|
+
x_days:
|
80
|
+
one: "1 day"
|
81
|
+
other: "{{count}} days"
|
82
|
+
about_x_months:
|
83
|
+
one: "about 1 month"
|
84
|
+
other: "about {{count}} months"
|
85
|
+
x_months:
|
86
|
+
one: "1 month"
|
87
|
+
other: "{{count}} months"
|
88
|
+
about_x_years:
|
89
|
+
one: "about 1 year"
|
90
|
+
other: "about {{count}} years"
|
91
|
+
over_x_years:
|
92
|
+
one: "over 1 year"
|
93
|
+
other: "over {{count}} years"
|
94
|
+
almost_x_years:
|
95
|
+
one: "almost 1 year"
|
96
|
+
other: "almost {{count}} years"
|
97
|
+
prompts:
|
98
|
+
year: "Year"
|
99
|
+
month: "Month"
|
100
|
+
day: "Day"
|
101
|
+
hour: "Hour"
|
102
|
+
minute: "Minute"
|
103
|
+
second: "Seconds"
|
104
|
+
|
105
|
+
activemodel:
|
106
|
+
errors:
|
107
|
+
template:
|
108
|
+
header:
|
109
|
+
one: "1 error prohibited this {{model}} from being saved"
|
110
|
+
other: "{{count}} errors prohibited this {{model}} from being saved"
|
111
|
+
# The variable :count is also available
|
112
|
+
body: "There were problems with the following fields:"
|
113
|
+
|
114
|
+
support:
|
115
|
+
select:
|
116
|
+
# default value for :prompt => true in FormOptionsHelper
|
117
|
+
prompt: "Please select"
|
@@ -1,26 +1,6 @@
|
|
1
1
|
module Padrino
|
2
2
|
module Helpers
|
3
3
|
module RenderHelpers
|
4
|
-
# Renders a erb template based on the relative path
|
5
|
-
# erb_template 'users/new'
|
6
|
-
def erb_template(template_path, options={})
|
7
|
-
render_template template_path, options.merge(:template_engine => :erb)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Renders a haml template based on the relative path
|
11
|
-
# haml_template 'users/new'
|
12
|
-
def haml_template(template_path, options={})
|
13
|
-
render_template template_path, options.merge(:template_engine => :haml)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Renders a template from a file path automatically determining rendering engine
|
17
|
-
# render_template 'users/new'
|
18
|
-
# options = { :template_engine => 'haml' }
|
19
|
-
def render_template(template_path, options={})
|
20
|
-
template_engine = options.delete(:template_engine) || resolve_template_engine(template_path)
|
21
|
-
render template_engine.to_sym, template_path.to_sym, options
|
22
|
-
end
|
23
|
-
|
24
4
|
# Partials implementation which includes collections support
|
25
5
|
# partial 'photo/_item', :object => @photo
|
26
6
|
# partial 'photo/_item', :collection => @photos
|
@@ -37,27 +17,16 @@ module Padrino
|
|
37
17
|
collection.collect do |member|
|
38
18
|
counter += 1
|
39
19
|
options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter)
|
40
|
-
|
20
|
+
render(template_path, nil, options.merge(:layout => false))
|
41
21
|
end.join("\n")
|
42
22
|
else
|
43
23
|
if member = options.delete(:object)
|
44
24
|
options[:locals].merge!(object_name => member)
|
45
25
|
end
|
46
|
-
|
26
|
+
render(template_path, nil, options.merge(:layout => false))
|
47
27
|
end
|
48
28
|
end
|
49
|
-
alias render_partial partial
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# Returns the template engine (i.e haml) to use for a given template_path
|
54
|
-
# resolve_template_engine('users/new') => :haml
|
55
|
-
def resolve_template_engine(template_path)
|
56
|
-
resolved_template_path = File.join(self.options.views, template_path.to_s + ".*")
|
57
|
-
template_file = Dir[resolved_template_path].first
|
58
|
-
raise "Template path '#{template_path}' could not be located in views!" unless template_file
|
59
|
-
template_engine = File.extname(template_file)[1..-1].to_sym
|
60
|
-
end
|
29
|
+
alias :render_partial :partial
|
61
30
|
end
|
62
31
|
end
|
63
32
|
end
|
data/padrino-helpers.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{padrino-helpers}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2010-01-06}
|
13
13
|
s.description = %q{Tag helpers, asset helpers, form helpers, form builders and many more helpers for padrino}
|
14
14
|
s.email = %q{nesquena@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"lib/padrino-helpers/form_builder/standard_form_builder.rb",
|
29
29
|
"lib/padrino-helpers/form_helpers.rb",
|
30
30
|
"lib/padrino-helpers/format_helpers.rb",
|
31
|
+
"lib/padrino-helpers/locale/en.yml",
|
31
32
|
"lib/padrino-helpers/output_helpers.rb",
|
32
33
|
"lib/padrino-helpers/render_helpers.rb",
|
33
34
|
"lib/padrino-helpers/tag_helpers.rb",
|
@@ -1,41 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT
|
2
|
+
PADRINO_ENV = 'test' unless defined? PADRINO_ENV
|
3
|
+
|
4
|
+
require 'padrino-core'
|
3
5
|
|
4
6
|
class RenderUser
|
5
7
|
attr_accessor :name
|
6
8
|
def initialize(name); @name = name; end
|
7
9
|
end
|
8
10
|
|
9
|
-
class RenderDemo <
|
10
|
-
|
11
|
-
|
12
|
-
configure do
|
13
|
-
set :root, File.dirname(__FILE__)
|
14
|
-
end
|
15
|
-
|
16
|
-
# haml_template
|
17
|
-
get '/render_haml' do
|
18
|
-
@template = 'haml'
|
19
|
-
haml_template 'haml/test'
|
20
|
-
end
|
21
|
-
|
22
|
-
# erb_template
|
23
|
-
get '/render_erb' do
|
24
|
-
@template = 'erb'
|
25
|
-
erb_template 'erb/test'
|
26
|
-
end
|
27
|
-
|
28
|
-
# render_template with explicit engine
|
29
|
-
get '/render_template/:engine' do
|
30
|
-
@template = params[:engine]
|
31
|
-
render_template "template/#{@template}_template", :template_engine => @template
|
32
|
-
end
|
33
|
-
|
34
|
-
# render_template without explicit engine
|
35
|
-
get '/render_template' do
|
36
|
-
render_template "template/some_template"
|
37
|
-
end
|
38
|
-
|
11
|
+
class RenderDemo < Padrino::Application
|
12
|
+
|
39
13
|
# partial with object
|
40
14
|
get '/partial/object' do
|
41
15
|
partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" }
|
data/test/helper.rb
CHANGED
@@ -5,10 +5,8 @@ require 'mocha'
|
|
5
5
|
require 'rack/test'
|
6
6
|
require 'webrat'
|
7
7
|
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
10
8
|
require 'support_helpers'
|
11
|
-
require
|
9
|
+
require 'padrino-helpers'
|
12
10
|
|
13
11
|
class Test::Unit::TestCase
|
14
12
|
include Padrino::Helpers::OutputHelpers
|
data/test/support_helpers.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
+
require 'padrino-core/support_lite'
|
1
2
|
unless Fixnum.method_defined?(:days)
|
2
|
-
|
3
|
+
# We don't add active_support/core_ext/object/misc because override some extlib defaults
|
4
|
+
if Padrino.support == :extlib
|
5
|
+
class Object
|
6
|
+
# A duck-type assistant method. For example, Active Support extends Date
|
7
|
+
# to define an acts_like_date? method, and extends Time to define
|
8
|
+
# acts_like_time?. As a result, we can do "x.acts_like?(:time)" and
|
9
|
+
# "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that
|
10
|
+
# we want to act like Time simply need to define an acts_like_time? method.
|
11
|
+
def acts_like?(duck)
|
12
|
+
respond_to? "acts_like_#{duck}?"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
else
|
16
|
+
require 'active_support/core_ext/object/misc'
|
17
|
+
end
|
3
18
|
require 'active_support/core_ext/date'
|
4
19
|
require 'active_support/core_ext/time'
|
5
20
|
require 'active_support/core_ext/numeric'
|
data/test/test_format_helpers.rb
CHANGED
@@ -87,60 +87,57 @@ class TestFormatHelpers < Test::Unit::TestCase
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
context 'for #
|
90
|
+
context 'for #time_ago_in_words method' do
|
91
91
|
should "display today" do
|
92
|
-
assert_equal '
|
92
|
+
assert_equal 'less than a minute', time_ago_in_words(Time.now)
|
93
93
|
end
|
94
94
|
should "display yesterday" do
|
95
|
-
assert_equal '
|
95
|
+
assert_equal '1 day', time_ago_in_words(1.day.ago)
|
96
96
|
end
|
97
97
|
should "display tomorrow" do
|
98
|
-
assert_equal '
|
98
|
+
assert_equal '1 day', time_ago_in_words(1.day.from_now)
|
99
99
|
end
|
100
100
|
should "return future number of days" do
|
101
|
-
assert_equal '
|
101
|
+
assert_equal '4 days', time_ago_in_words(4.days.from_now)
|
102
102
|
end
|
103
103
|
should "return past days ago" do
|
104
|
-
assert_equal '4 days
|
104
|
+
assert_equal '4 days', time_ago_in_words(4.days.ago)
|
105
105
|
end
|
106
106
|
should "return formatted archived date" do
|
107
|
-
assert_equal
|
107
|
+
assert_equal '3 months', time_ago_in_words(100.days.ago)
|
108
108
|
end
|
109
109
|
should "return formatted archived year date" do
|
110
|
-
assert_equal
|
110
|
+
assert_equal 'over 1 year', time_ago_in_words(500.days.ago)
|
111
111
|
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context 'for #relative_time_ago method' do
|
115
112
|
should 'display now as a minute ago' do
|
116
|
-
assert_equal '
|
113
|
+
assert_equal '1 minute', time_ago_in_words(1.minute.ago)
|
117
114
|
end
|
118
115
|
should "display a few minutes ago" do
|
119
|
-
assert_equal '4 minutes',
|
116
|
+
assert_equal '4 minutes', time_ago_in_words(4.minute.ago)
|
120
117
|
end
|
121
118
|
should "display an hour ago" do
|
122
|
-
assert_equal 'about 1 hour',
|
119
|
+
assert_equal 'about 1 hour', time_ago_in_words(1.hour.ago + 5.minutes.ago.sec)
|
123
120
|
end
|
124
121
|
should "display a few hours ago" do
|
125
|
-
assert_equal 'about 3 hours',
|
122
|
+
assert_equal 'about 3 hours', time_ago_in_words(3.hour.ago + 5.minutes.ago.sec)
|
126
123
|
end
|
127
124
|
should "display a day ago" do
|
128
|
-
assert_equal '1 day',
|
125
|
+
assert_equal '1 day', time_ago_in_words(1.day.ago)
|
129
126
|
end
|
130
127
|
should "display a few days ago" do
|
131
|
-
assert_equal '5 days',
|
128
|
+
assert_equal '5 days', time_ago_in_words(5.days.ago - 5.minutes.ago.sec)
|
132
129
|
end
|
133
130
|
should "display a month ago" do
|
134
|
-
assert_equal 'about 1 month',
|
131
|
+
assert_equal 'about 1 month', time_ago_in_words(32.days.ago + 5.minutes.ago.sec)
|
135
132
|
end
|
136
133
|
should "display a few months ago" do
|
137
|
-
assert_equal '6 months',
|
134
|
+
assert_equal '6 months', time_ago_in_words(180.days.ago - 5.minutes.ago.sec)
|
138
135
|
end
|
139
136
|
should "display a year ago" do
|
140
|
-
assert_equal 'about 1 year',
|
137
|
+
assert_equal 'about 1 year', time_ago_in_words(365.days.ago - 5.minutes.ago.sec)
|
141
138
|
end
|
142
139
|
should "display a few years ago" do
|
143
|
-
assert_equal 'over 7 years',
|
140
|
+
assert_equal 'over 7 years', time_ago_in_words(2800.days.ago - 5.minutes.ago.sec)
|
144
141
|
end
|
145
142
|
end
|
146
143
|
|
data/test/test_render_helpers.rb
CHANGED
@@ -6,34 +6,6 @@ class TestRenderHelpers < Test::Unit::TestCase
|
|
6
6
|
RenderDemo.tap { |app| app.set :environment, :test }
|
7
7
|
end
|
8
8
|
|
9
|
-
context 'for #haml_template method' do
|
10
|
-
setup { visit '/render_haml' }
|
11
|
-
should('render template properly') do
|
12
|
-
assert_have_selector "h1", :content => "This is a haml template!"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
context 'for #erb_template method' do
|
17
|
-
setup { visit '/render_erb' }
|
18
|
-
should('render template properly') do
|
19
|
-
assert_have_selector "h1", :content => "This is a erb template!"
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
context 'for #render_template method with explicit engine' do
|
24
|
-
setup { visit '/render_template/haml' }
|
25
|
-
should('render template properly') do
|
26
|
-
assert_have_selector "h1", :content => "This is a haml template sent from render_template!"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context 'for #render_template method without explicit engine' do
|
31
|
-
setup { visit '/render_template' }
|
32
|
-
should('render template properly') do
|
33
|
-
assert_have_selector "h1", :content => "This is a haml template which was detected!"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
9
|
context 'for #partial method and object' do
|
38
10
|
setup { visit '/partial/object' }
|
39
11
|
should "render partial html with object" do
|
@@ -46,7 +18,7 @@ class TestRenderHelpers < Test::Unit::TestCase
|
|
46
18
|
assert_have_selector 'p', :content => "Extra is bar"
|
47
19
|
end
|
48
20
|
end
|
49
|
-
|
21
|
+
|
50
22
|
context 'for #partial method and collection' do
|
51
23
|
setup { visit '/partial/collection' }
|
52
24
|
should "render partial html with collection" do
|
@@ -61,7 +33,7 @@ class TestRenderHelpers < Test::Unit::TestCase
|
|
61
33
|
assert_have_selector 'p', :content => "Extra is bar"
|
62
34
|
end
|
63
35
|
end
|
64
|
-
|
36
|
+
|
65
37
|
context 'for #partial method and locals' do
|
66
38
|
setup { visit '/partial/locals' }
|
67
39
|
should "render partial html with locals" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date:
|
15
|
+
date: 2010-01-06 00:00:00 +01:00
|
16
16
|
default_executable:
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/padrino-helpers/form_builder/standard_form_builder.rb
|
107
107
|
- lib/padrino-helpers/form_helpers.rb
|
108
108
|
- lib/padrino-helpers/format_helpers.rb
|
109
|
+
- lib/padrino-helpers/locale/en.yml
|
109
110
|
- lib/padrino-helpers/output_helpers.rb
|
110
111
|
- lib/padrino-helpers/render_helpers.rb
|
111
112
|
- lib/padrino-helpers/tag_helpers.rb
|