trenni-formatters 2.10.0 → 2.13.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/lib/trenni/formatters/formatter.rb +7 -7
- data/lib/trenni/formatters/html/accept_checkbox.rb +65 -0
- data/lib/trenni/formatters/html/definition_list_form.rb +7 -6
- data/lib/trenni/formatters/html/form_formatter.rb +1 -1
- data/lib/trenni/formatters/html/label_form.rb +4 -6
- data/lib/trenni/formatters/html/option_select.rb +41 -36
- data/lib/trenni/formatters/html/radio_select.rb +23 -21
- data/lib/trenni/formatters/relative_time.rb +1 -1
- data/lib/trenni/formatters/truncated_text.rb +14 -12
- data/lib/trenni/formatters/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a733cfc023aed3ce78ce8278b8d4ef57ee05215440d5bcf0304280115b002cc5
|
4
|
+
data.tar.gz: 374dade3208878129d786ef7917085ee5f05e5df50a62eb2d969ce970be944b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6663a34484d4fdc67cc9771df53959941e8c514bf03b752bb2c63680ac1e041ee7da4c95a6d8bb45430dd230093cc9b5911c1fef394dc6d179fafd4e9632121
|
7
|
+
data.tar.gz: a469d0252fdf4dd7fecd68048350e68a938bb28bbfe3347b47d2c04c39cc40fd7f5fd6dc3477c05d7eb360190f58c526d9fc900930183868ff3cadc2538486b6
|
@@ -81,17 +81,17 @@ module Trenni
|
|
81
81
|
|
82
82
|
attr :options
|
83
83
|
|
84
|
-
def format_unspecified(object, options)
|
84
|
+
def format_unspecified(object, **options)
|
85
85
|
object.to_s
|
86
86
|
end
|
87
87
|
|
88
|
-
def format(object, options
|
88
|
+
def format(object, **options)
|
89
89
|
method_name = self.method_for_mapping(object)
|
90
90
|
|
91
91
|
if self.respond_to?(method_name)
|
92
|
-
self.send(method_name, object, options)
|
92
|
+
self.send(method_name, object, **options)
|
93
93
|
else
|
94
|
-
format_unspecified(object, options)
|
94
|
+
format_unspecified(object, **options)
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -101,15 +101,15 @@ module Trenni
|
|
101
101
|
@options[key]
|
102
102
|
end
|
103
103
|
|
104
|
-
map(String) do |object, options|
|
104
|
+
map(String) do |object, **options|
|
105
105
|
object
|
106
106
|
end
|
107
107
|
|
108
|
-
map(NilClass) do |object, options|
|
108
|
+
map(NilClass) do |object, **options|
|
109
109
|
options[:blank] || @options[:blank] || ""
|
110
110
|
end
|
111
111
|
|
112
|
-
map(TrueClass, FalseClass, *Mapping.lookup_descendants(Numeric)) do |object, options|
|
112
|
+
map(TrueClass, FalseClass, *Mapping.lookup_descendants(Numeric)) do |object, **options|
|
113
113
|
object.to_s
|
114
114
|
end
|
115
115
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'trenni/builder'
|
24
|
+
|
25
|
+
module Trenni
|
26
|
+
module Formatters
|
27
|
+
module HTML
|
28
|
+
class AcceptCheckbox
|
29
|
+
def self.call(formatter, builder, **options, &block)
|
30
|
+
instance = self.new(formatter, builder, **options)
|
31
|
+
|
32
|
+
instance.call(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(formatter, builder, **options)
|
36
|
+
@formatter = formatter
|
37
|
+
@builder = builder
|
38
|
+
@options = options
|
39
|
+
end
|
40
|
+
|
41
|
+
def name_for(**options)
|
42
|
+
@formatter.name_for(**options)
|
43
|
+
end
|
44
|
+
|
45
|
+
def checkbox_attributes_for(**options)
|
46
|
+
@formatter.checkbox_attributes_for(**options)
|
47
|
+
end
|
48
|
+
|
49
|
+
def call(&block)
|
50
|
+
Builder.fragment(@builder) do |builder|
|
51
|
+
builder.inline('span') do
|
52
|
+
builder.inline :input, type: :hidden, name: name_for(**@options), value: 'false'
|
53
|
+
|
54
|
+
builder.tag :input, checkbox_attributes_for(**@options)
|
55
|
+
|
56
|
+
builder.text " "
|
57
|
+
|
58
|
+
builder.capture(self, &block)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -116,18 +116,17 @@ module Trenni
|
|
116
116
|
builder.tag :input, submit_attributes_for(**options)
|
117
117
|
end
|
118
118
|
end
|
119
|
-
|
120
|
-
def element(klass, options
|
119
|
+
|
120
|
+
def element(klass, **options, &block)
|
121
121
|
options = @options.merge(**options)
|
122
|
-
buffer = Trenni::Template.buffer(block.binding)
|
123
122
|
|
124
|
-
|
123
|
+
Builder.fragment(block&.binding) do |builder|
|
125
124
|
builder.inline(:dt) do
|
126
125
|
builder.text title_for(**options)
|
127
126
|
end
|
128
127
|
|
129
128
|
builder.tag(:dd) do
|
130
|
-
klass.call(self,
|
129
|
+
klass.call(self, builder, **options, &block)
|
131
130
|
|
132
131
|
if details = details_for(**options)
|
133
132
|
builder.inline(:small, class: 'details') {builder.text details}
|
@@ -138,7 +137,9 @@ module Trenni
|
|
138
137
|
|
139
138
|
def fieldset(**options, &block)
|
140
139
|
super do |builder|
|
141
|
-
builder.tag(:dl
|
140
|
+
builder.tag(:dl) do
|
141
|
+
yield(builder)
|
142
|
+
end
|
142
143
|
end
|
143
144
|
end
|
144
145
|
end
|
@@ -99,8 +99,6 @@ module Trenni
|
|
99
99
|
builder.inline :input, :type => :hidden, :name => name_for(**options), :value => 'false'
|
100
100
|
|
101
101
|
builder.inline(:span) do
|
102
|
-
builder.text title_for(**options)
|
103
|
-
|
104
102
|
if details = details_for(**options)
|
105
103
|
builder.inline(:small) {builder.text details}
|
106
104
|
end
|
@@ -108,7 +106,7 @@ module Trenni
|
|
108
106
|
|
109
107
|
builder.tag :input, checkbox_attributes_for(**options)
|
110
108
|
|
111
|
-
# We would like a little bit of whitespace between the checkbox and the title
|
109
|
+
# We would like a little bit of whitespace between the checkbox and the title:
|
112
110
|
builder.text " " + title_for(**options)
|
113
111
|
end
|
114
112
|
end
|
@@ -124,11 +122,11 @@ module Trenni
|
|
124
122
|
end
|
125
123
|
end
|
126
124
|
|
127
|
-
def element(klass, options
|
125
|
+
def element(klass, **options, &block)
|
128
126
|
options = @options.merge(**options)
|
129
127
|
buffer = Trenni::Template.buffer(block.binding)
|
130
128
|
|
131
|
-
|
129
|
+
Builder.fragment(buffer) do |builder|
|
132
130
|
builder.inline(:label) do
|
133
131
|
builder.inline(:span) do
|
134
132
|
builder.text title_for(**options)
|
@@ -138,7 +136,7 @@ module Trenni
|
|
138
136
|
end
|
139
137
|
end
|
140
138
|
|
141
|
-
klass.call(self,
|
139
|
+
klass.call(self, builder, **options, &block)
|
142
140
|
end
|
143
141
|
end
|
144
142
|
end
|
@@ -27,22 +27,18 @@ module Trenni
|
|
27
27
|
module HTML
|
28
28
|
# Standard drop-down select box:
|
29
29
|
class OptionSelect
|
30
|
-
def self.call(formatter,
|
31
|
-
instance = self.new(formatter,
|
30
|
+
def self.call(formatter, builder, **options, &block)
|
31
|
+
instance = self.new(formatter, builder, **options)
|
32
32
|
|
33
|
-
instance.call(
|
33
|
+
instance.call(&block)
|
34
34
|
end
|
35
35
|
|
36
|
-
def initialize(formatter,
|
36
|
+
def initialize(formatter, builder, **options)
|
37
37
|
@formatter = formatter
|
38
|
-
@object = formatter.object
|
39
|
-
@field = options[:field]
|
40
|
-
|
41
|
-
@options = options
|
42
|
-
|
43
38
|
@builder = builder
|
39
|
+
@options = options
|
44
40
|
end
|
45
|
-
|
41
|
+
|
46
42
|
def name_for(**options)
|
47
43
|
if name = @formatter.name_for(**options)
|
48
44
|
if options[:multiple]
|
@@ -52,23 +48,23 @@ module Trenni
|
|
52
48
|
return name
|
53
49
|
end
|
54
50
|
end
|
55
|
-
|
51
|
+
|
56
52
|
def raw_value_for(**options)
|
57
53
|
@formatter.raw_value_for(**options)
|
58
54
|
end
|
59
|
-
|
55
|
+
|
60
56
|
def raw_value
|
61
57
|
@raw_value ||= raw_value_for(**@options)
|
62
58
|
end
|
63
|
-
|
59
|
+
|
64
60
|
def value_for(**options)
|
65
61
|
@formatter.value_for(**options)
|
66
62
|
end
|
67
|
-
|
63
|
+
|
68
64
|
def title_for(**options)
|
69
65
|
@formatter.title_for(**options)
|
70
66
|
end
|
71
|
-
|
67
|
+
|
72
68
|
def option_attributes_for(**options)
|
73
69
|
return {
|
74
70
|
:value => value_for(**options),
|
@@ -78,15 +74,21 @@ module Trenni
|
|
78
74
|
:data => options[:data],
|
79
75
|
}
|
80
76
|
end
|
81
|
-
|
82
|
-
def item(
|
77
|
+
|
78
|
+
def item(**options, &block)
|
83
79
|
options[:field] ||= 'id'
|
84
80
|
|
85
|
-
Builder.fragment(builder) do |builder|
|
86
|
-
builder.inline(:option, option_attributes_for(**options))
|
81
|
+
Builder.fragment(block&.binding || @builder) do |builder|
|
82
|
+
builder.inline(:option, option_attributes_for(**options)) do
|
83
|
+
if block_given?
|
84
|
+
builder.capture(self, &block)
|
85
|
+
else
|
86
|
+
builder.text title_for(**options)
|
87
|
+
end
|
88
|
+
end
|
87
89
|
end
|
88
90
|
end
|
89
|
-
|
91
|
+
|
90
92
|
def optional_title_for(**options)
|
91
93
|
if options[:optional] == true
|
92
94
|
options[:blank] || ''
|
@@ -94,7 +96,7 @@ module Trenni
|
|
94
96
|
options[:optional]
|
95
97
|
end
|
96
98
|
end
|
97
|
-
|
99
|
+
|
98
100
|
def group_attributes_for(**options)
|
99
101
|
return {
|
100
102
|
:label => title_for(**options),
|
@@ -103,19 +105,17 @@ module Trenni
|
|
103
105
|
:data => options[:data],
|
104
106
|
}
|
105
107
|
end
|
106
|
-
|
107
|
-
def group(options
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
item(:title => optional_title_for(**options), :value => nil, :builder => builder)
|
112
|
-
end
|
113
|
-
|
114
|
-
builder.capture(&block)
|
108
|
+
|
109
|
+
def group(**options, &block)
|
110
|
+
@builder.tag :optgroup, group_attributes_for(**options) do
|
111
|
+
if options[:optional]
|
112
|
+
item(title: optional_title_for(**options), value: nil)
|
115
113
|
end
|
114
|
+
|
115
|
+
@builder.capture(&block)
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def select_attributes_for(**options)
|
120
120
|
return {
|
121
121
|
:name => name_for(**options),
|
@@ -123,14 +123,19 @@ module Trenni
|
|
123
123
|
:class => options[:class],
|
124
124
|
:multiple => options[:multiple],
|
125
125
|
:data => options[:data],
|
126
|
+
:required => options[:required],
|
126
127
|
}
|
127
128
|
end
|
128
|
-
|
129
|
-
def
|
129
|
+
|
130
|
+
def optional?
|
131
|
+
@options[:optional]
|
132
|
+
end
|
133
|
+
|
134
|
+
def call(&block)
|
130
135
|
Builder.fragment(@builder) do |builder|
|
131
|
-
builder.tag :select, select_attributes_for(
|
132
|
-
if
|
133
|
-
item(:
|
136
|
+
builder.tag :select, select_attributes_for(**@options) do
|
137
|
+
if self.optional?
|
138
|
+
builder << item(title: optional_title_for(**@options), value: nil)
|
134
139
|
end
|
135
140
|
|
136
141
|
builder.capture(self, &block)
|
@@ -27,22 +27,20 @@ module Trenni
|
|
27
27
|
module HTML
|
28
28
|
# Table based select boxes using per-row checkboxes.
|
29
29
|
class RadioSelect
|
30
|
-
def self.call(formatter,
|
31
|
-
instance = self.new(formatter,
|
30
|
+
def self.call(formatter, builder, **options, &block)
|
31
|
+
instance = self.new(formatter, builder, **options)
|
32
32
|
|
33
|
-
instance.call(
|
33
|
+
instance.call(&block)
|
34
34
|
end
|
35
35
|
|
36
|
-
def initialize(formatter,
|
36
|
+
def initialize(formatter, builder, **options)
|
37
37
|
@formatter = formatter
|
38
|
-
@
|
39
|
-
|
38
|
+
@builder = builder
|
40
39
|
@options = options
|
41
|
-
@field = options[:field]
|
42
40
|
|
43
|
-
@
|
41
|
+
@field = options[:field]
|
44
42
|
end
|
45
|
-
|
43
|
+
|
46
44
|
def name_for(**options)
|
47
45
|
@formatter.name_for(**options)
|
48
46
|
end
|
@@ -50,19 +48,19 @@ module Trenni
|
|
50
48
|
def raw_value_for(**options)
|
51
49
|
@formatter.raw_value_for(**options)
|
52
50
|
end
|
53
|
-
|
51
|
+
|
54
52
|
def raw_value
|
55
53
|
@raw_value ||= raw_value_for(**@options)
|
56
54
|
end
|
57
|
-
|
55
|
+
|
58
56
|
def value_for(**options)
|
59
57
|
@formatter.value_for(**options)
|
60
58
|
end
|
61
|
-
|
59
|
+
|
62
60
|
def title_for(**options)
|
63
61
|
@formatter.title_for(**options)
|
64
62
|
end
|
65
|
-
|
63
|
+
|
66
64
|
def radio_attributes_for(**options)
|
67
65
|
return {
|
68
66
|
:type => :radio,
|
@@ -73,9 +71,9 @@ module Trenni
|
|
73
71
|
:data => options[:data],
|
74
72
|
}
|
75
73
|
end
|
76
|
-
|
77
|
-
def item(
|
78
|
-
Builder.fragment
|
74
|
+
|
75
|
+
def item(**options, &block)
|
76
|
+
Builder.fragment do |builder|
|
79
77
|
builder.tag :tr do
|
80
78
|
builder.inline(:td, :class => :handle) do
|
81
79
|
builder.tag :input, radio_attributes_for(**options)
|
@@ -89,7 +87,7 @@ module Trenni
|
|
89
87
|
end
|
90
88
|
end
|
91
89
|
end
|
92
|
-
end
|
90
|
+
end
|
93
91
|
end
|
94
92
|
|
95
93
|
def optional_title_for(**options)
|
@@ -99,13 +97,17 @@ module Trenni
|
|
99
97
|
options[:optional]
|
100
98
|
end
|
101
99
|
end
|
102
|
-
|
103
|
-
def
|
100
|
+
|
101
|
+
def optional?
|
102
|
+
@options[:optional]
|
103
|
+
end
|
104
|
+
|
105
|
+
def call(&block)
|
104
106
|
Builder.fragment(@builder) do |builder|
|
105
107
|
builder.tag :table do
|
106
108
|
builder.tag :tbody do
|
107
|
-
if
|
108
|
-
item(:
|
109
|
+
if self.optional?
|
110
|
+
builder << item(title: optional_title_for(**@options), value: nil)
|
109
111
|
end
|
110
112
|
|
111
113
|
builder.capture(self, &block)
|
@@ -27,7 +27,7 @@ module Trenni
|
|
27
27
|
module Formatters
|
28
28
|
module RelativeTime
|
29
29
|
def self.included(base)
|
30
|
-
base.map(Time) do |object, options|
|
30
|
+
base.map(Time) do |object, **options|
|
31
31
|
current_time = options.fetch(:current_time) {Time.now}
|
32
32
|
|
33
33
|
# Ensure we display the time in localtime, and show the year if it is different:
|
@@ -26,28 +26,30 @@ require 'mapping/model'
|
|
26
26
|
module Trenni
|
27
27
|
module Formatters
|
28
28
|
module TruncatedText
|
29
|
-
def truncated_text(content,
|
29
|
+
def truncated_text(content, length: 30, **options)
|
30
30
|
if content
|
31
|
-
|
32
|
-
|
33
|
-
content = TruncatedText.truncate_text(content, length, options)
|
31
|
+
content = TruncatedText.truncate_text(content, length, **options)
|
34
32
|
|
35
33
|
return self.format(content)
|
36
34
|
end
|
37
35
|
end
|
38
36
|
|
39
|
-
def self.truncate_text(text, truncate_at,
|
37
|
+
def self.truncate_text(text, truncate_at, omission: nil, separator: nil, **options)
|
40
38
|
return text.dup unless text.length > truncate_at
|
41
39
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
omission ||= '...'
|
41
|
+
|
42
|
+
length_with_room_for_omission = truncate_at - omission.length
|
43
|
+
|
44
|
+
stop = nil
|
45
|
+
|
46
|
+
if separator
|
47
|
+
stop = text.rindex(separator, length_with_room_for_omission)
|
48
48
|
end
|
49
49
|
|
50
|
-
|
50
|
+
stop ||= length_with_room_for_omission
|
51
|
+
|
52
|
+
"#{text[0...stop]}#{omission}"
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trenni-formatters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mapping
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '3.
|
33
|
+
version: '3.12'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '3.
|
40
|
+
version: '3.12'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,14 +122,15 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
-
description:
|
126
|
-
email:
|
125
|
+
description:
|
126
|
+
email:
|
127
127
|
executables: []
|
128
128
|
extensions: []
|
129
129
|
extra_rdoc_files: []
|
130
130
|
files:
|
131
131
|
- lib/trenni/formatters.rb
|
132
132
|
- lib/trenni/formatters/formatter.rb
|
133
|
+
- lib/trenni/formatters/html/accept_checkbox.rb
|
133
134
|
- lib/trenni/formatters/html/definition_list_form.rb
|
134
135
|
- lib/trenni/formatters/html/form_formatter.rb
|
135
136
|
- lib/trenni/formatters/html/label_form.rb
|
@@ -144,7 +145,7 @@ licenses:
|
|
144
145
|
- MIT
|
145
146
|
metadata:
|
146
147
|
funding_uri: https://github.com/sponsors/ioquatix/
|
147
|
-
post_install_message:
|
148
|
+
post_install_message:
|
148
149
|
rdoc_options: []
|
149
150
|
require_paths:
|
150
151
|
- lib
|
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
version: '0'
|
161
162
|
requirements: []
|
162
163
|
rubygems_version: 3.1.2
|
163
|
-
signing_key:
|
164
|
+
signing_key:
|
164
165
|
specification_version: 4
|
165
166
|
summary: Formatters for Trenni, to assist with typical views and form based interfaces.
|
166
167
|
test_files: []
|