padrino-helpers 0.13.0.beta2 → 0.13.0.beta3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino/rendering.rb +16 -3
- data/lib/padrino-helpers/form_builder/abstract_form_builder.rb +35 -0
- data/lib/padrino-helpers/form_helpers.rb +219 -0
- data/test/fixtures/markup_app/views/form_for.erb +28 -0
- data/test/fixtures/markup_app/views/form_for.haml +22 -0
- data/test/fixtures/markup_app/views/form_for.slim +21 -0
- data/test/fixtures/markup_app/views/form_tag.erb +21 -0
- data/test/fixtures/markup_app/views/form_tag.haml +14 -0
- data/test/fixtures/markup_app/views/form_tag.slim +14 -0
- data/test/test_form_builder.rb +238 -0
- data/test/test_form_helpers.rb +298 -0
- data/test/test_rendering.rb +14 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04bc4991e6d578ff63ba8e869485e744e3383578
|
4
|
+
data.tar.gz: 17bd91f2a5fec04199e4985ca3b7b90d7e285399
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246cb04ce86e264275303dcc5d7f62a9b27e95dce324ce40341620b262ad8660089d24fd12c2c4057ceb60811db21eb6c6877171e4910c040566230b56ad2648
|
7
|
+
data.tar.gz: 7556f2f8fe3cd8a6b7fabab699401d91691032074f382536f682ff11ff72bc7486a79fa7cd01e39cd39b2377abb1ea239236d03518f042c4f22e3bf1d297f67a
|
data/lib/padrino/rendering.rb
CHANGED
@@ -34,6 +34,11 @@ module Padrino
|
|
34
34
|
/~$/ # This is for Gedit
|
35
35
|
] unless defined?(IGNORE_FILE_PATTERN)
|
36
36
|
|
37
|
+
##
|
38
|
+
# Defines common content-type alias mappings.
|
39
|
+
#
|
40
|
+
CONTENT_TYPE_ALIASES = { :htm => :html }
|
41
|
+
|
37
42
|
##
|
38
43
|
# Default options used in the resolve_template-method.
|
39
44
|
#
|
@@ -307,13 +312,14 @@ module Padrino
|
|
307
312
|
end
|
308
313
|
|
309
314
|
def select_template(templates, template_path, content_type, _locale)
|
310
|
-
|
315
|
+
symbol = content_type_symbol(content_type)
|
316
|
+
simple_content_type = [:html, :plain].include?(symbol)
|
311
317
|
target_path, target_engine = path_and_engine(template_path)
|
312
318
|
|
313
|
-
templates.find{ |file,_| file.to_s == "#{target_path}.#{locale}.#{
|
319
|
+
templates.find{ |file,_| file.to_s == "#{target_path}.#{locale}.#{symbol}" } ||
|
314
320
|
templates.find{ |file,_| file.to_s == "#{target_path}.#{locale}" && simple_content_type } ||
|
315
321
|
templates.find{ |file,engine| engine == target_engine || File.extname(file.to_s) == ".#{target_engine}" } ||
|
316
|
-
templates.find{ |file,_| file.to_s == "#{target_path}.#{
|
322
|
+
templates.find{ |file,_| file.to_s == "#{target_path}.#{symbol}" } ||
|
317
323
|
templates.find{ |file,_| file.to_s == "#{target_path}" && simple_content_type }
|
318
324
|
end
|
319
325
|
|
@@ -335,6 +341,13 @@ module Padrino
|
|
335
341
|
require 'padrino/rendering/erb_template'
|
336
342
|
settings.set :erb, Padrino::Rendering.engine_configurations[:erb]
|
337
343
|
end
|
344
|
+
|
345
|
+
def content_type_symbol(type)
|
346
|
+
if defined?(::Rack::Mime::MIME_TYPES) && type.kind_of?(String)
|
347
|
+
type = ::Rack::Mime::MIME_TYPES.key(type).sub(/\./,'').to_sym
|
348
|
+
end
|
349
|
+
CONTENT_TYPE_ALIASES[type] || type
|
350
|
+
end
|
338
351
|
end
|
339
352
|
end
|
340
353
|
end
|
@@ -117,6 +117,34 @@ module Padrino
|
|
117
117
|
@template.image_submit_tag source, options
|
118
118
|
end
|
119
119
|
|
120
|
+
def datetime_field(field, options={})
|
121
|
+
@template.datetime_field_tag field_name(field), default_options(field, options)
|
122
|
+
end
|
123
|
+
|
124
|
+
def datetime_local_field(field, options={})
|
125
|
+
@template.datetime_local_field_tag field_name(field), default_options(field, options)
|
126
|
+
end
|
127
|
+
|
128
|
+
def date_field(field, options={})
|
129
|
+
@template.date_field_tag field_name(field), default_options(field, options)
|
130
|
+
end
|
131
|
+
|
132
|
+
def month_field(field, options={})
|
133
|
+
@template.month_field_tag field_name(field), default_options(field, options)
|
134
|
+
end
|
135
|
+
|
136
|
+
def week_field(field, options={})
|
137
|
+
@template.week_field_tag field_name(field), default_options(field, options)
|
138
|
+
end
|
139
|
+
|
140
|
+
def time_field(field, options={})
|
141
|
+
@template.time_field_tag field_name(field), default_options(field, options)
|
142
|
+
end
|
143
|
+
|
144
|
+
def color_field(field, options={})
|
145
|
+
@template.color_field_tag field_name(field), default_options(field, options)
|
146
|
+
end
|
147
|
+
|
120
148
|
##
|
121
149
|
# Supports nested fields for a child model within a form.
|
122
150
|
# f.fields_for :addresses
|
@@ -146,6 +174,13 @@ module Padrino
|
|
146
174
|
[:hidden_field, :text_field, :text_area, :password_field, :file_field, :radio_button, :check_box, :select]
|
147
175
|
end
|
148
176
|
|
177
|
+
##
|
178
|
+
# Returns the human name of the field. Look that use builtin I18n.
|
179
|
+
#
|
180
|
+
def field_human_name(field)
|
181
|
+
I18n.translate("#{object_model_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models)
|
182
|
+
end
|
183
|
+
|
149
184
|
##
|
150
185
|
# Returns the name for the given field.
|
151
186
|
# field_name(:username) => "user[username]"
|
@@ -620,6 +620,185 @@ module Padrino
|
|
620
620
|
input_tag(:range, options)
|
621
621
|
end
|
622
622
|
|
623
|
+
DATETIME_ATTRIBUTES = [:value, :max, :min].freeze
|
624
|
+
COLOR_CODE_REGEXP = /\A#([0-9a-fA-F]{3}){1,2}\z/.freeze
|
625
|
+
|
626
|
+
##
|
627
|
+
# Constructs a datetime tag from the given options.
|
628
|
+
#
|
629
|
+
# @example
|
630
|
+
# datetime_field_tag('datetime_with_min_max', :min => DateTime.new(1993, 2, 24, 12, 30, 45),
|
631
|
+
# :max => DateTime.new(2000, 4, 1, 12, 0, 0))
|
632
|
+
# datetime_field_tag('datetime_with_value', :value => DateTime.new(2000, 4, 1, 12, 0, 0))
|
633
|
+
#
|
634
|
+
# @param [String] name
|
635
|
+
# The name of the datetime field.
|
636
|
+
# @param [Hash] options
|
637
|
+
# The html options for the datetime field.
|
638
|
+
# @option options [DateTime, String] :min
|
639
|
+
# The min date time of the datetime field.
|
640
|
+
# @option options [DateTime, String] :max
|
641
|
+
# The max date time of the datetime field.
|
642
|
+
# @option options [DateTime, String] :value
|
643
|
+
# The value of the datetime field. See examples for details.
|
644
|
+
# @return [String] The html datetime field
|
645
|
+
#
|
646
|
+
def datetime_field_tag(name, options = {})
|
647
|
+
options = { :name => name }.update(options)
|
648
|
+
options = convert_attributes_into_datetime("%Y-%m-%dT%T.%L%z", options)
|
649
|
+
input_tag(:datetime, options)
|
650
|
+
end
|
651
|
+
|
652
|
+
##
|
653
|
+
# Constructs a datetime-local tag from the given options.
|
654
|
+
#
|
655
|
+
# @example
|
656
|
+
# datetime_local_field_tag('datetime_local_with_min_max', :min => DateTime.new(1993, 2, 24, 12, 30, 45),
|
657
|
+
# :max => DateTime.new(2000, 4, 1, 12, 0, 0))
|
658
|
+
# datetime_local_field_tag('datetime_local_with_value', :value => DateTime.new(2000, 4, 1, 12, 0, 0))
|
659
|
+
#
|
660
|
+
# @param [String] name
|
661
|
+
# The name of the datetime local field.
|
662
|
+
# @param [Hash] options
|
663
|
+
# The html options for the datetime-local field.
|
664
|
+
# @option options [DateTime, String] :min
|
665
|
+
# The min date time of the datetime-local field.
|
666
|
+
# @option options [DateTime, String] :max
|
667
|
+
# The max date time of the datetime-local field.
|
668
|
+
# @option options [DateTime, String] :value
|
669
|
+
# The value of the datetime field. See examples for details.
|
670
|
+
# @return [String] The html datetime-local field
|
671
|
+
#
|
672
|
+
def datetime_local_field_tag(name, options = {})
|
673
|
+
options = { :name => name }.update(options)
|
674
|
+
options = convert_attributes_into_datetime("%Y-%m-%dT%T", options)
|
675
|
+
input_tag(:"datetime-local", options)
|
676
|
+
end
|
677
|
+
|
678
|
+
##
|
679
|
+
# Constructs a date tag from the given options.
|
680
|
+
#
|
681
|
+
# @example
|
682
|
+
# date_field_tag('date_with_min_max', :min => DateTime.new(1993, 2, 24),
|
683
|
+
# :max => DateTime.new(2000, 4, 1))
|
684
|
+
# date_field_tag('date_with_value', :value => DateTime.new(2000, 4, 1))
|
685
|
+
#
|
686
|
+
# @param [String] name
|
687
|
+
# The name of the date field.
|
688
|
+
# @param [Hash] options
|
689
|
+
# The html options for the date field.
|
690
|
+
# @option options [DateTime, String] :min
|
691
|
+
# The min date time of the date field.
|
692
|
+
# @option options [DateTime, String] :max
|
693
|
+
# The max date time of the date field.
|
694
|
+
# @option options [DateTime, String] :value
|
695
|
+
# The value of the date field. See examples for details.
|
696
|
+
# @return [String] The html date field
|
697
|
+
#
|
698
|
+
def date_field_tag(name, options = {})
|
699
|
+
options = { :name => name }.update(options)
|
700
|
+
options = convert_attributes_into_datetime("%Y-%m-%d", options)
|
701
|
+
input_tag(:date, options)
|
702
|
+
end
|
703
|
+
|
704
|
+
##
|
705
|
+
# Constructs a month tag from the given options.
|
706
|
+
#
|
707
|
+
# @example
|
708
|
+
# month_field_tag('month_with_min_max', :min => DateTime.new(1993, 2, 24),
|
709
|
+
# :max => DateTime.new(2000, 4, 1))
|
710
|
+
# month_field_tag('month_with_value', :value => DateTime.new(2000, 4, 1))
|
711
|
+
#
|
712
|
+
# @param [String] name
|
713
|
+
# The name of the month field.
|
714
|
+
# @param [Hash] options
|
715
|
+
# The html options for the month field.
|
716
|
+
# @option options [DateTime, String] :min
|
717
|
+
# The min month time of the month field.
|
718
|
+
# @option options [DateTime, String] :max
|
719
|
+
# The max month time of the month field.
|
720
|
+
# @option options [DateTime, String] :value
|
721
|
+
# The value of the month field. See examples for details.
|
722
|
+
# @return [String] The html month field
|
723
|
+
#
|
724
|
+
def month_field_tag(name, options = {})
|
725
|
+
options = { :name => name }.update(options)
|
726
|
+
options = convert_attributes_into_datetime("%Y-%m", options)
|
727
|
+
input_tag(:month, options)
|
728
|
+
end
|
729
|
+
|
730
|
+
##
|
731
|
+
# Constructs a week tag from the given options.
|
732
|
+
#
|
733
|
+
# @example
|
734
|
+
# week_field_tag('week_with_min_max', :min => DateTime.new(1993, 2, 24),
|
735
|
+
# :max => DateTime.new(2000, 4, 1))
|
736
|
+
# week_field_tag('week_with_value', :value => DateTime.new(2000, 4, 1))
|
737
|
+
#
|
738
|
+
# @param [String] name
|
739
|
+
# The name of the week field.
|
740
|
+
# @param [Hash] options
|
741
|
+
# The html options for the week field.
|
742
|
+
# @option options [DateTime, String] :min
|
743
|
+
# The min week time of the week field.
|
744
|
+
# @option options [DateTime, String] :max
|
745
|
+
# The max week time of the week field.
|
746
|
+
# @option options [DateTime, String] :value
|
747
|
+
# The value of the week field. See examples for details.
|
748
|
+
# @return [String] The html week field
|
749
|
+
#
|
750
|
+
def week_field_tag(name, options = {})
|
751
|
+
options = { :name => name }.update(options)
|
752
|
+
options = convert_attributes_into_datetime("%Y-W%W", options)
|
753
|
+
input_tag(:week, options)
|
754
|
+
end
|
755
|
+
|
756
|
+
##
|
757
|
+
# Constructs a time tag from the given options.
|
758
|
+
#
|
759
|
+
# @example
|
760
|
+
# time_field_tag('time_with_min_max', :max => Time.new(1993, 2, 24, 1, 19, 12),
|
761
|
+
# :min => Time.new(2008, 6, 21, 13, 30, 0))
|
762
|
+
# time_field_tag('time_with_value', :value => Time.new(2008, 6, 21, 13, 30, 0))
|
763
|
+
#
|
764
|
+
# @param [String] name
|
765
|
+
# The name of the time field.
|
766
|
+
# @param [Hash] options
|
767
|
+
# The html options for the time field.
|
768
|
+
# @option options [Time, DateTime, String] :min
|
769
|
+
# The min time of the time field.
|
770
|
+
# @option options [Time, DateTime, String] :max
|
771
|
+
# The max time of the time field.
|
772
|
+
# @option options [Time, DateTime, String] :value
|
773
|
+
# The value of the time field. See examples for details.
|
774
|
+
# @return [String] The html time field
|
775
|
+
#
|
776
|
+
def time_field_tag(name, options = {})
|
777
|
+
options = { :name => name }.update(options)
|
778
|
+
options = convert_attributes_into_datetime("%T.%L", options)
|
779
|
+
input_tag(:time, options)
|
780
|
+
end
|
781
|
+
|
782
|
+
##
|
783
|
+
# Constructs a color tag from the given options.
|
784
|
+
#
|
785
|
+
# @example
|
786
|
+
# color_field_tag('color', :value => "#ff0000")
|
787
|
+
# color_field_tag('color', :value => "#f00")
|
788
|
+
#
|
789
|
+
# @param [String] name
|
790
|
+
# The name of the color field.
|
791
|
+
# @param [Hash] options
|
792
|
+
# The html options for the color field.
|
793
|
+
# @option options [String] :value
|
794
|
+
# The value of the color field. See examples for details.
|
795
|
+
#
|
796
|
+
def color_field_tag(name, options = {})
|
797
|
+
options = { :name => name }.update(options)
|
798
|
+
options[:value] = adjust_color(options[:value])
|
799
|
+
input_tag(:color, options)
|
800
|
+
end
|
801
|
+
|
623
802
|
private
|
624
803
|
|
625
804
|
##
|
@@ -634,6 +813,46 @@ module Padrino
|
|
634
813
|
builder_class = "Padrino::Helpers::FormBuilder::#{builder_class}".constantize if builder_class.is_a?(String)
|
635
814
|
builder_class.new(self, object, options)
|
636
815
|
end
|
816
|
+
|
817
|
+
##
|
818
|
+
# Converts value into DateTime.
|
819
|
+
#
|
820
|
+
# @example
|
821
|
+
# datetime_value('1993-02-24T12:30:45') #=> #<DateTime: 1993-02-24T12:30:45+00:00>
|
822
|
+
#
|
823
|
+
def datetime_value(value)
|
824
|
+
if value.kind_of?(String)
|
825
|
+
DateTime.parse(value) rescue nil
|
826
|
+
else
|
827
|
+
value
|
828
|
+
end
|
829
|
+
end
|
830
|
+
|
831
|
+
##
|
832
|
+
# Converts special attributes into datetime format strings that conforms to RFC 3399.
|
833
|
+
#
|
834
|
+
def convert_attributes_into_datetime(format, options)
|
835
|
+
DATETIME_ATTRIBUTES.each_with_object(options) do |attribute|
|
836
|
+
value = datetime_value(options[attribute])
|
837
|
+
options[attribute] = value.strftime(format) if value.respond_to?(:strftime)
|
838
|
+
end
|
839
|
+
end
|
840
|
+
|
841
|
+
##
|
842
|
+
# Adjusts color code for the given color.
|
843
|
+
#
|
844
|
+
# @example
|
845
|
+
# adust_color("#000") #=> "#000000"
|
846
|
+
# adust_color("#ff0000") #=> "#ff0000"
|
847
|
+
# adust_color("#foobar") #=> "#000000"
|
848
|
+
#
|
849
|
+
def adjust_color(color)
|
850
|
+
return "#000000" unless color =~ COLOR_CODE_REGEXP
|
851
|
+
return color if (color_size = color.size) == 7
|
852
|
+
color.slice(1, color_size - 1).each_char.with_object("#") do |chr, obj|
|
853
|
+
obj << chr * 2
|
854
|
+
end
|
855
|
+
end
|
637
856
|
end
|
638
857
|
end
|
639
858
|
end
|
@@ -50,6 +50,34 @@
|
|
50
50
|
<%= f.label :remember_me %>
|
51
51
|
<%= f.check_box :remember_me, :value => '1' %>
|
52
52
|
</p>
|
53
|
+
<p>
|
54
|
+
<%= f.label :datetime %>
|
55
|
+
<%= f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0) %>
|
56
|
+
</p>
|
57
|
+
<p>
|
58
|
+
<%= f.label :datetime_local %>
|
59
|
+
<%= f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0) %>
|
60
|
+
</p>
|
61
|
+
<p>
|
62
|
+
<%= f.label :date %>
|
63
|
+
<%= f.date_field :date, :max => DateTime.new(2000, 4, 1) %>
|
64
|
+
</p>
|
65
|
+
<p>
|
66
|
+
<%= f.label :month %>
|
67
|
+
<%= f.month_field :month, :max => DateTime.new(2000, 4, 1) %>
|
68
|
+
</p>
|
69
|
+
<p>
|
70
|
+
<%= f.label :week %>
|
71
|
+
<%= f.week_field :week, :max => DateTime.new(2000, 4, 1) %>
|
72
|
+
</p>
|
73
|
+
<p>
|
74
|
+
<%= f.label :time %>
|
75
|
+
<%= f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0) %>
|
76
|
+
</p>
|
77
|
+
<p>
|
78
|
+
<%= f.label :color %>
|
79
|
+
<%= f.color_field :color, :value => "#f00" %>
|
80
|
+
</p>
|
53
81
|
<p><%= f.submit "Create", :class => 'success', :id => 'demo-button' %></p>
|
54
82
|
<p><%= f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button' %></p>
|
55
83
|
<% end %>
|
@@ -38,6 +38,28 @@
|
|
38
38
|
%p
|
39
39
|
= f.label :remember_me
|
40
40
|
= f.check_box :remember_me, :value => "1"
|
41
|
+
%p
|
42
|
+
= f.label :datetime
|
43
|
+
= f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0)
|
44
|
+
%p
|
45
|
+
= f.label :datetime_local
|
46
|
+
= f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0)
|
47
|
+
%p
|
48
|
+
= f.label :date
|
49
|
+
= f.date_field :date, :max => DateTime.new(2000, 4, 1)
|
50
|
+
%p
|
51
|
+
= f.label :month
|
52
|
+
= f.month_field :month, :max => DateTime.new(2000, 4, 1)
|
53
|
+
%p
|
54
|
+
= f.label :week
|
55
|
+
= f.week_field :week, :max => DateTime.new(2000, 4, 1)
|
56
|
+
%p
|
57
|
+
= f.label :time
|
58
|
+
= f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0)
|
59
|
+
%p
|
60
|
+
= f.label :color
|
61
|
+
= f.color_field :color, :value => "#f00"
|
62
|
+
</p>
|
41
63
|
%p
|
42
64
|
= f.submit "Create", :class => 'success', :id => 'demo-button'
|
43
65
|
%p
|
@@ -38,6 +38,27 @@
|
|
38
38
|
p
|
39
39
|
= f.label :remember_me
|
40
40
|
= f.check_box :remember_me, :value => "1"
|
41
|
+
p
|
42
|
+
= f.label :datetime
|
43
|
+
= f.datetime_field :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0)
|
44
|
+
p
|
45
|
+
= f.label :datetime_local
|
46
|
+
= f.datetime_local_field :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0)
|
47
|
+
p
|
48
|
+
= f.label :date
|
49
|
+
= f.date_field :date, :max => DateTime.new(2000, 4, 1)
|
50
|
+
p
|
51
|
+
= f.label :month
|
52
|
+
= f.month_field :month, :max => DateTime.new(2000, 4, 1)
|
53
|
+
p
|
54
|
+
= f.label :week
|
55
|
+
= f.week_field :week, :max => DateTime.new(2000, 4, 1)
|
56
|
+
p
|
57
|
+
= f.label :time
|
58
|
+
= f.time_field :time, :max => Time.new(2008, 6, 21, 13, 30, 0)
|
59
|
+
p
|
60
|
+
= f.label :color
|
61
|
+
= f.color_field :color, :value => "#f00"
|
41
62
|
p
|
42
63
|
= f.submit "Create", :class => 'success', :id => 'demo-button'
|
43
64
|
p
|
@@ -83,6 +83,27 @@
|
|
83
83
|
<%= range_field_tag('ranger_with_min_max', :min => 1, :max => 50) %>
|
84
84
|
<%= range_field_tag('ranger_with_range', :range => 1..5) %>
|
85
85
|
</p>
|
86
|
+
<p>
|
87
|
+
<%= datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) %>
|
88
|
+
</p>
|
89
|
+
<p>
|
90
|
+
<%= datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0) %>
|
91
|
+
</p>
|
92
|
+
<p>
|
93
|
+
<%= date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %>
|
94
|
+
</p>
|
95
|
+
<p>
|
96
|
+
<%= month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %>
|
97
|
+
</p>
|
98
|
+
<p>
|
99
|
+
<%= week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1) %>
|
100
|
+
</p>
|
101
|
+
<p>
|
102
|
+
<%= time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0) %>
|
103
|
+
</p>
|
104
|
+
<p>
|
105
|
+
<%= color_field_tag :color, :value => "#f00" %>
|
106
|
+
</p>
|
86
107
|
<% end %>
|
87
108
|
<% field_set_tag(:class => 'buttons') do %>
|
88
109
|
<%= submit_tag "Login" %>
|
@@ -69,6 +69,20 @@
|
|
69
69
|
%p
|
70
70
|
= range_field_tag('ranger_with_min_max', :min => 1, :max => 50)
|
71
71
|
= range_field_tag('ranger_with_range', :range => 1..5)
|
72
|
+
%p
|
73
|
+
= datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0)
|
74
|
+
%p
|
75
|
+
= datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0)
|
76
|
+
%p
|
77
|
+
= date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
78
|
+
%p
|
79
|
+
= month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
80
|
+
%p
|
81
|
+
= week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
82
|
+
%p
|
83
|
+
= time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0)
|
84
|
+
%p
|
85
|
+
= color_field_tag :color, :value => "#f00"
|
72
86
|
= field_set_tag(:class => 'buttons') do
|
73
87
|
= submit_tag "Login"
|
74
88
|
= button_tag "Cancel"
|
@@ -69,6 +69,20 @@
|
|
69
69
|
p
|
70
70
|
= range_field_tag('ranger_with_min_max', :min => 1, :max => 50)
|
71
71
|
= range_field_tag('ranger_with_range', :range => 1..5)
|
72
|
+
p
|
73
|
+
= datetime_field_tag :datetime, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0)
|
74
|
+
p
|
75
|
+
= datetime_local_field_tag :datetime_local, :max => DateTime.new(2000, 4, 1, 12, 0, 0), :min => DateTime.new(1993, 2, 24, 12, 30, 45), :value => DateTime.new(2000, 4, 1, 12, 0, 0)
|
76
|
+
p
|
77
|
+
= date_field_tag :date, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
78
|
+
p
|
79
|
+
= month_field_tag :month, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
80
|
+
p
|
81
|
+
= week_field_tag :week, :max => DateTime.new(2000, 4, 1), :min => DateTime.new(1993, 2, 24), :value => DateTime.new(2000, 4, 1)
|
82
|
+
p
|
83
|
+
= time_field_tag :time, :max => Time.new(2008, 6, 21, 13, 30, 0), :min => Time.new(1993, 2, 24, 1, 19, 12), :value => Time.new(2008, 6, 21, 13, 30, 0)
|
84
|
+
p
|
85
|
+
= color_field_tag :color, :value => "#f00"
|
72
86
|
|
73
87
|
= field_set_tag(:class => 'buttons') do
|
74
88
|
= submit_tag "Login"
|
data/test/test_form_builder.rb
CHANGED
@@ -1213,4 +1213,242 @@ describe "FormBuilder" do
|
|
1213
1213
|
assert_have_selector '#demo2 p input', :type => 'image', :class => 'image', :src => "/images/buttons/ok.png?#{@stamp}"
|
1214
1214
|
end
|
1215
1215
|
end
|
1216
|
+
|
1217
|
+
describe 'for #datetime_field method' do
|
1218
|
+
it 'should display correct datetime field html' do
|
1219
|
+
actual_html = standard_builder.datetime_field(:datetime)
|
1220
|
+
assert_has_tag('input[type=datetime]', :id => 'user_datetime', :name => 'user[datetime]') { actual_html }
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1224
|
+
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1225
|
+
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1226
|
+
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1227
|
+
actual_html = standard_builder.datetime_field(:datetime, :max => max, :min => min, :value => value)
|
1228
|
+
expected = {
|
1229
|
+
:id => 'user_datetime',
|
1230
|
+
:max => "2000-04-01T12:00:00.000+0000",
|
1231
|
+
:min => "1993-02-24T12:30:45.000+0000",
|
1232
|
+
:value => "2000-04-01T12:00:00.000+0000"
|
1233
|
+
}
|
1234
|
+
assert_has_tag('input[type=datetime]', expected) { actual_html }
|
1235
|
+
end
|
1236
|
+
|
1237
|
+
it 'should display correct datetime field in haml' do
|
1238
|
+
visit '/haml/form_for'
|
1239
|
+
assert_have_selector '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
it 'should display correct datetime field in erb' do
|
1243
|
+
visit '/erb/form_for'
|
1244
|
+
assert_have_selector '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
it 'should display correct datetime field in slim' do
|
1248
|
+
visit '/slim/form_for'
|
1249
|
+
assert_have_selector '#demo input[type=datetime]', :id => 'markup_user_datetime', :max => "2000-04-01T12:00:00.000+0000"
|
1250
|
+
end
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
describe 'for #datetime_local_field method' do
|
1254
|
+
it 'should display correct datetime-local field html' do
|
1255
|
+
actual_html = standard_builder.datetime_local_field(:datetime_local)
|
1256
|
+
assert_has_tag('input[type=datetime-local]', :id => 'user_datetime_local', :name => 'user[datetime_local]') { actual_html }
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1260
|
+
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1261
|
+
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1262
|
+
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1263
|
+
actual_html = standard_builder.datetime_local_field(:datetime_local, :max => max, :min => min, :value => value)
|
1264
|
+
expected = {
|
1265
|
+
:id => 'user_datetime_local',
|
1266
|
+
:max => "2000-04-01T12:00:00",
|
1267
|
+
:min => "1993-02-24T12:30:45",
|
1268
|
+
:value => "2000-04-01T12:00:00"
|
1269
|
+
}
|
1270
|
+
assert_has_tag('input[type=datetime-local]', expected) { actual_html }
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
it 'should display correct datetime-local field in haml' do
|
1274
|
+
visit '/haml/form_for'
|
1275
|
+
assert_have_selector '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
|
1276
|
+
end
|
1277
|
+
|
1278
|
+
it 'should display correct datetime-local field in erb' do
|
1279
|
+
visit '/erb/form_for'
|
1280
|
+
assert_have_selector '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
|
1281
|
+
end
|
1282
|
+
|
1283
|
+
it 'should display correct datetime-local field in slim' do
|
1284
|
+
visit '/slim/form_for'
|
1285
|
+
assert_have_selector '#demo input[type=datetime-local]', :id => 'markup_user_datetime_local'
|
1286
|
+
end
|
1287
|
+
end
|
1288
|
+
|
1289
|
+
describe 'for #date_field method' do
|
1290
|
+
it 'should display correct date field html' do
|
1291
|
+
actual_html = standard_builder.date_field(:date)
|
1292
|
+
assert_has_tag('input[type=date]', :id => 'user_date', :name => 'user[date]') { actual_html }
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1296
|
+
max = DateTime.new(2000, 4, 1)
|
1297
|
+
min = DateTime.new(1993, 2, 24)
|
1298
|
+
value = DateTime.new(2000, 4, 1)
|
1299
|
+
actual_html = standard_builder.date_field(:date, :max => max, :min => min, :value => value)
|
1300
|
+
expected = {
|
1301
|
+
:id => 'user_date',
|
1302
|
+
:max => "2000-04-01",
|
1303
|
+
:min => "1993-02-24",
|
1304
|
+
:value => "2000-04-01"
|
1305
|
+
}
|
1306
|
+
assert_has_tag('input[type=date]', expected) { actual_html }
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
it 'should display correct date field in haml' do
|
1310
|
+
visit '/haml/form_for'
|
1311
|
+
assert_have_selector '#demo input[type=date]', :id => 'markup_user_date'
|
1312
|
+
end
|
1313
|
+
|
1314
|
+
it 'should display correct date field in erb' do
|
1315
|
+
visit '/erb/form_for'
|
1316
|
+
assert_have_selector '#demo input[type=date]', :id => 'markup_user_date'
|
1317
|
+
end
|
1318
|
+
|
1319
|
+
it 'should display correct date field in slim' do
|
1320
|
+
visit '/slim/form_for'
|
1321
|
+
assert_have_selector '#demo input[type=date]', :id => 'markup_user_date'
|
1322
|
+
end
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
describe 'for #month_field method' do
|
1326
|
+
it 'should display correct month field html' do
|
1327
|
+
actual_html = standard_builder.month_field(:month)
|
1328
|
+
assert_has_tag('input[type=month]', :id => 'user_month', :name => 'user[month]') { actual_html }
|
1329
|
+
end
|
1330
|
+
|
1331
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1332
|
+
max = DateTime.new(2000, 4, 1)
|
1333
|
+
min = DateTime.new(1993, 2, 24)
|
1334
|
+
value = DateTime.new(2000, 4, 1)
|
1335
|
+
actual_html = standard_builder.month_field(:month, :max => max, :min => min, :value => value)
|
1336
|
+
expected = {
|
1337
|
+
:id => 'user_month',
|
1338
|
+
:max => "2000-04",
|
1339
|
+
:min => "1993-02",
|
1340
|
+
:value => "2000-04"
|
1341
|
+
}
|
1342
|
+
assert_has_tag('input[type=month]', expected) { actual_html }
|
1343
|
+
end
|
1344
|
+
|
1345
|
+
it 'should display correct month field in haml' do
|
1346
|
+
visit '/haml/form_for'
|
1347
|
+
assert_have_selector '#demo input[type=month]', :id => 'markup_user_month'
|
1348
|
+
end
|
1349
|
+
|
1350
|
+
it 'should display correct month field in erb' do
|
1351
|
+
visit '/erb/form_for'
|
1352
|
+
assert_have_selector '#demo input[type=month]', :id => 'markup_user_month'
|
1353
|
+
end
|
1354
|
+
|
1355
|
+
it 'should display correct month field in slim' do
|
1356
|
+
visit '/slim/form_for'
|
1357
|
+
assert_have_selector '#demo input[type=month]', :id => 'markup_user_month'
|
1358
|
+
end
|
1359
|
+
end
|
1360
|
+
|
1361
|
+
describe 'for #week_field method' do
|
1362
|
+
it 'should display correct week field html' do
|
1363
|
+
actual_html = standard_builder.week_field(:week)
|
1364
|
+
assert_has_tag('input[type=week]', :id => 'user_week', :name => 'user[week]') { actual_html }
|
1365
|
+
end
|
1366
|
+
|
1367
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1368
|
+
max = DateTime.new(2000, 4, 1)
|
1369
|
+
min = DateTime.new(1993, 2, 24)
|
1370
|
+
value = DateTime.new(2000, 4, 1)
|
1371
|
+
actual_html = standard_builder.week_field(:week, :max => max, :min => min, :value => value)
|
1372
|
+
expected = {
|
1373
|
+
:id => 'user_week',
|
1374
|
+
:max => "2000-W13",
|
1375
|
+
:min => "1993-W08",
|
1376
|
+
:value => "2000-W13"
|
1377
|
+
}
|
1378
|
+
assert_has_tag('input[type=week]', expected) { actual_html }
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
it 'should display correct week field in haml' do
|
1382
|
+
visit '/haml/form_for'
|
1383
|
+
assert_have_selector '#demo input[type=week]', :id => 'markup_user_week'
|
1384
|
+
end
|
1385
|
+
|
1386
|
+
it 'should display correct week field in erb' do
|
1387
|
+
visit '/erb/form_for'
|
1388
|
+
assert_have_selector '#demo input[type=week]', :id => 'markup_user_week'
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
it 'should display correct week field in slim' do
|
1392
|
+
visit '/slim/form_for'
|
1393
|
+
assert_have_selector '#demo input[type=week]', :id => 'markup_user_week'
|
1394
|
+
end
|
1395
|
+
end
|
1396
|
+
|
1397
|
+
describe 'for #time_field method' do
|
1398
|
+
it 'should display correct time field html' do
|
1399
|
+
actual_html = standard_builder.time_field(:time)
|
1400
|
+
assert_has_tag('input[type=time]', :id => 'user_time', :name => 'user[time]') { actual_html }
|
1401
|
+
end
|
1402
|
+
|
1403
|
+
it 'should format DateTime to correct value if min and max and value options exist' do
|
1404
|
+
max = Time.new(2008, 6, 21, 13, 30, 0)
|
1405
|
+
min = Time.new(1993, 2, 24, 1, 19, 12)
|
1406
|
+
value = Time.new(2008, 6, 21, 13, 30, 0)
|
1407
|
+
actual_html = standard_builder.time_field(:time, :max => max, :min => min, :value => value)
|
1408
|
+
expected = {
|
1409
|
+
:id => 'user_time',
|
1410
|
+
:max => "13:30:00.000",
|
1411
|
+
:min => "01:19:12.000",
|
1412
|
+
:value => "13:30:00.000"
|
1413
|
+
}
|
1414
|
+
assert_has_tag('input[type=time]', expected) { actual_html }
|
1415
|
+
end
|
1416
|
+
|
1417
|
+
it 'should display correct time field in haml' do
|
1418
|
+
visit '/haml/form_for'
|
1419
|
+
assert_have_selector '#demo input[type=time]', :id => 'markup_user_time'
|
1420
|
+
end
|
1421
|
+
|
1422
|
+
it 'should display correct time field in erb' do
|
1423
|
+
visit '/erb/form_for'
|
1424
|
+
assert_have_selector '#demo input[type=time]', :id => 'markup_user_time'
|
1425
|
+
end
|
1426
|
+
|
1427
|
+
it 'should display correct time field in slim' do
|
1428
|
+
visit '/slim/form_for'
|
1429
|
+
assert_have_selector '#demo input[type=time]', :id => 'markup_user_time'
|
1430
|
+
end
|
1431
|
+
end
|
1432
|
+
|
1433
|
+
describe 'for #color_field method' do
|
1434
|
+
it 'should display correct color field html' do
|
1435
|
+
actual_html = standard_builder.color_field(:color)
|
1436
|
+
assert_has_tag('input[type=color]', :id => 'user_color', :name => 'user[color]') { actual_html }
|
1437
|
+
end
|
1438
|
+
|
1439
|
+
it 'should display correct color field in haml' do
|
1440
|
+
visit '/haml/form_for'
|
1441
|
+
assert_have_selector '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
|
1442
|
+
end
|
1443
|
+
|
1444
|
+
it 'should display correct color field in erb' do
|
1445
|
+
visit '/erb/form_for'
|
1446
|
+
assert_have_selector '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
|
1447
|
+
end
|
1448
|
+
|
1449
|
+
it 'should display correct color field in slim' do
|
1450
|
+
visit '/slim/form_for'
|
1451
|
+
assert_have_selector '#demo input[type=color]', :id => 'markup_user_color', :value => "#ff0000"
|
1452
|
+
end
|
1453
|
+
end
|
1216
1454
|
end
|
data/test/test_form_helpers.rb
CHANGED
@@ -1053,4 +1053,302 @@ describe "FormHelpers" do
|
|
1053
1053
|
assert_have_selector 'input', :type => 'range', :name => 'ranger_with_range', :min => '1', :max => '5', :count => 1
|
1054
1054
|
end
|
1055
1055
|
end
|
1056
|
+
|
1057
|
+
describe 'for #datetime_field_tag' do
|
1058
|
+
before do
|
1059
|
+
@expected = {
|
1060
|
+
:name => 'datetime',
|
1061
|
+
:max => "2000-04-01T12:00:00.000+0000",
|
1062
|
+
:min => "1993-02-24T12:30:45.000+0000",
|
1063
|
+
:value => "2000-04-01T12:00:00.000+0000"
|
1064
|
+
}
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
it 'should create an input tag with min and max and value options' do
|
1068
|
+
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1069
|
+
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1070
|
+
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1071
|
+
actual_html = datetime_field_tag('datetime', :max => max, :min => min, :value => value)
|
1072
|
+
assert_has_tag('input', @expected) { actual_html }
|
1073
|
+
end
|
1074
|
+
|
1075
|
+
it 'should create an input tag with datetime' do
|
1076
|
+
actual_html = datetime_field_tag('datetime')
|
1077
|
+
assert_has_tag('input[type=datetime]') { actual_html }
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
it 'should create an input tag when the format string passed as datetime option value' do
|
1081
|
+
actual_html = datetime_field_tag('datetime', :value => '1993-02-24T12:30:45+00:00')
|
1082
|
+
assert_has_tag('input[type=datetime]', :value => "1993-02-24T12:30:45.000+0000") { actual_html }
|
1083
|
+
end
|
1084
|
+
|
1085
|
+
it 'should display correct datetime_field_tag in erb' do
|
1086
|
+
visit '/erb/form_tag'
|
1087
|
+
assert_have_selector 'input', @expected
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
it 'should display correct datetime_field_tag in haml' do
|
1091
|
+
visit '/haml/form_tag'
|
1092
|
+
assert_have_selector 'input', @expected
|
1093
|
+
end
|
1094
|
+
|
1095
|
+
it 'should display correct datetime_field_tag in slim' do
|
1096
|
+
visit '/slim/form_tag'
|
1097
|
+
assert_have_selector 'input', @expected
|
1098
|
+
end
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
describe 'for #datetime_local_field_tag' do
|
1102
|
+
before do
|
1103
|
+
@expected = {
|
1104
|
+
:name => 'datetime_local',
|
1105
|
+
:max => "2000-04-01T12:00:00",
|
1106
|
+
:min => "1993-02-24T12:30:45",
|
1107
|
+
:value => "2000-04-01T12:00:00"
|
1108
|
+
}
|
1109
|
+
end
|
1110
|
+
|
1111
|
+
it 'should create an input tag with min and max and value options' do
|
1112
|
+
max = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1113
|
+
min = DateTime.new(1993, 2, 24, 12, 30, 45)
|
1114
|
+
value = DateTime.new(2000, 4, 1, 12, 0, 0)
|
1115
|
+
actual_html = datetime_local_field_tag('datetime_local', :max => max, :min => min, :value => value)
|
1116
|
+
assert_has_tag('input', @expected) { actual_html }
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
it 'should create an input tag with datetime-local' do
|
1120
|
+
actual_html = datetime_local_field_tag('datetime_local')
|
1121
|
+
assert_has_tag('input[type="datetime-local"]') { actual_html }
|
1122
|
+
end
|
1123
|
+
|
1124
|
+
it 'should create an input tag when the format string passed as datetime-local option value' do
|
1125
|
+
actual_html = datetime_local_field_tag('datetime_local', :value => '1993-02-24T12:30:45')
|
1126
|
+
assert_has_tag('input[type="datetime-local"]', :value => "1993-02-24T12:30:45") { actual_html }
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
it 'should display correct datetime_local_field_tag in erb' do
|
1130
|
+
visit '/erb/form_tag'
|
1131
|
+
assert_have_selector 'input', @expected
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
it 'should display correct datetime_local_field_tag in haml' do
|
1135
|
+
visit '/haml/form_tag'
|
1136
|
+
assert_have_selector 'input', @expected
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
it 'should display correct datetime_local_field_tag in slim' do
|
1140
|
+
visit '/slim/form_tag'
|
1141
|
+
assert_have_selector 'input', @expected
|
1142
|
+
end
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
describe 'for #date_field_tag' do
|
1146
|
+
before do
|
1147
|
+
@expected = {
|
1148
|
+
:name => 'date',
|
1149
|
+
:max => "2000-04-01",
|
1150
|
+
:min => "1993-02-24",
|
1151
|
+
:value => "2000-04-01"
|
1152
|
+
}
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
it 'should create an input tag with min and max and value options' do
|
1156
|
+
max = DateTime.new(2000, 4, 1)
|
1157
|
+
min = DateTime.new(1993, 2, 24)
|
1158
|
+
value = DateTime.new(2000, 4, 1)
|
1159
|
+
actual_html = date_field_tag('date', :max => max, :min => min, :value => value)
|
1160
|
+
assert_has_tag('input', @expected) { actual_html }
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
it 'should create an input tag with date' do
|
1164
|
+
actual_html = date_field_tag('date')
|
1165
|
+
assert_has_tag('input[type="date"]') { actual_html }
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
it 'should create an input tag when the format string passed as date option value' do
|
1169
|
+
actual_html = date_field_tag('date', :value => '1993-02-24')
|
1170
|
+
assert_has_tag('input[type="date"]', :value => "1993-02-24") { actual_html }
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
it 'should display correct date_field_tag in erb' do
|
1174
|
+
visit '/erb/form_tag'
|
1175
|
+
assert_have_selector 'input', @expected
|
1176
|
+
end
|
1177
|
+
|
1178
|
+
it 'should display correct date_field_tag in haml' do
|
1179
|
+
visit '/haml/form_tag'
|
1180
|
+
assert_have_selector 'input', @expected
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
it 'should display correct date_field_tag in slim' do
|
1184
|
+
visit '/slim/form_tag'
|
1185
|
+
assert_have_selector 'input', @expected
|
1186
|
+
end
|
1187
|
+
end
|
1188
|
+
|
1189
|
+
describe 'for #month_field_tag' do
|
1190
|
+
before do
|
1191
|
+
@expected = {
|
1192
|
+
:name => 'month',
|
1193
|
+
:max => "2000-04",
|
1194
|
+
:min => "1993-02",
|
1195
|
+
:value => "2000-04"
|
1196
|
+
}
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
it 'should create an input tag with min and max and value options' do
|
1200
|
+
max = DateTime.new(2000, 4, 1)
|
1201
|
+
min = DateTime.new(1993, 2, 24)
|
1202
|
+
value = DateTime.new(2000, 4, 1)
|
1203
|
+
actual_html = month_field_tag('month', :max => max, :min => min, :value => value)
|
1204
|
+
assert_has_tag('input', @expected) { actual_html }
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
it 'should create an input tag with month' do
|
1208
|
+
actual_html = month_field_tag('month')
|
1209
|
+
assert_has_tag('input[type="month"]') { actual_html }
|
1210
|
+
end
|
1211
|
+
|
1212
|
+
it 'should create an input tag when the format string passed as month option value' do
|
1213
|
+
actual_html = month_field_tag('month', :value => '1993-02-24')
|
1214
|
+
assert_has_tag('input[type="month"]', :value => "1993-02") { actual_html }
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
it 'should display correct month_field_tag in erb' do
|
1218
|
+
visit '/erb/form_tag'
|
1219
|
+
assert_have_selector 'input', @expected
|
1220
|
+
end
|
1221
|
+
|
1222
|
+
it 'should display correct month_field_tag in haml' do
|
1223
|
+
visit '/haml/form_tag'
|
1224
|
+
assert_have_selector 'input', @expected
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
it 'should display correct month_field_tag in slim' do
|
1228
|
+
visit '/slim/form_tag'
|
1229
|
+
assert_have_selector 'input', @expected
|
1230
|
+
end
|
1231
|
+
end
|
1232
|
+
|
1233
|
+
describe 'for #week_field_tag' do
|
1234
|
+
before do
|
1235
|
+
@expected = {
|
1236
|
+
:name => 'week',
|
1237
|
+
:max => "2000-W13",
|
1238
|
+
:min => "1993-W08",
|
1239
|
+
:value => "2000-W13"
|
1240
|
+
}
|
1241
|
+
end
|
1242
|
+
|
1243
|
+
it 'should create an input tag with min and max and value options' do
|
1244
|
+
max = DateTime.new(2000, 4, 1)
|
1245
|
+
min = DateTime.new(1993, 2, 24)
|
1246
|
+
value = DateTime.new(2000, 4, 1)
|
1247
|
+
actual_html = week_field_tag('week', :max => max, :min => min, :value => value)
|
1248
|
+
assert_has_tag('input', @expected) { actual_html }
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
it 'should create an input tag with week' do
|
1252
|
+
actual_html = week_field_tag('week')
|
1253
|
+
assert_has_tag('input[type="week"]') { actual_html }
|
1254
|
+
end
|
1255
|
+
|
1256
|
+
it 'should create an input tag when the format string passed as week option value' do
|
1257
|
+
actual_html = week_field_tag('week', :value => '1993-02-24')
|
1258
|
+
assert_has_tag('input[type="week"]', :value => "1993-W08") { actual_html }
|
1259
|
+
end
|
1260
|
+
|
1261
|
+
it 'should display correct week_field_tag in erb' do
|
1262
|
+
visit '/erb/form_tag'
|
1263
|
+
assert_have_selector 'input', @expected
|
1264
|
+
end
|
1265
|
+
|
1266
|
+
it 'should display correct week_field_tag in haml' do
|
1267
|
+
visit '/haml/form_tag'
|
1268
|
+
assert_have_selector 'input', @expected
|
1269
|
+
end
|
1270
|
+
|
1271
|
+
it 'should display correct week_field_tag in slim' do
|
1272
|
+
visit '/slim/form_tag'
|
1273
|
+
assert_have_selector 'input', @expected
|
1274
|
+
end
|
1275
|
+
end
|
1276
|
+
|
1277
|
+
describe 'for #time_field_tag' do
|
1278
|
+
before do
|
1279
|
+
@expected = {
|
1280
|
+
:name => 'time',
|
1281
|
+
:max => "13:30:00.000",
|
1282
|
+
:min => "01:19:12.000",
|
1283
|
+
:value => "13:30:00.000"
|
1284
|
+
}
|
1285
|
+
end
|
1286
|
+
|
1287
|
+
it 'should create an input tag with min and max and value options' do
|
1288
|
+
max = Time.new(2008, 6, 21, 13, 30, 0)
|
1289
|
+
min = Time.new(1993, 2, 24, 1, 19, 12)
|
1290
|
+
value = Time.new(2008, 6, 21, 13, 30, 0)
|
1291
|
+
actual_html = time_field_tag('time', :max => max, :min => min, :value => value)
|
1292
|
+
assert_has_tag('input', @expected) { actual_html }
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
it 'should create an input tag with time' do
|
1296
|
+
actual_html = time_field_tag('time')
|
1297
|
+
assert_has_tag('input[type="time"]') { actual_html }
|
1298
|
+
end
|
1299
|
+
|
1300
|
+
it 'should create an input tag when the format string passed as time option value' do
|
1301
|
+
actual_html = time_field_tag('time', :value => '1993-02-24 01:19:12')
|
1302
|
+
assert_has_tag('input[type="time"]', :value => "01:19:12.000") { actual_html }
|
1303
|
+
end
|
1304
|
+
|
1305
|
+
it 'should display correct time_field_tag in erb' do
|
1306
|
+
visit '/erb/form_tag'
|
1307
|
+
assert_have_selector 'input', @expected
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
it 'should display correct time_field_tag in haml' do
|
1311
|
+
visit '/haml/form_tag'
|
1312
|
+
assert_have_selector 'input', @expected
|
1313
|
+
end
|
1314
|
+
|
1315
|
+
it 'should display correct time_field_tag in slim' do
|
1316
|
+
visit '/slim/form_tag'
|
1317
|
+
assert_have_selector 'input', @expected
|
1318
|
+
end
|
1319
|
+
end
|
1320
|
+
|
1321
|
+
describe 'for #color_field_tag' do
|
1322
|
+
before do
|
1323
|
+
@expected = {
|
1324
|
+
:name => 'color',
|
1325
|
+
:value => '#ff0000'
|
1326
|
+
}
|
1327
|
+
end
|
1328
|
+
|
1329
|
+
it 'should create an input tag with value option' do
|
1330
|
+
actual_html = color_field_tag('color', :value => "#ff0000")
|
1331
|
+
assert_has_tag('input[type="color"]', @expected) { actual_html }
|
1332
|
+
end
|
1333
|
+
|
1334
|
+
it 'should create an input tag with short color code' do
|
1335
|
+
actual_html = color_field_tag('color', :value => "#f00")
|
1336
|
+
assert_has_tag('input[type="color"]', @expected) { actual_html }
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
it 'should display correct color_field_tag in erb' do
|
1340
|
+
visit '/erb/form_tag'
|
1341
|
+
assert_have_selector 'input', @expected
|
1342
|
+
end
|
1343
|
+
|
1344
|
+
it 'should display correct color_field_tag in haml' do
|
1345
|
+
visit '/haml/form_tag'
|
1346
|
+
assert_have_selector 'input', @expected
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
it 'should display correct color_field_tag in slim' do
|
1350
|
+
visit '/slim/form_tag'
|
1351
|
+
assert_have_selector 'input', @expected
|
1352
|
+
end
|
1353
|
+
end
|
1056
1354
|
end
|
data/test/test_rendering.rb
CHANGED
@@ -116,6 +116,20 @@ describe "Rendering" do
|
|
116
116
|
assert_equal "html file", body
|
117
117
|
end
|
118
118
|
|
119
|
+
it 'should find proper templates when content_type is set by string' do
|
120
|
+
create_layout :error, "layout<%= yield %>"
|
121
|
+
create_view :e404, "404 file"
|
122
|
+
|
123
|
+
mock_app do
|
124
|
+
not_found do
|
125
|
+
content_type 'text/html'
|
126
|
+
render 'e404', :layout => :error
|
127
|
+
end
|
128
|
+
end
|
129
|
+
get '/missing'
|
130
|
+
assert_equal 'layout404 file', body
|
131
|
+
end
|
132
|
+
|
119
133
|
it 'should not use html file when DEFAULT_RENDERING_OPTIONS[:strict_format] == true' do
|
120
134
|
create_layout :foo, "html file", :format => :html
|
121
135
|
|
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.13.0.
|
4
|
+
version: 0.13.0.beta3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-08-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-support
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.13.0.
|
22
|
+
version: 0.13.0.beta3
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.13.0.
|
29
|
+
version: 0.13.0.beta3
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: tilt
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|