trenni-formatters 2.8.1 → 2.10.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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -41,8 +43,8 @@ module Trenni
41
43
  @builder = builder
42
44
  end
43
45
 
44
- def name_for(options)
45
- if name = @formatter.name_for(options)
46
+ def name_for(**options)
47
+ if name = @formatter.name_for(**options)
46
48
  if options[:multiple]
47
49
  name = "#{name}[]"
48
50
  end
@@ -51,26 +53,26 @@ module Trenni
51
53
  end
52
54
  end
53
55
 
54
- def raw_value_for(options)
55
- @formatter.raw_value_for(options)
56
+ def raw_value_for(**options)
57
+ @formatter.raw_value_for(**options)
56
58
  end
57
59
 
58
60
  def raw_value
59
- @raw_value ||= raw_value_for(@options)
61
+ @raw_value ||= raw_value_for(**@options)
60
62
  end
61
63
 
62
- def value_for(options)
63
- @formatter.value_for(options)
64
+ def value_for(**options)
65
+ @formatter.value_for(**options)
64
66
  end
65
67
 
66
- def title_for(options)
67
- @formatter.title_for(options)
68
+ def title_for(**options)
69
+ @formatter.title_for(**options)
68
70
  end
69
71
 
70
- def option_attributes_for(options)
72
+ def option_attributes_for(**options)
71
73
  return {
72
- :value => value_for(options),
73
- :selected => options.fetch(:selected){ raw_value == raw_value_for(options) },
74
+ :value => value_for(**options),
75
+ :selected => options.fetch(:selected) {raw_value == raw_value_for(**options)},
74
76
  :id => options[:id],
75
77
  :class => options[:class],
76
78
  :data => options[:data],
@@ -81,11 +83,11 @@ module Trenni
81
83
  options[:field] ||= 'id'
82
84
 
83
85
  Builder.fragment(builder) do |builder|
84
- builder.inline(:option, option_attributes_for(options)) { builder.text title_for(options) }
86
+ builder.inline(:option, option_attributes_for(**options)) {builder.text title_for(**options)}
85
87
  end
86
88
  end
87
89
 
88
- def optional_title_for(options)
90
+ def optional_title_for(**options)
89
91
  if options[:optional] == true
90
92
  options[:blank] || ''
91
93
  else
@@ -93,9 +95,9 @@ module Trenni
93
95
  end
94
96
  end
95
97
 
96
- def group_attributes_for(options)
98
+ def group_attributes_for(**options)
97
99
  return {
98
- :label => title_for(options),
100
+ :label => title_for(**options),
99
101
  :id => options[:id],
100
102
  :class => options[:class],
101
103
  :data => options[:data],
@@ -104,9 +106,9 @@ module Trenni
104
106
 
105
107
  def group(options = {}, &block)
106
108
  Builder.fragment(@builder) do |builder|
107
- builder.tag :optgroup, group_attributes_for(options) do
109
+ builder.tag :optgroup, group_attributes_for(**options) do
108
110
  if options[:optional]
109
- item(:title => optional_title_for(options), :value => nil, :builder => builder)
111
+ item(:title => optional_title_for(**options), :value => nil, :builder => builder)
110
112
  end
111
113
 
112
114
  builder.capture(&block)
@@ -114,9 +116,9 @@ module Trenni
114
116
  end
115
117
  end
116
118
 
117
- def select_attributes_for(options)
119
+ def select_attributes_for(**options)
118
120
  return {
119
- :name => name_for(options),
121
+ :name => name_for(**options),
120
122
  :id => options[:id],
121
123
  :class => options[:class],
122
124
  :multiple => options[:multiple],
@@ -126,9 +128,9 @@ module Trenni
126
128
 
127
129
  def call(options = {}, &block)
128
130
  Builder.fragment(@builder) do |builder|
129
- builder.tag :select, select_attributes_for(options) do
131
+ builder.tag :select, select_attributes_for(**options) do
130
132
  if options[:optional]
131
- item(:title => optional_title_for(options), :value => nil, :builder => builder)
133
+ item(:title => optional_title_for(**options), :value => nil, :builder => builder)
132
134
  end
133
135
 
134
136
  builder.capture(self, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -41,33 +43,33 @@ module Trenni
41
43
  @builder = builder
42
44
  end
43
45
 
44
- def name_for(options)
45
- @formatter.name_for(options)
46
+ def name_for(**options)
47
+ @formatter.name_for(**options)
46
48
  end
47
49
 
48
- def raw_value_for(options)
49
- @formatter.raw_value_for(options)
50
+ def raw_value_for(**options)
51
+ @formatter.raw_value_for(**options)
50
52
  end
51
53
 
52
54
  def raw_value
53
- @raw_value ||= raw_value_for(@options)
55
+ @raw_value ||= raw_value_for(**@options)
54
56
  end
55
57
 
56
- def value_for(options)
57
- @formatter.value_for(options)
58
+ def value_for(**options)
59
+ @formatter.value_for(**options)
58
60
  end
59
61
 
60
- def title_for(options)
61
- @formatter.title_for(options)
62
+ def title_for(**options)
63
+ @formatter.title_for(**options)
62
64
  end
63
65
 
64
- def radio_attributes_for(options)
66
+ def radio_attributes_for(**options)
65
67
  return {
66
68
  :type => :radio,
67
69
  :name => @field,
68
70
  # We set a default value to empty string, otherwise it becomes "on".
69
- :value => value_for(options) || "",
70
- :checked => options.fetch(:selected){ raw_value == raw_value_for(options) },
71
+ :value => value_for(**options) || "",
72
+ :checked => options.fetch(:selected) {raw_value == raw_value_for(**options)},
71
73
  :data => options[:data],
72
74
  }
73
75
  end
@@ -76,21 +78,21 @@ module Trenni
76
78
  Builder.fragment(builder) do |builder|
77
79
  builder.tag :tr do
78
80
  builder.inline(:td, :class => :handle) do
79
- builder.tag :input, radio_attributes_for(options)
81
+ builder.tag :input, radio_attributes_for(**options)
80
82
  end
81
83
 
82
84
  builder.inline(:td, :class => :item) do
83
85
  if block_given?
84
86
  builder.capture(self, &block)
85
87
  else
86
- builder.text title_for(options)
88
+ builder.text title_for(**options)
87
89
  end
88
90
  end
89
91
  end
90
92
  end >> block
91
93
  end
92
94
 
93
- def optional_title_for(options)
95
+ def optional_title_for(**options)
94
96
  if options[:optional] == true
95
97
  options[:blank] || ''
96
98
  else
@@ -103,7 +105,7 @@ module Trenni
103
105
  builder.tag :table do
104
106
  builder.tag :tbody do
105
107
  if options[:optional]
106
- item(:title => optional_title_for(options), :value => nil, :builder => builder)
108
+ item(:title => optional_title_for(**options), :value => nil, :builder => builder)
107
109
  end
108
110
 
109
111
  builder.capture(self, &block)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -18,20 +20,18 @@
18
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
21
  # THE SOFTWARE.
20
22
 
21
- require 'sanitize'
22
- require 'kramdown'
23
+ require 'markly'
23
24
 
24
25
  require 'trenni/markup'
26
+ require 'trenni/sanitize/fragment'
25
27
 
26
28
  module Trenni
27
29
  module Formatters
28
30
  module Markdown
29
- def markdown(text)
30
- config = Sanitize::Config::BASIC.dup
31
-
32
- config[:elements] += ['h1', 'h2', 'h3']
31
+ def markdown(text, filter = Trenni::Sanitize::Fragment, **options)
32
+ root = Markly.parse(text, **options)
33
33
 
34
- html = Sanitize.clean(Kramdown::Document.new(text).to_html, config)
34
+ html = filter.parse(root.to_html).output
35
35
 
36
36
  return MarkupString.raw(html)
37
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
4
  #
3
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -20,6 +22,6 @@
20
22
 
21
23
  module Trenni
22
24
  module Formatters
23
- VERSION = "2.8.1"
25
+ VERSION = "2.10.0"
24
26
  end
25
27
  end
metadata CHANGED
@@ -1,43 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.1
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2020-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: trenni
14
+ name: mapping
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.4'
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.4'
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: mapping
28
+ name: trenni
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '3.4'
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: '1.1'
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bake-bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bake-modernize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
41
83
  - !ruby/object:Gem::Dependency
42
84
  name: bundler
43
85
  requirement: !ruby/object:Gem::Requirement
@@ -53,21 +95,21 @@ dependencies:
53
95
  - !ruby/object:Gem::Version
54
96
  version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
- name: rspec
98
+ name: covered
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
- - - "~>"
101
+ - - ">="
60
102
  - !ruby/object:Gem::Version
61
- version: '3.4'
103
+ version: '0'
62
104
  type: :development
63
105
  prerelease: false
64
106
  version_requirements: !ruby/object:Gem::Requirement
65
107
  requirements:
66
- - - "~>"
108
+ - - ">="
67
109
  - !ruby/object:Gem::Version
68
- version: '3.4'
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: rake
112
+ name: rspec
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - ">="
@@ -80,44 +122,28 @@ dependencies:
80
122
  - - ">="
81
123
  - !ruby/object:Gem::Version
82
124
  version: '0'
83
- description: "\tTrenni is a templating system, and these formatters assist with the
84
- development\n\tof typical view and form based web interface. A formatter is a high-level\n\tadapter
85
- that turns model data into presentation text.\n\n\tFormatters are designed to be
86
- customised, typically per-project, for specific\n\tformatting needs.\n"
87
- email:
88
- - samuel.williams@oriontransfer.co.nz
125
+ description:
126
+ email:
89
127
  executables: []
90
128
  extensions: []
91
129
  extra_rdoc_files: []
92
130
  files:
93
- - ".gitignore"
94
- - ".rspec"
95
- - ".simplecov"
96
- - ".travis.yml"
97
- - Gemfile
98
- - README.md
99
- - Rakefile
100
131
  - lib/trenni/formatters.rb
101
132
  - lib/trenni/formatters/formatter.rb
102
133
  - lib/trenni/formatters/html/definition_list_form.rb
103
134
  - lib/trenni/formatters/html/form_formatter.rb
135
+ - lib/trenni/formatters/html/label_form.rb
104
136
  - lib/trenni/formatters/html/option_select.rb
105
137
  - lib/trenni/formatters/html/radio_select.rb
106
138
  - lib/trenni/formatters/markdown.rb
107
139
  - lib/trenni/formatters/relative_time.rb
108
140
  - lib/trenni/formatters/truncated_text.rb
109
141
  - lib/trenni/formatters/version.rb
110
- - spec/trenni/formatters/formatters_spec.rb
111
- - spec/trenni/formatters/html/form_formatter_spec.rb
112
- - spec/trenni/formatters/html/option_select_spec.rb
113
- - spec/trenni/formatters/html/radio_select_spec.rb
114
- - spec/trenni/formatters/markdown_spec.rb
115
- - spec/trenni/formatters/relative_time_spec.rb
116
- - spec/trenni/formatters/truncated_text_spec.rb
117
- - trenni-formatters.gemspec
118
142
  homepage: https://github.com/ioquatix/trenni-formatters
119
- licenses: []
120
- metadata: {}
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ funding_uri: https://github.com/sponsors/ioquatix/
121
147
  post_install_message:
122
148
  rdoc_options: []
123
149
  require_paths:
@@ -126,22 +152,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
152
  requirements:
127
153
  - - ">="
128
154
  - !ruby/object:Gem::Version
129
- version: '0'
155
+ version: '2.5'
130
156
  required_rubygems_version: !ruby/object:Gem::Requirement
131
157
  requirements:
132
158
  - - ">="
133
159
  - !ruby/object:Gem::Version
134
160
  version: '0'
135
161
  requirements: []
136
- rubygems_version: 3.0.1
162
+ rubygems_version: 3.1.2
137
163
  signing_key:
138
164
  specification_version: 4
139
165
  summary: Formatters for Trenni, to assist with typical views and form based interfaces.
140
- test_files:
141
- - spec/trenni/formatters/formatters_spec.rb
142
- - spec/trenni/formatters/html/form_formatter_spec.rb
143
- - spec/trenni/formatters/html/option_select_spec.rb
144
- - spec/trenni/formatters/html/radio_select_spec.rb
145
- - spec/trenni/formatters/markdown_spec.rb
146
- - spec/trenni/formatters/relative_time_spec.rb
147
- - spec/trenni/formatters/truncated_text_spec.rb
166
+ test_files: []