trenni-formatters 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac162860960979c57091379978f2bacfb93ef759
4
- data.tar.gz: 9c31ab0d5f6c847a97512dfd1513bd83c87b1124
3
+ metadata.gz: 8211316a3883ea35000eac2f2d7577066801285c
4
+ data.tar.gz: 1e663830ec43445a1580b330d1d3285633b40c46
5
5
  SHA512:
6
- metadata.gz: 0ca42bc7c0c37c207f9ed0db93696cde7c3c899788d3c0f8c7a0537bc43ebdc7045144fdee8b5336dfc12d364fb9b44069423c90a7fe9402f023656a3a10b895
7
- data.tar.gz: d17162fb3e392f9001d2e6c95f46d9140211b8b28d6ebfcd7854e76237e36ca4234a35cd41a66a8dd92c5cd19306d4655c3e576af3d54667731d67da5616cd4b
6
+ metadata.gz: 2883f0457f3bdb1c6a82390be80d435ed68ee6532cbe50129a3e283cb97e9ced70007e086a993cd4fc912e8ed1c04ad61d2904f3d38b9c3ea4bd7d93c02eb8cf
7
+ data.tar.gz: 875cc5c45745c8f1e67e4ad5c814ec101529459cf72a52f6dd46811b8d36e6e3117f4d164ef5a81dace38e2049b336802a03f80620b2dc32d60602f7a5d077fb
@@ -77,14 +77,22 @@ module Trenni
77
77
  }
78
78
  end
79
79
 
80
- def item(options = {})
80
+ def item(builder: nil, **options)
81
81
  options[:field] ||= 'id'
82
82
 
83
- Builder.fragment(options[:builder]) do |builder|
83
+ Builder.fragment(builder) do |builder|
84
84
  builder.inline(:option, option_attributes_for(options)) { builder.text title_for(options) }
85
85
  end
86
86
  end
87
87
 
88
+ def optional_title_for(options)
89
+ if options[:optional] == true
90
+ options[:blank] || ''
91
+ else
92
+ options[:optional]
93
+ end
94
+ end
95
+
88
96
  def group_attributes_for(options)
89
97
  return {
90
98
  :label => title_for(options),
@@ -98,7 +106,7 @@ module Trenni
98
106
  Builder.fragment(@builder) do |builder|
99
107
  builder.tag :optgroup, group_attributes_for(options) do
100
108
  if options[:optional]
101
- item(:title => '', :value => '', :builder => builder)
109
+ item(:title => optional_title_for(options), :value => nil, :builder => builder)
102
110
  end
103
111
 
104
112
  builder.append Trenni::Template.capture(&block)
@@ -120,7 +128,7 @@ module Trenni
120
128
  Builder.fragment(@builder) do |builder|
121
129
  builder.tag :select, select_attributes_for(options) do
122
130
  if options[:optional]
123
- item(:title => '', :value => '', :builder => builder)
131
+ item(:title => optional_title_for(options), :value => nil, :builder => builder)
124
132
  end
125
133
 
126
134
  builder.append Trenni::Template.capture(self, &block)
@@ -72,8 +72,8 @@ module Trenni
72
72
  }
73
73
  end
74
74
 
75
- def item(options = {}, &block)
76
- Builder.fragment do |builder|
75
+ def item(builder: nil, **options, &block)
76
+ Builder.fragment(builder) do |builder|
77
77
  builder.tag :tr do
78
78
  builder.inline(:td, :class => :handle) do
79
79
  builder.tag :input, radio_attributes_for(options)
@@ -90,10 +90,22 @@ module Trenni
90
90
  end >> block
91
91
  end
92
92
 
93
+ def optional_title_for(options)
94
+ if options[:optional] == true
95
+ options[:blank] || ''
96
+ else
97
+ options[:optional]
98
+ end
99
+ end
100
+
93
101
  def call(options = {}, &block)
94
102
  Builder.fragment(@builder) do |builder|
95
103
  builder.tag :table do
96
104
  builder.tag :tbody do
105
+ if options[:optional]
106
+ item(:title => optional_title_for(options), :value => nil, :builder => builder)
107
+ end
108
+
97
109
  builder.append Trenni::Template.capture(self, &block)
98
110
  end
99
111
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Formatters
23
- VERSION = "2.3.0"
23
+ VERSION = "2.4.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams