forme 1.11.0 → 1.12.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 +4 -4
- data/CHANGELOG +10 -0
- data/MIT-LICENSE +1 -1
- data/README.rdoc +9 -5
- data/lib/forme/transformers/formatter.rb +4 -1
- data/lib/forme/version.rb +1 -1
- data/lib/forme.rb +2 -0
- data/lib/sequel/plugins/forme.rb +2 -1
- data/lib/sequel/plugins/forme_set.rb +3 -1
- data/spec/forme_spec.rb +4 -0
- data/spec/rails_integration_spec.rb +39 -23
- data/spec/roda_integration_spec.rb +2 -2
- data/spec/sequel_i18n_plugin_spec.rb +1 -0
- data/spec/sequel_plugin_spec.rb +8 -0
- data/spec/sequel_set_plugin_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f9ee8a7a7efaf9ff59c55404e6c11aba0125cdf59972366b94aa3359b06c6c1f
|
|
4
|
+
data.tar.gz: dd9f90ad552c827b66a3d8146f8933e5258b34ece1db5a8a9515ac9e2aeada44
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5867cc14f49ea0a2419e4f7d30a518a8886753f11e4e6af46f7565106ef54869c9bf9d5ba691f7f08ee7fab5d729bb16e8b1463939dc043d7e91aeb5e8bf1f2e
|
|
7
|
+
data.tar.gz: 25bf44d57e37ef994cab9a6c2bf532b4dddd209fff6b1542b21596e2cdbfa1e20a1ae04af9d2b4c0ad113f322c06fe1e8a662a4d2facd36439f2c1a45d2e4250
|
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
=== 1.12.0 (2021-08-25)
|
|
2
|
+
|
|
3
|
+
* Make forme_set Sequel plugin handle frozen Sequel::Model instances (jeremyevans)
|
|
4
|
+
|
|
5
|
+
* Do not override an error on a field when using the Sequel plugin if :error option is already given (jeremyevans)
|
|
6
|
+
|
|
7
|
+
* Avoid error when creating label text when using Sequel input on non-Sequel form without an explicit :label option (jeremyevans)
|
|
8
|
+
|
|
9
|
+
* Make :select_options option for date/datetime selects support providing both option texts and option values using a 2 element array (jeremyevans)
|
|
10
|
+
|
|
1
11
|
=== 1.11.0 (2020-01-03)
|
|
2
12
|
|
|
3
13
|
* Add Roda forme_set plugin, using HMACed form metadata to automatically handle submitted form parameters (jeremyevans)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
|
@@ -101,8 +101,7 @@ by creating your own transformer and then calling the existing transformer.
|
|
|
101
101
|
Demo Site :: http://forme-demo.jeremyevans.net
|
|
102
102
|
RDoc :: http://forme.jeremyevans.net
|
|
103
103
|
Source :: https://github.com/jeremyevans/forme
|
|
104
|
-
|
|
105
|
-
Google Group :: https://groups.google.com/forum/#!forum/ruby-forme
|
|
104
|
+
Discussion Forum :: https://github.com/jeremyevans/forme/discussions
|
|
106
105
|
Bug Tracker :: https://github.com/jeremyevans/forme/issues
|
|
107
106
|
|
|
108
107
|
= Basic Usage
|
|
@@ -940,6 +939,7 @@ These options are supported by all of the input types:
|
|
|
940
939
|
:disabled :: Set the disabled attribute if true
|
|
941
940
|
:error :: Set an error message, invoking the error_handler
|
|
942
941
|
:error_handler :: Set a custom error_handler, overriding the form's default
|
|
942
|
+
:help :: Set help text to use, invoking the helper
|
|
943
943
|
:helper :: Set a custom helper, overriding the form's default
|
|
944
944
|
:id :: The id attribute to use
|
|
945
945
|
:key :: The base to use for the name and id attributes, based on the current
|
|
@@ -983,9 +983,12 @@ creates multiple select options. Options:
|
|
|
983
983
|
(:date default: <tt>[:year, '-', :month, '-', :day]</tt>)
|
|
984
984
|
(:datetime default: <tt>[:year, '-', :month, '-', :day, ' ', :hour, ':', :minute, ':', :second]</tt>)
|
|
985
985
|
:select_labels :: The labels to use for the select boxes. Should be a hash keyed by the
|
|
986
|
-
|
|
986
|
+
symbol used (e.g. <tt>{:month=>'Month'}</tt>). By default, no labels are used.
|
|
987
987
|
:select_options :: The options to use for the select boxes. Should be a hash keyed by the
|
|
988
|
-
symbol used in order (e.g. <tt>{:year=>1970..2020}</tt>)
|
|
988
|
+
symbol used in order (e.g. <tt>{:year=>1970..2020}</tt>). The values
|
|
989
|
+
can be a number used as both the value and the text of the option or
|
|
990
|
+
an array with two elements, the first of which is the value for the option
|
|
991
|
+
and the second of which is the text for the option.
|
|
989
992
|
|
|
990
993
|
=== :select
|
|
991
994
|
|
|
@@ -1005,7 +1008,8 @@ Creates a select tag, containing option tags specified by the :options option.
|
|
|
1005
1008
|
:options :: An enumerable of options used for creating option tags.
|
|
1006
1009
|
If the :text_method and :value_method are not given and the entry is an
|
|
1007
1010
|
array, uses the first entry of the array as the text of the option, and
|
|
1008
|
-
the
|
|
1011
|
+
the last entry of the array as the value of the option. If the last entry
|
|
1012
|
+
of the array is a hash, uses the hash as the attributes for the option.
|
|
1009
1013
|
:selected :: The value that should be selected. Any options that are equal to
|
|
1010
1014
|
this value (or included in this value if a multiple select box),
|
|
1011
1015
|
are set to selected.
|
|
@@ -160,7 +160,10 @@ module Forme
|
|
|
160
160
|
@opts[:select_labels] ||= {}
|
|
161
161
|
order.map do |x|
|
|
162
162
|
next x if x.is_a?(String)
|
|
163
|
-
|
|
163
|
+
options = ops[x].map do |value, text|
|
|
164
|
+
[text || sprintf(format, value), value]
|
|
165
|
+
end
|
|
166
|
+
opts = @opts.merge(:label=>@opts[:select_labels][x], :wrapper=>nil, :error=>nil, :name=>"#{name}[#{x}]", :value=>values[x], :options=>options)
|
|
164
167
|
opts[:id] = if first_input
|
|
165
168
|
first_input = false
|
|
166
169
|
id
|
data/lib/forme/version.rb
CHANGED
data/lib/forme.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Forme
|
|
|
10
10
|
|
|
11
11
|
begin
|
|
12
12
|
require 'cgi/escape'
|
|
13
|
+
# :nocov:
|
|
13
14
|
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
|
14
15
|
CGI = Object.new
|
|
15
16
|
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
|
|
@@ -32,6 +33,7 @@ module Forme
|
|
|
32
33
|
end
|
|
33
34
|
end
|
|
34
35
|
end
|
|
36
|
+
# :nocov:
|
|
35
37
|
|
|
36
38
|
@default_add_blank_prompt = nil
|
|
37
39
|
@default_config = :default
|
data/lib/sequel/plugins/forme.rb
CHANGED
|
@@ -192,6 +192,7 @@ module Sequel # :nodoc:
|
|
|
192
192
|
|
|
193
193
|
# Set the error option correctly if the field contains errors
|
|
194
194
|
def handle_errors(f)
|
|
195
|
+
return if opts.has_key?(:error)
|
|
195
196
|
if e = obj.errors.on(f)
|
|
196
197
|
opts[:error] = e.join(', ')
|
|
197
198
|
end
|
|
@@ -346,7 +347,7 @@ module Sequel # :nodoc:
|
|
|
346
347
|
|
|
347
348
|
# Delegate to the +form+.
|
|
348
349
|
def humanize(s)
|
|
349
|
-
form.humanize(s)
|
|
350
|
+
form.respond_to?(:humanize) ? form.humanize(s) : s.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
|
|
350
351
|
end
|
|
351
352
|
|
|
352
353
|
# If the column allows +NULL+ values, use a three-valued select
|
|
@@ -18,6 +18,7 @@ module Sequel # :nodoc:
|
|
|
18
18
|
module InstanceMethods
|
|
19
19
|
# Hash with column name symbol keys and Forme::SequelInput values
|
|
20
20
|
def forme_inputs
|
|
21
|
+
return (@forme_inputs || {}) if frozen?
|
|
21
22
|
@forme_inputs ||= {}
|
|
22
23
|
end
|
|
23
24
|
|
|
@@ -25,12 +26,13 @@ module Sequel # :nodoc:
|
|
|
25
26
|
# is a boolean flag, if true, the uploaded values should be a subset of the allowed values,
|
|
26
27
|
# otherwise, there should be a single uploaded value that is a member of the allowed values.
|
|
27
28
|
def forme_validations
|
|
29
|
+
return (@forme_validations || {}) if frozen?
|
|
28
30
|
@forme_validations ||= {}
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
# Keep track of the inputs used.
|
|
32
34
|
def forme_input(_form, field, _opts)
|
|
33
|
-
forme_inputs[field] = super
|
|
35
|
+
frozen? ? super : (forme_inputs[field] = super)
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
# Given the hash of submitted parameters, return a hash containing information on how to
|
data/spec/forme_spec.rb
CHANGED
|
@@ -317,6 +317,10 @@ describe "Forme plain forms" do
|
|
|
317
317
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>1970..2020}).to_s.must_equal %{<select id="bar" name="foo[year]">#{sel(1970..2020, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
|
318
318
|
end
|
|
319
319
|
|
|
320
|
+
it "should support :select_options with both values and text for dates when :as=>:select is given" do
|
|
321
|
+
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :select_options=>{:year=>[[2011, 'A'], [2012, 'B']]}).to_s.must_equal %{<select id="bar" name="foo[year]"><option selected="selected" value="2011">A</option><option value="2012">B</option></select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select>}
|
|
322
|
+
end
|
|
323
|
+
|
|
320
324
|
it "should have explicit labeler and trtd wrapper work with multiple select boxes for dates" do
|
|
321
325
|
@f.input(:date, :name=>"foo", :id=>"bar", :as=>:select, :value=>Date.new(2011, 6, 5), :wrapper=>:trtd, :labeler=>:explicit, :label=>'Baz').to_s.must_equal %{<tr><td><label class="label-before" for="bar">Baz</label></td><td><select id="bar" name="foo[year]">#{sel(1900..2050, 2011)}</select>-<select id="bar_month" name="foo[month]">#{sel(1..12, 6)}</select>-<select id="bar_day" name="foo[day]">#{sel(1..31, 5)}</select></td></tr>}
|
|
322
326
|
end
|
|
@@ -3,32 +3,48 @@ require File.join(File.dirname(File.expand_path(__FILE__)), 'sequel_helper.rb')
|
|
|
3
3
|
|
|
4
4
|
require 'rubygems'
|
|
5
5
|
begin
|
|
6
|
-
require 'action_controller/railtie'
|
|
7
|
-
rescue LoadError
|
|
8
|
-
warn "unable to load rails, skipping rails spec"
|
|
9
|
-
else
|
|
10
|
-
begin
|
|
11
|
-
require 'active_pack/gem_version'
|
|
12
|
-
rescue LoadError
|
|
13
|
-
end
|
|
14
|
-
require 'forme/rails'
|
|
6
|
+
require 'action_controller/railtie'
|
|
15
7
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
get action, :controller=>'forme', :action=>action
|
|
20
|
-
end
|
|
8
|
+
begin
|
|
9
|
+
require 'active_pack/gem_version'
|
|
10
|
+
rescue LoadError
|
|
21
11
|
end
|
|
22
|
-
|
|
23
|
-
config.middleware.delete(ActionDispatch::HostAuthorization) if defined?(ActionDispatch::HostAuthorization)
|
|
24
|
-
config.middleware.delete(ActionDispatch::ShowExceptions)
|
|
25
|
-
config.middleware.delete(Rack::Lock)
|
|
26
|
-
config.secret_key_base = 'foo'*15
|
|
27
|
-
config.secret_token = 'secret token'*15 if Rails.respond_to?(:version) && Rails.version < '5.2'
|
|
28
|
-
config.eager_load = true
|
|
29
|
-
initialize!
|
|
30
|
-
end
|
|
12
|
+
require 'forme/rails'
|
|
31
13
|
|
|
14
|
+
if Rails.respond_to?(:version) && Rails.version.start_with?('4')
|
|
15
|
+
# Work around issue in backported openssl environments where
|
|
16
|
+
# secret is 64 bytes intead of 32 bytes
|
|
17
|
+
require 'active_support/message_encryptor'
|
|
18
|
+
ActiveSupport::MessageEncryptor.send :prepend, Module.new {
|
|
19
|
+
def initialize(secret, *signature_key_or_options)
|
|
20
|
+
secret = secret[0, 32]
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
class FormeRails < Rails::Application
|
|
27
|
+
routes.append do
|
|
28
|
+
%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|
|
|
29
|
+
get action, :controller=>'forme', :action=>action
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
config.active_support.deprecation = :stderr
|
|
33
|
+
config.middleware.delete(ActionDispatch::HostAuthorization) if defined?(ActionDispatch::HostAuthorization)
|
|
34
|
+
config.middleware.delete(ActionDispatch::ShowExceptions)
|
|
35
|
+
config.middleware.delete(Rack::Lock)
|
|
36
|
+
config.secret_key_base = 'foo'*15
|
|
37
|
+
config.secret_token = 'secret token'*15 if Rails.respond_to?(:version) && Rails.version < '5.2'
|
|
38
|
+
config.eager_load = true
|
|
39
|
+
begin
|
|
40
|
+
initialize!
|
|
41
|
+
rescue NoMethodError
|
|
42
|
+
raise LoadError
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
rescue LoadError
|
|
46
|
+
warn "unable to load or setup rails, skipping rails spec"
|
|
47
|
+
else
|
|
32
48
|
class FormeController < ActionController::Base
|
|
33
49
|
helper Forme::Rails::ERB
|
|
34
50
|
|
|
@@ -149,7 +149,7 @@ else
|
|
|
149
149
|
forme_set_block = orig_hash.delete(:forme_set_block)
|
|
150
150
|
orig_hash.each{|k,v| hash[k.to_s] = v}
|
|
151
151
|
album = @ab
|
|
152
|
-
ret,
|
|
152
|
+
ret, _, data, hmac = nil
|
|
153
153
|
|
|
154
154
|
@app.route do |r|
|
|
155
155
|
r.get do
|
|
@@ -274,7 +274,7 @@ else
|
|
|
274
274
|
obj.must_be_same_as @ab
|
|
275
275
|
version.must_be_nil
|
|
276
276
|
|
|
277
|
-
|
|
277
|
+
forme_set(@ab, {:name=>'Bar', :forme_set_block=>forme_set_block}, {}, :form_version=>2){|f| f.input(:name)}
|
|
278
278
|
obj.must_be_same_as @ab
|
|
279
279
|
name.must_equal 'Bar'
|
|
280
280
|
version.must_equal 2
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'spec_helper.rb')
|
|
2
2
|
|
|
3
3
|
begin
|
|
4
|
+
raise LoadError if defined?(JRUBY_VERSION) && /\A9\.2\./.match(JRUBY_VERSION)
|
|
4
5
|
require File.join(File.dirname(File.expand_path(__FILE__)), 'sequel_i18n_helper.rb')
|
|
5
6
|
rescue LoadError
|
|
6
7
|
warn "unable to load i18n, skipping i18n Sequel plugin spec"
|
data/spec/sequel_plugin_spec.rb
CHANGED
|
@@ -331,6 +331,11 @@ describe "Forme Sequel::Model forms" do
|
|
|
331
331
|
@b.input(:foo, :type=>:phone).to_s.must_equal '<label>Foo: <input id="album_foo" name="album[foo]" type="phone" value="bar"/></label>'
|
|
332
332
|
end
|
|
333
333
|
|
|
334
|
+
it "should not override an explicit :error setting" do
|
|
335
|
+
@ab.errors.add(:name, 'tis not valid')
|
|
336
|
+
@b.input(:name, :error=>nil).to_s.must_equal '<label>Name: <input id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label>'
|
|
337
|
+
end
|
|
338
|
+
|
|
334
339
|
it "should correctly show an error message if there is one" do
|
|
335
340
|
@ab.errors.add(:name, 'tis not valid')
|
|
336
341
|
@b.input(:name).to_s.must_equal '<label>Name: <input aria-describedby="album_name_error_message" aria-invalid="true" class="error" id="album_name" maxlength="255" name="album[name]" type="text" value="b"/></label><span class="error_message" id="album_name_error_message">tis not valid</span>'
|
|
@@ -453,6 +458,9 @@ describe "Forme Sequel::Model forms" do
|
|
|
453
458
|
Forme.form(@ab){|f| f.subform(:artist, :inputs=>[:name], :grid=>true, :skip_primary_key=>true)}.to_s.must_equal '<form class="forme album" method="post"><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>'
|
|
454
459
|
end
|
|
455
460
|
|
|
461
|
+
it "should handle non-Sequel forms with Sequel inputs" do
|
|
462
|
+
Forme.form{|f| f.input(:name, :obj=>@ab).to_s.must_equal '<label>Name: <input id="name" maxlength="255" name="name" type="text" value="b"/></label>'}
|
|
463
|
+
end
|
|
456
464
|
end
|
|
457
465
|
|
|
458
466
|
describe "Forme Sequel plugin default input types based on column names" do
|
|
@@ -222,4 +222,11 @@ describe "Sequel forme_set plugin" do
|
|
|
222
222
|
@ab.forme_validations[:name] = [:bar, []]
|
|
223
223
|
proc{@ab.valid?}.must_raise Sequel::Plugins::Forme::Error
|
|
224
224
|
end
|
|
225
|
+
|
|
226
|
+
it "should handle frozen instances as form inputs" do
|
|
227
|
+
@ab.freeze
|
|
228
|
+
@ab.forme_inputs.must_equal({})
|
|
229
|
+
@ab.forme_validations.must_equal({})
|
|
230
|
+
@f.input(:name).must_be_kind_of(Forme::Input)
|
|
231
|
+
end
|
|
225
232
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
|
4
|
+
version: 1.12.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:
|
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -216,7 +216,7 @@ metadata:
|
|
|
216
216
|
bug_tracker_uri: https://github.com/jeremyevans/forme/issues
|
|
217
217
|
changelog_uri: http://forme.jeremyevans.net/files/CHANGELOG.html
|
|
218
218
|
documentation_uri: http://forme.jeremyevans.net
|
|
219
|
-
mailing_list_uri: https://
|
|
219
|
+
mailing_list_uri: https://github.com/jeremyevans/forme/discussions
|
|
220
220
|
source_code_uri: https://github.com/jeremyevans/forme
|
|
221
221
|
post_install_message:
|
|
222
222
|
rdoc_options:
|
|
@@ -240,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
240
240
|
- !ruby/object:Gem::Version
|
|
241
241
|
version: '0'
|
|
242
242
|
requirements: []
|
|
243
|
-
rubygems_version: 3.
|
|
243
|
+
rubygems_version: 3.2.22
|
|
244
244
|
signing_key:
|
|
245
245
|
specification_version: 4
|
|
246
246
|
summary: HTML forms library
|