forme 1.6.0 → 1.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 617e4bb020afdaf14cb5a13ec71c57bc0c33f173
4
- data.tar.gz: 05ee61e281799560dd9c9eb84911a11bf9ca0c0c
2
+ SHA256:
3
+ metadata.gz: 4c126daca3403b2140b2059d04c6ef405a11f8d56418ce4e971025ee8f861ec2
4
+ data.tar.gz: 347c183344c4fe77f42753d0ec0515ce11065e648a9d37d14665b7d10fb090ed
5
5
  SHA512:
6
- metadata.gz: 90d0384542f59034b2428aeff330e0e9379b9c732877bbfa22d8be3be4cbeb89a24c635495ab638423ca2126dc7cea89ca07c74e4eea49193cd770fe521d67e5
7
- data.tar.gz: 6aab3b04c4658e2c104f056104d5e2480580f51b1328e9540bc52b9c6ab0c9941b0bf7bfe5ddb9051b6d501e1bad7b8a6c5b115133caba05b689b28dbee1eb0c
6
+ metadata.gz: 220b3e73af81b0db1f4187ba2f65505b775780ff8b9459d3b95f139d5160fcaa3eacf5e2172b5f9e883c7f7fc9bf7b4bb23ef05b54abbf815fe2d481844a5038
7
+ data.tar.gz: 5742f5edf32047920fb23f73bdd86a3c29823d1c2f9b0834718a304d157cabea627767448c534e9b2a0e21c0ab78dbb240c66692706bb68c59e84c1a9c618c2a
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ === 1.7.0 (2018-02-07)
2
+
3
+ * Have radioset and checkboxset inputs respect :error_attr option (jeremyevans)
4
+
5
+ * Add :tag_labeler option for checkboxsets and radiosets for the labeler to use for individual elements (jeremyevans)
6
+
7
+ * Use milliseconds instead of microseconds for serializing Time and DateTime values, since that's what datetime-local inputs support (jeremyevans)
8
+
1
9
  === 1.6.0 (2017-05-03)
2
10
 
3
11
  * Use thead/tbody tags for table inputs_wrapper transformer and Sequel plugin subform :grid option (jeremyevans)
@@ -813,12 +813,16 @@ Creates a select tag, containing option tags specified by the :options option.
813
813
  === :checkboxset
814
814
 
815
815
  Creates a set of checkbox inputs all using the same name. Supports the same options
816
- as the select type, except that the :multiple option is assumed to be true.
816
+ as the select type, except that the :multiple option is assumed to be true. Also supports
817
+ the following options:
818
+
819
+ :tag_wrapper :: The wrapper transformer for individual tags in the set
820
+ :tag_labeler :: The labeler transformer for individual tags in the set
817
821
 
818
822
  === :radioset
819
823
 
820
824
  Creates a set of radio buttons all using the same name. Supports the same options
821
- as the select type.
825
+ as the :checkboxset type.
822
826
 
823
827
  === :textarea
824
828
 
@@ -229,6 +229,7 @@ module Forme
229
229
  end
230
230
 
231
231
  tag_wrapper = Forme.transformer(:tag_wrapper, @opts.delete(:tag_wrapper), @input.form_opts) || :default
232
+ tag_labeler = Forme.transformer(:labeler, @opts.delete(:tag_labeler), @input.form_opts) || :default
232
233
  wrapper = @opts.fetch(:wrapper){@opts[:wrapper] = @input.form_opts[:set_wrapper] || @input.form_opts[:wrapper]}
233
234
  wrapper = Forme.transformer(:wrapper, wrapper)
234
235
 
@@ -236,7 +237,7 @@ module Forme
236
237
  value ||= label
237
238
  label_attr = {:class=>:option}
238
239
  label_attr.merge!(@opts[:label_attr]) if @opts[:label_attr]
239
- r_opts = attrs.merge(tag_attrs).merge(:label=>label||value, :label_attr=>label_attr, :wrapper=>tag_wrapper)
240
+ r_opts = attrs.merge(tag_attrs).merge(:label=>label||value, :label_attr=>label_attr, :wrapper=>tag_wrapper, :labeler=>tag_labeler)
240
241
  r_opts[:value] ||= value if value
241
242
  r_opts[:checked] ||= :checked if sel
242
243
  r_opts[:formatter] = @opts[:formatter] if @opts[:formatter]
@@ -256,7 +257,7 @@ module Forme
256
257
  end
257
258
 
258
259
  if @opts[:set_error]
259
- _add_set_error(tags)
260
+ _add_set_error(tags)
260
261
  end
261
262
 
262
263
  tags.unshift(set_label) if @opts[:set_label]
@@ -271,8 +272,11 @@ module Forme
271
272
  def _add_set_error(tags)
272
273
  if (last_input = tags.last) && last_input.is_a?(Input)
273
274
  last_input.opts[:error] = @opts[:set_error]
275
+ last_input.opts[:error_attr] = @opts[:error_attr] if @opts[:error_attr]
274
276
  else
275
- tags << form._tag(:span, {:class=>'error_message'}, [@opts[:set_error]])
277
+ attr = @opts[:error_attr] || {}
278
+ Forme.attr_classes(attr, 'error_message')
279
+ tags << form._tag(:span, attr, [@opts[:set_error]])
276
280
  end
277
281
  end
278
282
 
@@ -66,7 +66,7 @@ module Forme
66
66
 
67
67
  # Return a string in ISO format representing the +Time+ or +DateTime+ instance.
68
68
  def format_time(time)
69
- time.is_a?(Time) ? (time.strftime('%Y-%m-%dT%H:%M:%S') + sprintf(".%06d", time.usec)) : (time.strftime('%Y-%m-%dT%H:%M:%S.') + time.strftime('%N')[0...6])
69
+ time.is_a?(Time) ? (time.strftime('%Y-%m-%dT%H:%M:%S') + sprintf(".%03d", time.usec)) : (time.strftime('%Y-%m-%dT%H:%M:%S.') + time.strftime('%N')[0...3])
70
70
  end
71
71
 
72
72
  # Escape ampersands, brackets and quotes to their HTML/XML entities.
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Forme
4
4
  # Version constant, use <tt>Forme.version</tt> instead.
5
- VERSION = '1.6.0'.freeze
5
+ VERSION = '1.7.0'.freeze
6
6
 
7
7
  # Returns the version as a frozen string (e.g. '0.1.0')
8
8
  def self.version
@@ -54,12 +54,12 @@ describe "Forme Sequel::Model BS3 forms" do
54
54
  end
55
55
 
56
56
  it "should use datetime inputs for Time" do
57
- @b.input(:created_at).to_s.must_match %r{<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album\[created_at\]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></div>}
57
+ @b.input(:created_at).to_s.must_match %r{<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album\[created_at\]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>}
58
58
  end
59
59
 
60
60
  it "should use datetime inputs for DateTimes" do
61
61
  @ab.values[:created_at] = DateTime.new(2011, 6, 5)
62
- @b.input(:created_at).to_s.must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></div>'
62
+ @b.input(:created_at).to_s.must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>'
63
63
  end
64
64
 
65
65
  it "should include type as wrapper class" do
@@ -67,7 +67,7 @@ describe "Forme Sequel::Model BS3 forms" do
67
67
  f = Forme::Form.new(@ab, :config=>:bs3)
68
68
  f.input(:name).to_s.must_equal '<div class="form-group string"><label for="album_name">Name</label> <input class="form-control" id="album_name" name="album[name]" type="text" value="b"/></div>'
69
69
  f.input(:release_date).to_s.must_equal '<div class="date form-group"><label for="album_release_date">Release date</label> <input class="form-control" id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></div>'
70
- f.input(:created_at).to_s.must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></div>'
70
+ f.input(:created_at).to_s.must_equal '<div class="datetime form-group"><label for="album_created_at">Created at</label> <input class="form-control" id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></div>'
71
71
  end
72
72
 
73
73
  it "should include required * in label if required" do
@@ -599,8 +599,8 @@ describe "Forme Bootstrap3 (BS3) forms" do
599
599
 
600
600
  it "should format dates, times, and datetimes in ISO format" do
601
601
  @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
602
- @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
603
- @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
602
+ @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
603
+ @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
604
604
  end
605
605
 
606
606
  it "should format bigdecimals in standard notation" do
@@ -404,6 +404,10 @@ describe "Forme plain forms" do
404
404
  @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :label_attr=>{:foo=>:bar}).to_s.must_equal '<label class="option" foo="bar"><input type="radio" value="1"/> 1</label><label class="option" foo="bar"><input checked="checked" type="radio" value="2"/> 2</label><label class="option" foo="bar"><input type="radio" value="3"/> 3</label>'
405
405
  end
406
406
 
407
+ it "should create set of radio buttons with :error and :error_attr options" do
408
+ @f.input(:radioset, :options=>[1, 2, 3], :selected=>2, :error=>'foo', :error_attr=>{'bar'=>'baz'}).to_s.must_equal '<label class="option"><input type="radio" value="1"/> 1</label><label class="option"><input checked="checked" type="radio" value="2"/> 2</label><label class="option"><input class="error" type="radio" value="3"/> 3</label><span bar="baz" class="error_message">foo</span>'
409
+ end
410
+
407
411
  it "should create set of checkbox buttons" do
408
412
  @f.input(:checkboxset, :options=>[1, 2, 3], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
409
413
  @f.input(:checkboxset, :options=>[1, 2, 3], :value=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> 1</label><label class="option"><input checked="checked" type="checkbox" value="2"/> 2</label><label class="option"><input type="checkbox" value="3"/> 3</label>'
@@ -413,6 +417,18 @@ describe "Forme plain forms" do
413
417
  @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :selected=>2).to_s.must_equal '<label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input checked="checked" type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
414
418
  end
415
419
 
420
+ it "should support :wrapper and :tag_wrapper for checkboxsets" do
421
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_wrapper=>:div, :wrapper=>:li).to_s.must_equal '<li><div><label class="option"><input type="checkbox" value="1"/> a</label></div><div><label class="option"><input type="checkbox" value="2"/> b</label></div><div><label class="option"><input type="checkbox" value="3"/> c</label></div></li>'
422
+ end
423
+
424
+ it "should support :label for checkboxsets" do
425
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :label=>'foo').to_s.must_equal '<span class="label">foo</span><label class="option"><input type="checkbox" value="1"/> a</label><label class="option"><input type="checkbox" value="2"/> b</label><label class="option"><input type="checkbox" value="3"/> c</label>'
426
+ end
427
+
428
+ it "should support :tag_labeler for checkboxsets" do
429
+ @f.input(:checkboxset, :options=>[[:a, 1], [:b, 2], [:c, 3]], :tag_labeler=>:explicit).to_s.must_equal '<input type="checkbox" value="1"/><label class="option label-after">a</label><input type="checkbox" value="2"/><label class="option label-after">b</label><input type="checkbox" value="3"/><label class="option label-after">c</label>'
430
+ end
431
+
416
432
  it "should create set of checkbox buttons with options and values with hashes" do
417
433
  @f.input(:checkboxset, :options=>[[:a, {:attr=>{:foo=>1}}], [:b, {:class=>'foo', :value=>2}], [:c, {:id=>:baz}]], :selected=>2).to_s.must_equal '<label class="option"><input foo="1" type="checkbox" value="a"/> a</label><label class="option"><input checked="checked" class="foo" type="checkbox" value="2"/> b</label><label class="option"><input id="baz" type="checkbox" value="c"/> c</label>'
418
434
  end
@@ -623,8 +639,8 @@ describe "Forme plain forms" do
623
639
 
624
640
  it "should format dates, times, and datetimes in ISO format" do
625
641
  @f.tag(:div, :foo=>Date.new(2011, 6, 5)).to_s.must_equal '<div foo="2011-06-05"></div>'
626
- @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
627
- @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000000"></div>'
642
+ @f.tag(:div, :foo=>DateTime.new(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
643
+ @f.tag(:div, :foo=>Time.utc(2011, 6, 5, 4, 3, 2)).to_s.must_equal '<div foo="2011-06-05T04:03:02.000"></div>'
628
644
  end
629
645
 
630
646
  it "should format bigdecimals in standard notation" do
@@ -50,6 +50,18 @@ t = DB[:tags].insert(:name=>'t')
50
50
  DB[:tags].insert(:name=>'u')
51
51
  [[b, s], [b, t], [c, t]].each{|k, v| DB[:albums_tags].insert(k, v)}
52
52
 
53
+ # Allow loading of pg_array extension even when not on PostgreSQL
54
+ def DB.add_conversion_proc(*)
55
+ super if defined?(super)
56
+ end
57
+ def DB.conversion_procs_updated(*)
58
+ super if defined?(super)
59
+ end
60
+ def DB.conversion_procs
61
+ return super if defined?(super)
62
+ {}
63
+ end
64
+
53
65
  Sequel::Model.plugin :forme
54
66
  class Album < Sequel::Model
55
67
  plugin :association_pks
@@ -53,12 +53,12 @@ describe "Forme Sequel::Model forms" do
53
53
  end
54
54
 
55
55
  it "should use datetime inputs for Time" do
56
- @b.input(:created_at).to_s.must_match %r{<label>Created at: <input id="album_created_at" name="album\[created_at\]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></label>}
56
+ @b.input(:created_at).to_s.must_match %r{<label>Created at: <input id="album_created_at" name="album\[created_at\]" type="datetime-local" value="2011-06-05T00:00:00.000"/></label>}
57
57
  end
58
58
 
59
59
  it "should use datetime inputs for DateTimes" do
60
60
  @ab.values[:created_at] = DateTime.new(2011, 6, 5)
61
- @b.input(:created_at).to_s.must_equal '<label>Created at: <input id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></label>'
61
+ @b.input(:created_at).to_s.must_equal '<label>Created at: <input id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></label>'
62
62
  end
63
63
 
64
64
  it "should include type as wrapper class" do
@@ -66,7 +66,7 @@ describe "Forme Sequel::Model forms" do
66
66
  f = Forme::Form.new(@ab, :wrapper=>:li)
67
67
  f.input(:name).to_s.must_equal '<li class="string"><label>Name: <input id="album_name" name="album[name]" type="text" value="b"/></label></li>'
68
68
  f.input(:release_date).to_s.must_equal '<li class="date"><label>Release date: <input id="album_release_date" name="album[release_date]" type="date" value="2011-06-05"/></label></li>'
69
- f.input(:created_at).to_s.must_equal '<li class="datetime"><label>Created at: <input id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000000"/></label></li>'
69
+ f.input(:created_at).to_s.must_equal '<li class="datetime"><label>Created at: <input id="album_created_at" name="album[created_at]" type="datetime-local" value="2011-06-05T00:00:00.000"/></label></li>'
70
70
  end
71
71
 
72
72
  it "should include required * in label if required" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-03 00:00:00.000000000 Z
11
+ date: 2018-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  version: '0'
220
220
  requirements: []
221
221
  rubyforge_project:
222
- rubygems_version: 2.6.11
222
+ rubygems_version: 2.7.3
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: HTML forms library