forme 2.3.0 → 2.4.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 +1 -1
- data/lib/forme/transformers/formatter.rb +2 -1
- data/lib/forme/transformers/helper.rb +1 -1
- data/lib/forme/version.rb +1 -1
- data/lib/forme.rb +22 -17
- data/lib/roda/plugins/forme_set.rb +12 -0
- data/lib/sequel/plugins/forme.rb +6 -1
- data/lib/sequel/plugins/forme_set.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7427b1117f14a93c292826f8d5d25ceacc3d8948d720176a4a5c131b40875284
|
4
|
+
data.tar.gz: 8d992d583b50af76e3abf54ca3bcbd385f23bf3434d4d6bd761ee0c82ec75975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6fab6a2f89db35fea78cfa851bc6632d8c88d56bc683ebdd5af7f674325f71ab57efa8f327c00150afc5e24cdb7a39b8e4d2a734dafe228bca1794bf5a70514
|
7
|
+
data.tar.gz: fb11b777c89ac1ffdf18265ddc563d527cfd531505d23748957b233f87abd3e14ff5a52e43b335969ae41d71502e7bb5dec8fb12280bf3869ffc3159f7b688dc
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
=== 2.4.0 (2023-04-05)
|
2
|
+
|
3
|
+
* Support Sequel::Model#forme_use_required_abbr? to control whether to add abbr * tag for required inputs (jeremyevans) (#105)
|
4
|
+
|
5
|
+
* Make select input with option groups and a :value option correctly set selected attribute on options in all optgroups (v-kolesnikov) (#111, #110)
|
6
|
+
|
7
|
+
* Make Roda forme_set plugin only include metadata for inputs in the same form, and not inputs on other forms on the same page (jeremyevans) (#109)
|
8
|
+
|
9
|
+
* Use erb/escape for faster HTML escaping if available (jeremyevans)
|
10
|
+
|
1
11
|
=== 2.3.0 (2022-11-15)
|
2
12
|
|
3
13
|
* Add forme/bs5 for Bootstrap 5 support (janko) (#106)
|
data/MIT-LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -53,7 +53,7 @@ This results in the following HTML:
|
|
53
53
|
</label>
|
54
54
|
</form>
|
55
55
|
|
56
|
-
In addition to integrating with Sequel,
|
56
|
+
In addition to integrating with Sequel, Forme also integrates into
|
57
57
|
three separate web frameworks, Roda, Rails, and Sinatra, allowing
|
58
58
|
use of forms inside templates. This is the most common usage of Forme.
|
59
59
|
|
@@ -417,6 +417,7 @@ module Forme
|
|
417
417
|
return unless @opts[:options]
|
418
418
|
process_select_options(@opts[:options], &block)
|
419
419
|
end
|
420
|
+
@attr.delete(:value)
|
420
421
|
|
421
422
|
if prompt = @opts[:add_blank]
|
422
423
|
unless prompt.is_a?(String)
|
@@ -434,7 +435,7 @@ module Forme
|
|
434
435
|
def process_select_options(os)
|
435
436
|
vm = @opts[:value_method]
|
436
437
|
tm = @opts[:text_method]
|
437
|
-
sel = @opts[:selected] || @attr
|
438
|
+
sel = @opts[:selected] || @attr[:value]
|
438
439
|
|
439
440
|
if @opts[:multiple]
|
440
441
|
sel = Array(sel)
|
@@ -7,7 +7,7 @@ module Forme
|
|
7
7
|
class Helper
|
8
8
|
Forme.register_transformer(:helper, :default, new)
|
9
9
|
|
10
|
-
# Return tag with
|
10
|
+
# Return tag with help message span tag after it.
|
11
11
|
def call(tag, input)
|
12
12
|
attr = input.opts[:helper_attr]
|
13
13
|
attr = attr ? attr.dup : {}
|
data/lib/forme/version.rb
CHANGED
data/lib/forme.rb
CHANGED
@@ -9,27 +9,32 @@ module Forme
|
|
9
9
|
end
|
10
10
|
|
11
11
|
begin
|
12
|
-
require '
|
12
|
+
require 'erb/escape'
|
13
|
+
define_singleton_method(:h, ERB::Escape.instance_method(:html_escape))
|
13
14
|
# :nocov:
|
14
|
-
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
15
|
-
CGI = Object.new
|
16
|
-
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
|
17
|
-
end
|
18
|
-
def self.h(value)
|
19
|
-
CGI.escapeHTML(value.to_s)
|
20
|
-
end
|
21
15
|
rescue LoadError
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
def self.h(value)
|
28
|
-
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
|
16
|
+
begin
|
17
|
+
require 'cgi/escape'
|
18
|
+
unless CGI.respond_to?(:escapeHTML) # work around for JRuby 9.1
|
19
|
+
CGI = Object.new
|
20
|
+
CGI.extend(defined?(::CGI::Escape) ? ::CGI::Escape : ::CGI::Util)
|
29
21
|
end
|
30
|
-
else
|
31
22
|
def self.h(value)
|
32
|
-
value.to_s
|
23
|
+
CGI.escapeHTML(value.to_s)
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
ESCAPE_TABLE = {'&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => '''}.freeze
|
27
|
+
ESCAPE_TABLE.each_value(&:freeze)
|
28
|
+
if RUBY_VERSION >= '1.9'
|
29
|
+
# Escape the following characters with their HTML/XML
|
30
|
+
# equivalents.
|
31
|
+
def self.h(value)
|
32
|
+
value.to_s.gsub(/[&<>"']/, ESCAPE_TABLE)
|
33
|
+
end
|
34
|
+
else
|
35
|
+
def self.h(value)
|
36
|
+
value.to_s.gsub(/[&<>"']/){|s| ESCAPE_TABLE[s]}
|
37
|
+
end
|
33
38
|
end
|
34
39
|
end
|
35
40
|
end
|
@@ -37,6 +37,18 @@ class Roda
|
|
37
37
|
}.freeze
|
38
38
|
|
39
39
|
module InstanceMethods
|
40
|
+
# If a Sequel::Model object that supports forme_set is passed,
|
41
|
+
# isolate the inputs so that each form only includes metadata
|
42
|
+
# for inputs on the form, and not inputs for earlier forms on
|
43
|
+
# the same page.
|
44
|
+
def form(obj=nil, attr={}, opts={}, &block)
|
45
|
+
if obj.is_a?(Sequel::Plugins::FormeSet::InstanceMethods)
|
46
|
+
obj.isolate_forme_inputs{super}
|
47
|
+
else
|
48
|
+
super
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
40
52
|
# Return hash based on submitted parameters, with :values key
|
41
53
|
# being submitted values for the object, and :validations key
|
42
54
|
# being a hash of validation metadata for the object.
|
data/lib/sequel/plugins/forme.rb
CHANGED
@@ -207,7 +207,7 @@ module Sequel # :nodoc:
|
|
207
207
|
# is required.
|
208
208
|
def handle_label(f)
|
209
209
|
opts[:label] = humanize(field) unless opts.has_key?(:label)
|
210
|
-
opts[:label] = [opts[:label], form._tag(:abbr, {:title=>'required'}, '*')] if opts[:label] && opts[:required]
|
210
|
+
opts[:label] = [opts[:label], form._tag(:abbr, {:title=>'required'}, '*')] if opts[:label] && opts[:required] && obj.forme_use_required_abbr?
|
211
211
|
end
|
212
212
|
|
213
213
|
# Update the attributes and options for any recognized validations
|
@@ -492,6 +492,11 @@ module Sequel # :nodoc:
|
|
492
492
|
'post'
|
493
493
|
end
|
494
494
|
|
495
|
+
# Whether to set an abbr tag in labels for required inputs.
|
496
|
+
def forme_use_required_abbr?
|
497
|
+
true
|
498
|
+
end
|
499
|
+
|
495
500
|
# Use the underscored model name as the default namespace.
|
496
501
|
def forme_namespace
|
497
502
|
model.send(:underscore, model.name)
|
@@ -24,6 +24,21 @@ module Sequel # :nodoc:
|
|
24
24
|
@forme_inputs ||= {}
|
25
25
|
end
|
26
26
|
|
27
|
+
# Temporarily reset forme_inputs to the empty hash before yielding to the block.
|
28
|
+
# Used by the Roda forme_set plugin to make sure each form only includes metadata
|
29
|
+
# for inputs in that form, and not metadata for inputs for earlier forms on the same page.
|
30
|
+
def isolate_forme_inputs
|
31
|
+
return yield if frozen?
|
32
|
+
|
33
|
+
forme_inputs = self.forme_inputs
|
34
|
+
begin
|
35
|
+
@forme_inputs = {}
|
36
|
+
yield
|
37
|
+
ensure
|
38
|
+
@forme_inputs = forme_inputs.merge(@forme_inputs)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
27
42
|
# Hash with column name symbol keys and <tt>[subset, allowed_values]</tt> values. +subset+
|
28
43
|
# is a boolean flag, if true, the uploaded values should be a subset of the allowed values,
|
29
44
|
# otherwise, there should be a single uploaded value that is a member of the allowed values.
|
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.
|
4
|
+
version: 2.4.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: 2023-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -225,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
|
-
rubygems_version: 3.
|
228
|
+
rubygems_version: 3.4.10
|
229
229
|
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: HTML forms library
|