forme 2.0.0 → 2.1.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
2
  SHA256:
3
- metadata.gz: c2d1410426de24535a3e1734c9b6e050c7125e6c5837a1d5a3e400021ba4b17e
4
- data.tar.gz: 4ce1754d622e0f87272257b70665fc2eb03c289f2ada6e9a54d444238b4a8095
3
+ metadata.gz: 16429cabb255a24eacd8d108a6c0d1ed771581148f5f344a876ceb1da4082a3f
4
+ data.tar.gz: 7fc3607cba35093e78bdfb3f6892bd94289c698b6d015e1a701303e5f5435b1a
5
5
  SHA512:
6
- metadata.gz: 69699bc0f28300df39222a596e7e201e972c969d5562f9af12f641ab6d011fab2576ba547407623c7e39476fd451ede30ef6728c51a15f7ce26a4d3aeb341467
7
- data.tar.gz: b12a69a0991e97fb665707bdc275b5329f26c7331d35292a315d54cfa45e3ed8a117cf64cea1d0e8df4493a080cc03782a3027111e339e4b08398200cf91b7ef
6
+ metadata.gz: e399a4c2aa701ee112c1c3ed4f95854611781929b5ebcdc7b0c925c703d80b79d5cb77c1b1427e60be98b47e6308aac3cb2a231895874696a8265502fced126a
7
+ data.tar.gz: 4397400180f4398ca5a553acf2b2845607952cfadfa8126ea88e473b161b8ac7e04589fcf89a62291b3e6218dbb6cf29d83825090c076d020181d3d1f2b05de7
data/CHANGELOG CHANGED
@@ -1,3 +1,13 @@
1
+ === 2.1.0 (2022-05-25)
2
+
3
+ * Avoid hidden inputs inside tbody tags in subform in the Sequel::Model support, since that results in invalid HTML (jeremyevans)
4
+
5
+ * Fix verbose warnings in forme/rails (jeremyevans)
6
+
7
+ * Remove deprecated forme/sinatra and Forme::Sinatra::ERB (jeremyevans)
8
+
9
+ * Remove deprecated Form :hidden_tags option (jeremyevans)
10
+
1
11
  === 2.0.0 (2021-11-30)
2
12
 
3
13
  * Remove Tag#<< method (jeremyevans)
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011-2021 Jeremy Evans
1
+ Copyright (c) 2011-2022 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to
data/README.rdoc CHANGED
@@ -73,7 +73,7 @@ following HTML instead:
73
73
  </fieldset>
74
74
  </form>
75
75
 
76
- This allows you to reuse the same form code in multiple context,
76
+ This allows you to reuse the same form code in multiple contexts,
77
77
  which can save considerable development time.
78
78
 
79
79
  = Installation
@@ -871,7 +871,7 @@ in your Rails forms:
871
871
  <% end %>
872
872
  <% end %>
873
873
 
874
- This has been tested on Rails 3.2-6.1.
874
+ This has been tested on Rails 3.2-7.0.
875
875
 
876
876
  = Input Types and Options
877
877
 
@@ -1096,7 +1096,7 @@ usually a +Tag+ instance). It is up to the +Formatter+ to call the +Labeler+,
1096
1096
 
1097
1097
  The Forme::Form object takes the transformers as options (:formatter,
1098
1098
  :labeler, :error_handler, :helper, :wrapper, and :serializer), all of which
1099
- should be objects responding to +call+ (so you can use +Proc+s) or be symbols
1099
+ should be objects responding to +call+ (so you can use <tt>Proc</tt>s) or be symbols
1100
1100
  registered with the library using <tt>Forme.register_transformer</tt>:
1101
1101
 
1102
1102
  Forme.register_transformer(:wrapper, :p) do |tag, input|
data/Rakefile CHANGED
@@ -50,7 +50,7 @@ end
50
50
 
51
51
  desc "Run specs"
52
52
  task :spec do
53
- sh "#{FileUtils::RUBY} spec/all.rb"
53
+ sh "#{FileUtils::RUBY} #{'-w' if RUBY_VERSION >= '3'} spec/all.rb"
54
54
  end
55
55
  task :default => :spec
56
56
 
@@ -60,12 +60,6 @@ task :spec_cov do
60
60
  sh "#{FileUtils::RUBY} spec/all.rb"
61
61
  end
62
62
 
63
- desc "Run specs with -w, some warnings filtered"
64
- task :spec_w do
65
- ENV['WARNING'] = '1'
66
- sh "#{FileUtils::RUBY} -w spec/all.rb"
67
- end
68
-
69
63
  ### Other
70
64
 
71
65
  desc "Print #{NAME} version"
data/lib/forme/erb.rb CHANGED
@@ -4,16 +4,6 @@ require_relative 'template'
4
4
 
5
5
  module Forme
6
6
  module ERB
7
- HIDDEN_TAGS = []
8
-
9
- # Add a hidden tag proc that will be used for all forms created via Forme::ERB::Helper#form.
10
- # The block is yielded the Forme::Tag object for the form tag.
11
- # The block should return either nil if hidden tag should be added, or a Forme::Tag object (or an array of them),
12
- # or a hash with keys specifying the name of the tags and the values specifying the values of the tags .
13
- def self.add_hidden_tag(&block)
14
- HIDDEN_TAGS << block
15
- end
16
-
17
7
  # This is the module used to add the Forme integration to ERB templates, with optional support for
18
8
  # rack_csrf for CSRF handling.
19
9
  module Helper
@@ -30,10 +20,6 @@ module Forme
30
20
  end
31
21
  end
32
22
  end
33
-
34
- def _forme_form_hidden_tags
35
- HIDDEN_TAGS
36
- end
37
23
  end
38
24
  end
39
25
  end
data/lib/forme/form.rb CHANGED
@@ -12,9 +12,6 @@ module Forme
12
12
  # input type keys and values that are hashes of input options.
13
13
  attr_reader :input_defaults
14
14
 
15
- # The hidden tags to automatically add to the form.
16
- attr_reader :hidden_tags
17
-
18
15
  # The attributes used for the form tag for this form.
19
16
  attr_reader :form_tag_attributes
20
17
 
@@ -109,12 +106,6 @@ module Forme
109
106
 
110
107
  @serializer = @opts[:serializer]
111
108
  @input_defaults = @opts[:input_defaults] || {}
112
- @hidden_tags = @opts[:hidden_tags]
113
- if @hidden_tags && !@hidden_tags.empty? && RUBY_VERSION >= '2'
114
- uplevel = 6
115
- uplevel += @opts[:hidden_tags_uplevel] if @opts[:hidden_tags_uplevel]
116
- warn("The Forme::Form :hidden_tags option is deprecated, please switch to using the :before option", :uplevel=>uplevel)
117
- end
118
109
  @to_s = String.new
119
110
  end
120
111
 
@@ -127,7 +118,7 @@ module Forme
127
118
  end
128
119
  @form_tag_attributes = attr
129
120
 
130
- tag(:form, attr, method(:hidden_form_tags)) do
121
+ tag(:form, attr) do
131
122
  before_form_yield
132
123
  yield self if block_given?
133
124
  after_form_yield
@@ -355,35 +346,6 @@ module Forme
355
346
  end
356
347
  end
357
348
 
358
- # Return array of hidden tags to use for this form,
359
- # or nil if the form does not have hidden tags added automatically.
360
- def hidden_form_tags(form_tag)
361
- if hidden_tags
362
- tags = []
363
- hidden_tags.each do |hidden_tag|
364
- hidden_tag = hidden_tag.call(form_tag) if hidden_tag.respond_to?(:call)
365
- tags.concat(parse_hidden_tags(hidden_tag))
366
- end
367
- tags
368
- end
369
- end
370
-
371
- # Handle various types of hidden tags for the form.
372
- def parse_hidden_tags(hidden_tag)
373
- case hidden_tag
374
- when Array
375
- hidden_tag
376
- when Tag, String
377
- [hidden_tag]
378
- when Hash
379
- hidden_tag.map{|k,v| _tag(:input, :type=>:hidden, :name=>k, :value=>v)}
380
- when nil
381
- []
382
- else
383
- raise Error, "unhandled hidden_tag response: #{hidden_tag.inspect}"
384
- end
385
- end
386
-
387
349
  # Return the HTML content added by the block.
388
350
  def content_added
389
351
  offset = @to_s.length
data/lib/forme/rails.rb CHANGED
@@ -8,16 +8,6 @@ end
8
8
 
9
9
  module Forme
10
10
  module Rails
11
- HIDDEN_TAGS = []
12
-
13
- # Add a hidden tag proc that will be used for all forms created via Forme::Rails::ERB#form.
14
- # The block is yielded the Forme::Tag object for the form tag.
15
- # The block should return either nil if hidden tag should be added, or a Forme::Tag object (or an array of them),
16
- # or a hash with keys specifying the name of the tags and the values specifying the values of the tags .
17
- def self.add_hidden_tag(&block)
18
- HIDDEN_TAGS << block
19
- end
20
-
21
11
  class TemplateForm < ::Forme::Template::Form
22
12
  %w'inputs tag subform'.each do |meth|
23
13
  class_eval(<<-END, __FILE__, __LINE__+1)
@@ -59,23 +49,20 @@ module Forme
59
49
 
60
50
  private
61
51
 
52
+ remove_method :_forme_form_options
62
53
  def _forme_form_options(obj, attr, opts)
63
54
  if protect_against_forgery?
64
55
  opts[:_before_post] = lambda do |form|
65
56
  form.tag(:input, :type=>:hidden, :name=>request_forgery_protection_token, :value=>form_authenticity_token)
66
57
  end
67
58
  end
68
- opts[:hidden_tags_uplevel] = 2
69
59
  end
70
60
 
61
+ remove_method :_forme_form_class
71
62
  # The class to use for forms
72
63
  def _forme_form_class
73
64
  TemplateForm
74
65
  end
75
-
76
- def _forme_form_hidden_tags
77
- Forme::Rails::HIDDEN_TAGS
78
- end
79
66
  end
80
67
  end
81
68
  end
@@ -102,16 +102,8 @@ module Forme
102
102
  end
103
103
 
104
104
  # The options to use for forms. Any changes should mutate this hash to set options.
105
+ # Does nothing by default.
105
106
  def _forme_form_options(obj, attr, opts)
106
- if hidden_tags = _forme_form_hidden_tags
107
- opts[:hidden_tags] ||= []
108
- opts[:hidden_tags] += hidden_tags
109
- end
110
- opts[:hidden_tags_uplevel] = 1
111
- end
112
-
113
- def _forme_form_hidden_tags
114
- nil
115
107
  end
116
108
  end
117
109
  end
data/lib/forme/version.rb CHANGED
@@ -6,7 +6,7 @@ module Forme
6
6
  MAJOR = 2
7
7
 
8
8
  # The minor version of Forme, updated for new feature releases of Forme.
9
- MINOR = 0
9
+ MINOR = 1
10
10
 
11
11
  # The patch version of Forme, updated only for bug fixes from the last
12
12
  # feature release.
@@ -49,11 +49,6 @@ class Roda
49
49
  def _forme_form_class
50
50
  Form
51
51
  end
52
-
53
- def _forme_form_options(obj, attr, opts)
54
- super
55
- opts[:hidden_tags_uplevel] = 2
56
- end
57
52
  end
58
53
  end
59
54
 
@@ -66,9 +66,12 @@ module Sequel # :nodoc:
66
66
  grid = opts[:grid]
67
67
  ns = "#{association}_attributes"
68
68
 
69
+ send(multiple ? :each_obj : :with_obj, nested_obj, ns) do |no, i|
70
+ input(ref.associated_class.primary_key, :type=>:hidden, :label=>nil, :wrapper=>nil) unless no.new? || opts[:skip_primary_key]
71
+ end
72
+
69
73
  contents = proc do
70
74
  send(multiple ? :each_obj : :with_obj, nested_obj, ns) do |no, i|
71
- input(ref.associated_class.primary_key, :type=>:hidden, :label=>nil, :wrapper=>nil) unless no.new? || opts[:skip_primary_key]
72
75
  options = opts.dup
73
76
  if grid
74
77
  options.delete(:legend)
@@ -390,19 +390,19 @@ describe "Forme Sequel::Model BS3 forms" do
390
390
  end
391
391
 
392
392
  it "should use allow nested forms with one_to_many associations" do
393
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
393
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
394
394
  end
395
395
 
396
396
  it "should support :obj option for *_to_many associations" do
397
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
397
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></div></fieldset></form>'
398
398
  end
399
399
 
400
400
  it "should auto number legends when using subform with inputs for *_to_many associations" do
401
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
401
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
402
402
  end
403
403
 
404
404
  it "should support callable :legend option when using subform with inputs for *_to_many associations" do
405
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track 0 (m)</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 1 (n)</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
405
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 0 (m)</legend><div class="form-group string"><label for="album_tracks_attributes_0_name">Name</label> <input class="form-control" id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track 1 (n)</legend><div class="form-group string"><label for="album_tracks_attributes_1_name">Name</label> <input class="form-control" id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></form>'
406
406
  end
407
407
 
408
408
  it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
@@ -411,7 +411,7 @@ describe "Forme Sequel::Model BS3 forms" do
411
411
  end
412
412
 
413
413
  it "should use allow nested forms with many_to_many associations" do
414
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
414
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #1</legend><div class="form-group string"><label for="album_tags_attributes_0_name">Name</label> <input class="form-control" id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></div></fieldset><fieldset class="inputs"><legend>Tag #2</legend><div class="form-group string"><label for="album_tags_attributes_1_name">Name</label> <input class="form-control" id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></div></fieldset></form>'
415
415
  end
416
416
 
417
417
  it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
@@ -420,23 +420,23 @@ describe "Forme Sequel::Model BS3 forms" do
420
420
  end
421
421
 
422
422
  it "should handle multiple nested levels" do
423
- Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></div><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_1_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
423
+ Forme.form(Artist[1], {},{:config=>:bs3}){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></div><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_0_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></div></fieldset><fieldset class="inputs"><legend>Track #2</legend><div class="form-group string"><label for="artist_albums_attributes_0_tracks_attributes_1_name">Name</label> <input class="form-control" id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></div></fieldset></fieldset></form>'
424
424
  end
425
425
 
426
426
  it "should have #subform :grid option create a grid" do
427
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
427
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
428
428
  end
429
429
 
430
430
  it "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
431
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
431
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
432
432
  end
433
433
 
434
434
  it "should have #subform :grid option handle :legend and :labels options" do
435
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
435
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
436
436
  end
437
437
 
438
438
  it "should have #subform :grid option handle :legend and :labels nil values" do
439
- Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
439
+ Forme.form(@ab, {},{:config=>:bs3}){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><tbody><tr><td class="string"><input class="form-control" id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
440
440
  end
441
441
 
442
442
  it "should have #subform :grid option handle :skip_primary_key option" do
data/spec/erb_helper.rb CHANGED
@@ -184,10 +184,6 @@ END
184
184
  END
185
185
  end
186
186
 
187
- r.get 'hidden_tags' do
188
- erb "<%= form([:foo, :bar], {:action=>'/baz'}, :hidden_tags=>[{'a'=>'b'}]) %>"
189
- end
190
-
191
187
  r.get 'noblock' do
192
188
  erb "<%= form([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') %>"
193
189
  end
@@ -184,10 +184,6 @@ END
184
184
  END
185
185
  end
186
186
 
187
- r.get 'hidden_tags' do
188
- erb "<%= form([:foo, :bar], {:action=>'/baz'}, :hidden_tags=>[{'a'=>'b'}]) %>"
189
- end
190
-
191
187
  r.get 'noblock' do
192
188
  erb "<%= form([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') %>"
193
189
  end
data/spec/forme_spec.rb CHANGED
@@ -821,36 +821,6 @@ describe "Forme plain forms" do
821
821
  end
822
822
  end
823
823
 
824
- describe "Forme::Form :hidden_tags option " do
825
- silence_warnings "should handle hash" do
826
- Forme.form({}, :hidden_tags=>[{:a=>'b'}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
827
- end
828
-
829
- silence_warnings "should handle array" do
830
- Forme.form({}, :hidden_tags=>[["a ", "b"]]).to_s.must_equal '<form>a b</form>'
831
- end
832
-
833
- silence_warnings "should handle string" do
834
- Forme.form({}, :hidden_tags=>["a "]).to_s.must_equal '<form>a </form>'
835
- end
836
-
837
- silence_warnings "should handle proc return hash" do
838
- Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]).to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
839
- end
840
-
841
- silence_warnings "should handle proc return hash when from takes a block" do
842
- Forme.form({}, :hidden_tags=>[lambda{|tag| {:a=>'b'}}]){}.to_s.must_equal '<form><input name="a" type="hidden" value="b"/></form>'
843
- end
844
-
845
- silence_warnings "should handle proc return tag" do
846
- Forme.form({:method=>'post'}, :hidden_tags=>[lambda{|tag| tag.tag(tag.attr[:method])}]).to_s.must_equal '<form method="post"><post></post></form>'
847
- end
848
-
849
- silence_warnings "should raise error for unhandled object" do
850
- proc{Forme.form({}, :hidden_tags=>[Object.new])}.must_raise Forme::Error
851
- end
852
- end
853
-
854
824
  describe "Forme custom" do
855
825
  it "formatters can be specified as a proc" do
856
826
  Forme::Form.new(:formatter=>proc{|i| i.tag(:textarea, i.opts[:name]=>:name)}).input(:text, :name=>'foo').to_s.must_equal '<textarea foo="name"></textarea>'
@@ -23,7 +23,7 @@ begin
23
23
 
24
24
  class FormeRails < Rails::Application
25
25
  routes.append do
26
- %w'index inputs_block inputs_block_wrapper nest nest_sep nest_inputs nest_seq hash legend combined hidden_tags noblock noblock_post safe_buffer'.each do |action|
26
+ %w'index inputs_block inputs_block_wrapper nest nest_sep nest_inputs nest_seq hash legend combined noblock noblock_post safe_buffer'.each do |action|
27
27
  get action, :controller=>'forme', :action=>action
28
28
  end
29
29
  end
@@ -192,10 +192,6 @@ END
192
192
  END
193
193
  end
194
194
 
195
- def hidden_tags
196
- render :inline => "<%= forme([:foo, :bar], {:action=>'/baz'}, :hidden_tags=>[{'a'=>'b'}]) %>"
197
- end
198
-
199
195
  def noblock
200
196
  render :inline => "<%= forme([:foo, :bar], {:action=>'/baz'}, :inputs=>[:first], :button=>'xyz', :legend=>'123') %>"
201
197
  end
@@ -267,10 +263,6 @@ describe "Forme Rails integration" do
267
263
  sin_get('/combined').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset> <p>FBB</p> <input id="last" name="last" type="text" value="bar"/> <input type="submit" value="xyz"/></form>'
268
264
  end
269
265
 
270
- silence_warnings "#form should support :hidden_tags option" do
271
- sin_get('/hidden_tags').must_equal '<form action="/baz"><input name="a" type="hidden" value="b"/></form>'
272
- end
273
-
274
266
  it "#form should work without a block" do
275
267
  sin_get('/noblock').must_equal '<form action="/baz"><fieldset class="inputs"><legend>123</legend><input id="first" name="first" type="text" value="foo"/></fieldset><input type="submit" value="xyz"/></form>'
276
268
  end
@@ -44,9 +44,6 @@ def FormeRodaTest(block=ERB_BLOCK)
44
44
  r.get 'use_request_specific_token', :use do |use|
45
45
  render :inline=>"[#{Base64.strict_encode64(send(:csrf_secret))}]<%= form({:method=>:post}, {:use_request_specific_token=>#{use == '1'}}) %>"
46
46
  end
47
- r.get 'hidden_tags2' do |use|
48
- render :inline=>"<%= form({:method=>:post}, {:hidden_tags=>[{:foo=>'bar'}]}) %>"
49
- end
50
47
  r.get 'csrf', :use do |use|
51
48
  render :inline=>"<%= form({:method=>:post}, {:csrf=>#{use == '1'}}) %>"
52
49
  end
@@ -105,10 +102,6 @@ module FormeRouteCsrfSpecs
105
102
  app.new({'SCRIPT_NAME'=>'', 'PATH_INFO'=>'/use_request_specific_token/0', 'REQUEST_METHOD'=>'POST', 'rack.session'=>{'_roda_csrf_secret'=>secret}, 'rack.input'=>StringIO.new}).valid_csrf?(:token=>token).must_equal(plugin_opts.empty? ? false : true)
106
103
  end
107
104
 
108
- silence_warnings "should include :hidden_tags option" do
109
- sin_get('/hidden_tags2').must_include 'name="foo" type="hidden" value="bar"'
110
- end
111
-
112
105
  it "should handle the :csrf option" do
113
106
  sin_get('/csrf/1').must_include '<input name="_csrf" type="hidden" value="'
114
107
  sin_get('/csrf/0').wont_include '<input name="_csrf" type="hidden" value="'
@@ -226,7 +219,7 @@ END
226
219
  end
227
220
 
228
221
  body = @app.call('REQUEST_METHOD'=>'GET')[2].join.gsub("\n", ' ').gsub(/ +/, ' ').chomp(' ')
229
- body.sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
222
+ body.sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
230
223
  end
231
224
 
232
225
  it "#forme_set should include HMAC values if form includes inputs for obj" do
@@ -414,19 +414,19 @@ describe "Forme Sequel::Model forms" do
414
414
  end
415
415
 
416
416
  it "should use allow nested forms with one_to_many associations" do
417
- Forme.form(@ab){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
417
+ Forme.form(@ab){|f| f.subform(:tracks){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
418
418
  end
419
419
 
420
420
  it "should support :obj option for *_to_many associations" do
421
- Forme.form(@ab){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></label></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></label></fieldset></form>'
421
+ Forme.form(@ab){|f| f.subform(:tracks, :obj=>[Track.new(:name=>'x'), Track.load(:id=>5, :name=>'y')]){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="5"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="x"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="y"/></label></fieldset></form>'
422
422
  end
423
423
 
424
424
  it "should auto number legends when using subform with inputs for *_to_many associations" do
425
- Forme.form(@ab){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
425
+ Forme.form(@ab){|f| f.subform(:tracks, :inputs=>[:name])}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
426
426
  end
427
427
 
428
428
  it "should support callable :legend option when using subform with inputs for *_to_many associations" do
429
- Forme.form(@ab){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track 0 (m)</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 1 (n)</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
429
+ Forme.form(@ab){|f| f.subform(:tracks, :inputs=>[:name], :legend=>proc{|o, i| "Track #{i} (#{o.name})"})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tracks_attributes_0_id" name="album[tracks_attributes][0][id]" type="hidden" value="1"/><input id="album_tracks_attributes_1_id" name="album[tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track 0 (m)</legend><label>Name: <input id="album_tracks_attributes_0_name" maxlength="255" name="album[tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track 1 (n)</legend><label>Name: <input id="album_tracks_attributes_1_name" maxlength="255" name="album[tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></form>'
430
430
  end
431
431
 
432
432
  it "should not add hidden primary key field for nested forms with one_to_many associations with new objects" do
@@ -435,7 +435,7 @@ describe "Forme Sequel::Model forms" do
435
435
  end
436
436
 
437
437
  it "should use allow nested forms with many_to_many associations" do
438
- Forme.form(@ab){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Tag #1</legend><label>Name: <input id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></label></fieldset><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #2</legend><label>Name: <input id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
438
+ Forme.form(@ab){|f| f.subform(:tags){f.input(:name)}}.to_s.must_equal '<form class="forme album" method="post"><input id="album_tags_attributes_0_id" name="album[tags_attributes][0][id]" type="hidden" value="1"/><input id="album_tags_attributes_1_id" name="album[tags_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Tag #1</legend><label>Name: <input id="album_tags_attributes_0_name" maxlength="255" name="album[tags_attributes][0][name]" type="text" value="s"/></label></fieldset><fieldset class="inputs"><legend>Tag #2</legend><label>Name: <input id="album_tags_attributes_1_name" maxlength="255" name="album[tags_attributes][1][name]" type="text" value="t"/></label></fieldset></form>'
439
439
  end
440
440
 
441
441
  it "should not add hidden primary key field for nested forms with many_to_many associations with new objects" do
@@ -444,23 +444,23 @@ describe "Forme Sequel::Model forms" do
444
444
  end
445
445
 
446
446
  it "should handle multiple nested levels" do
447
- Forme.form(Artist[1]){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><label>Name: <input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></label><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></fieldset></form>'
447
+ Forme.form(Artist[1]){|f| f.subform(:albums){f.input(:name); f.subform(:tracks){f.input(:name)}}}.to_s.to_s.must_equal '<form class="forme artist" method="post"><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><fieldset class="inputs"><legend>Album #1</legend><label>Name: <input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="b"/></label><input id="artist_albums_attributes_0_tracks_attributes_0_id" name="artist[albums_attributes][0][tracks_attributes][0][id]" type="hidden" value="1"/><input id="artist_albums_attributes_0_tracks_attributes_1_id" name="artist[albums_attributes][0][tracks_attributes][1][id]" type="hidden" value="2"/><fieldset class="inputs"><legend>Track #1</legend><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][0][name]" type="text" value="m"/></label></fieldset><fieldset class="inputs"><legend>Track #2</legend><label>Name: <input id="artist_albums_attributes_0_tracks_attributes_1_name" maxlength="255" name="artist[albums_attributes][0][tracks_attributes][1][name]" type="text" value="n"/></label></fieldset></fieldset></form>'
448
448
  end
449
449
 
450
450
  it "should have #subform :grid option create a grid" do
451
- Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
451
+ Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true)}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
452
452
  end
453
453
 
454
454
  it "should have #subform :grid option respect :inputs_opts option to pass options to inputs" do
455
- Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
455
+ Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :inputs_opts=>{:attr=>{:class=>'foo'}})}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table class="foo"><caption>Artist</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
456
456
  end
457
457
 
458
458
  it "should have #subform :grid option handle :legend and :labels options" do
459
- Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
459
+ Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>'Foo', :labels=>%w'Bar')}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><caption>Foo</caption><thead><tr><th>Bar</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
460
460
  end
461
461
 
462
462
  it "should have #subform :grid option handle :legend and :labels nil values" do
463
- Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><table><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
463
+ Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :legend=>nil, :labels=>nil)}.to_s.must_equal '<form class="forme album" method="post"><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="1"/><table><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="a"/></td></tr></tbody></table></form>'
464
464
  end
465
465
 
466
466
  it "should have #subform :grid option handle :skip_primary_key option" do
@@ -34,15 +34,15 @@ module FormeErbSpecs
34
34
  end
35
35
 
36
36
  it "#form should correctly handle subform with :grid option with block" do
37
- sin_get('/grid-block').sub(/ 4\z/, '4').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td> 2 </tr></tbody></table> 3 <input type="submit" value="Sub"/></form>4'
37
+ sin_get('/grid-block').sub(/ 4\z/, '4').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td> 2 </tr></tbody></table> 3 <input type="submit" value="Sub"/></form>4'
38
38
  end
39
39
 
40
40
  it "#form should correctly handle subform with :grid option without block" do
41
- sin_get('/grid-noblock').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
41
+ sin_get('/grid-noblock').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme album" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="album_artist_attributes_id" name="album[artist_attributes][id]" type="hidden" value="2"/><table><caption>Foo</caption><thead><tr><th>Name</th></tr></thead><tbody><tr><td class="string"><input id="album_artist_attributes_name" maxlength="255" name="album[artist_attributes][name]" type="text" value="A"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
42
42
  end
43
43
 
44
44
  it "#form should correctly handle subform with :grid option without block" do
45
- sin_get('/grid-noblock-multiple').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme artist" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <table><caption>Foo</caption><thead><tr><th>Name</th><th>Copies</th></tr></thead><tbody><input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><tr><td class="string"><input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="N"/></td><td class="integer"><input id="artist_albums_attributes_0_copies_sold" name="artist[albums_attributes][0][copies_sold]" type="number" value="2"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
45
+ sin_get('/grid-noblock-multiple').sub(/ 3\z/, '3').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '<input name="_csrf" type="hidden" value="csrf"/>').must_equal '0 <form action="/baz" class="forme artist" method="post"><input name="_csrf" type="hidden" value="csrf"/> 1 <input id="artist_albums_attributes_0_id" name="artist[albums_attributes][0][id]" type="hidden" value="1"/><table><caption>Foo</caption><thead><tr><th>Name</th><th>Copies</th></tr></thead><tbody><tr><td class="string"><input id="artist_albums_attributes_0_name" maxlength="255" name="artist[albums_attributes][0][name]" type="text" value="N"/></td><td class="integer"><input id="artist_albums_attributes_0_copies_sold" name="artist[albums_attributes][0][copies_sold]" type="number" value="2"/></td></tr></tbody></table> 2 <input type="submit" value="Sub"/></form>3'
46
46
  end
47
47
 
48
48
  it "#form should accept two hashes instead of requiring obj as first argument" do
@@ -65,10 +65,6 @@ module FormeErbSpecs
65
65
  sin_get('/noblock_post').sub(%r{<input name=\"_csrf\" type=\"hidden\" value=\"([^\"]+)\"/>}, "<input name=\"_csrf\" type=\"hidden\" value=\"csrf\"/>").must_equal '<form method="post"><input name="_csrf" type="hidden" value="csrf"/><input type="submit" value="xyz"/></form>'
66
66
  end
67
67
 
68
- silence_warnings "#form should support :hidden_tags option" do
69
- sin_get('/hidden_tags').sub(%r{<input name="_csrf" type="hidden" value="([^"]+)"/>}, '').must_equal '<form action="/baz"><input name="a" type="hidden" value="b"/></form>'
70
- end
71
-
72
68
  it "#form with an empty form should work" do
73
69
  sin_get('/noblock_empty').must_equal '<form action="/baz"></form>'
74
70
  end
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,5 @@
1
1
  $:.unshift(File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib'))
2
2
 
3
- if ENV['WARNING']
4
- require 'warning'
5
- Warning.ignore([:missing_ivar, :not_reached, :method_redefined])
6
- end
7
-
8
3
  if ENV['COVERAGE']
9
4
  require_relative 'forme_coverage'
10
5
  SimpleCov.forme_coverage
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: 2.0.0
4
+ version: 2.1.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: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2022-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -176,7 +176,6 @@ files:
176
176
  - lib/forme/input.rb
177
177
  - lib/forme/rails.rb
178
178
  - lib/forme/raw.rb
179
- - lib/forme/sinatra.rb
180
179
  - lib/forme/tag.rb
181
180
  - lib/forme/template.rb
182
181
  - lib/forme/transformers/error_handler.rb
@@ -243,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
242
  - !ruby/object:Gem::Version
244
243
  version: '0'
245
244
  requirements: []
246
- rubygems_version: 3.2.32
245
+ rubygems_version: 3.3.7
247
246
  signing_key:
248
247
  specification_version: 4
249
248
  summary: HTML forms library
data/lib/forme/sinatra.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen-string-literal: true
2
-
3
- if RUBY_VERSION >= '2'
4
- warn('forme/sinatra and Forme::Sinatra::ERB are deprecated and will be removed in a future version, switch to forme/erb and Forme::ERB::Helper', :uplevel=>1)
5
- end
6
-
7
- require_relative 'erb'
8
-
9
- module Forme
10
- # For backwards compatibility only. New code should
11
- # require 'forme/erb' and include the Forme::ERB::Helper
12
- # class:
13
- #
14
- # helpers Forme::ERB::Helper
15
- module Sinatra
16
- ERB = Forme::ERB::Helper
17
- Erubis = ERB
18
- Form = Forme::Template::Form
19
- HIDDEN_TAGS = Forme::ERB::HIDDEN_TAGS
20
- end
21
- end