trenni 3.12.0 → 3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24fa931d5bc2440544d99451affb9fb2a2e356f69ad6a5c0d5da6133d58ff45b
4
- data.tar.gz: 84ed87a7f93c6b306220fe10e3822b222962db66068664df4afd29b432823864
3
+ metadata.gz: da3b501fe924214fa832ee9d8e66bc162318e20907d8f66e25e82400ed37fb7b
4
+ data.tar.gz: ac5611a7572697fe05d1bef571f78c17a3067dc9382362188ce46626a2ca7543
5
5
  SHA512:
6
- metadata.gz: 57068d50f31f1d6bdbd2976026da38b57c279350f2269f8437546245526a1483e57d7619f02f5e2c5e52f2d339e3ecb524951516173bafa46d8488156d6ddc2c
7
- data.tar.gz: 969c619651b2af237511d9230f15678c51d223266d37e6f3ab7c5861d39866c8322f89376124017708d2bddba3f3e446700f9c9b1a8448bc98fd3f9a7d1ac7f2
6
+ metadata.gz: a4efb7f90d9030a0239e3600f7ae971479183a93b1808694648d86ac7364d142f9a94fd77e673b7fe1e179c5c07549cd9303e8555b22555532b2279427bcadb1
7
+ data.tar.gz: 2c3bd0c40aff707e27e8d1287b7bd7b2aa13ac2d5c8f74e3d7d38c7674b53bda6158204eeabb2558237307313aa4e1b1cfce1c4c291b6200e6abcdb7dffeb593
@@ -129,14 +129,26 @@ module Trenni
129
129
  end
130
130
 
131
131
  # Begin an inline tag.
132
- def inline(name, attributes = {}, &block)
133
- indent = @indent
132
+ def inline_tag(name, attributes = {}, &block)
133
+ original_indent = @indent
134
134
 
135
135
  full_tag(name, attributes, @indent, false) do
136
136
  @indent = false
137
137
  yield if block_given?
138
- @indent = indent
139
138
  end
139
+ ensure
140
+ @indent = original_indent
141
+ end
142
+
143
+ alias inline inline_tag
144
+
145
+ def inline!
146
+ original_indent = @indent
147
+ @indent = false
148
+
149
+ yield
150
+ ensure
151
+ @indent = original_indent
140
152
  end
141
153
 
142
154
  def text(content)
@@ -162,7 +174,9 @@ module Trenni
162
174
  return unless content
163
175
 
164
176
  if content.is_a?(Fragment)
165
- content.call(self)
177
+ inline! do
178
+ content.call(self)
179
+ end
166
180
  else
167
181
  Markup.append(@output, content)
168
182
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Trenni
24
- VERSION = "3.12.0"
24
+ VERSION = "3.13.0"
25
25
  end
@@ -21,22 +21,34 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- require 'trenni'
24
+ require 'trenni/builder'
25
25
 
26
- module Trenni::BuilderSpec
27
- describe 'Trenni::Builder#tag' do
28
- subject {Trenni::Builder.new}
29
-
30
- it "should format nested attributes" do
31
- subject.tag('div', data: {id: 10})
32
-
33
- expect(subject.output).to be == '<div data-id="10"/>'
26
+ RSpec.describe Trenni::Builder do
27
+ it "should produce valid html" do
28
+ subject.doctype
29
+ subject.tag('html') do
30
+ subject.tag('head') do
31
+ subject.inline('title') do
32
+ subject.text('Hello World')
33
+ end
34
+ end
35
+ subject.tag('body') do
36
+ end
34
37
  end
38
+
39
+ expect(subject.output).to be == <<~HTML.chomp
40
+ <!DOCTYPE html>
41
+ <html>
42
+ <head>
43
+ <title>Hello World</title>
44
+ </head>
45
+ <body>
46
+ </body>
47
+ </html>
48
+ HTML
35
49
  end
36
50
 
37
- describe 'Trenni::Builder#fragment' do
38
- let(:builder) {Trenni::Builder.new}
39
-
51
+ describe '.fragment' do
40
52
  it "should use an existing builder" do
41
53
  result = Trenni::Builder.fragment do |builder|
42
54
  end
@@ -47,61 +59,59 @@ module Trenni::BuilderSpec
47
59
  it "should use an existing builder" do
48
60
  expect(Trenni::Builder).to receive(:new).and_call_original
49
61
 
50
- result = Trenni::Builder.fragment(builder) do |builder|
62
+ result = Trenni::Builder.fragment(subject) do |builder|
51
63
  end
52
64
 
53
65
  expect(result).to be_nil
54
66
  end
55
67
  end
56
68
 
57
- describe Trenni::Builder do
58
- describe '#<<' do
59
- it 'can append text' do
60
- subject << 'text'
61
- expect(subject.output).to be == "text"
62
- end
69
+ describe '#tag' do
70
+ it "should format nested attributes" do
71
+ subject.tag('div', data: {id: 10})
63
72
 
64
- it "doesn't append nil" do
65
- subject << nil
66
- expect(subject.output).to be == ""
67
- end
73
+ expect(subject.output).to be == '<div data-id="10"/>'
68
74
  end
69
75
 
70
- it 'should be able to append nil' do
71
- expect{subject.append(nil)}.to_not raise_error
76
+ it "should indent self-closing tag correctly" do
77
+ builder = Trenni::Builder.new
78
+
79
+ builder.tag('foo') {builder.tag('bar')}
80
+
81
+ expect(builder.output).to be == <<~HTML.chomp
82
+ <foo>
83
+ <bar/>
84
+ </foo>
85
+ HTML
72
86
  end
73
87
 
74
- it 'should append existing markup' do
75
- subject.tag("outer") do
76
- subject.append("<inner>\n\t<nested/>\n</inner>")
77
- end
78
-
79
- expect(subject.output).to be == "<outer>\n\t<inner>\n\t\t<nested/>\n\t</inner>\n</outer>"
88
+ it "should support compact attributes" do
89
+ subject.tag :option, :required => true
90
+ expect(subject.output).to be == %Q{<option required/>}
80
91
  end
81
92
 
82
- it "should produce valid html" do
83
- subject.doctype
84
- subject.tag('html') do
85
- subject.tag('head') do
86
- subject.inline('title') do
87
- subject.text('Hello World')
88
- end
89
- end
90
- subject.tag('body') do
91
- end
92
- end
93
-
94
- expect(subject.output).to be == "<!DOCTYPE html>\n<html>\n\t<head>\n\t\t<title>Hello World</title>\n\t</head>\n\t<body>\n\t</body>\n</html>"
93
+ it "should output without changing escaped characters" do
94
+ subject.tag "section", :'data-text' => 'foo\nbar'
95
+ expect(subject.output).to be == '<section data-text="foo\nbar"/>'
95
96
  end
96
97
 
97
- it "should indent self-closing tag correctly" do
98
- builder = Trenni::Builder.new
99
-
100
- builder.tag('foo') { builder.tag('bar') }
101
-
102
- expect(builder.output).to be == "<foo>\n\t<bar/>\n</foo>"
98
+ it "should order array attributes as specified" do
99
+ subject.tag :t, [[:a, 10], [:b, 20]]
100
+ expect(subject.output).to be == %Q{<t a="10" b="20"/>}
103
101
  end
104
102
 
103
+ it "should order hash attributes as specified" do
104
+ subject.tag :t, :b => 20, :a => 10
105
+ expect(subject.output).to be == %Q{<t b="20" a="10"/>}
106
+ end
107
+
108
+ it "shouldn't output attributes with nil value" do
109
+ subject.tag :t, [[:a, 10], [:b, nil]]
110
+ expect(subject.output).to be == %Q{<t a="10"/>}
111
+ end
112
+ end
113
+
114
+ describe '#inline' do
105
115
  it "should produce inline html" do
106
116
  subject.inline("div") do
107
117
  subject.tag("strong") do
@@ -114,6 +124,20 @@ module Trenni::BuilderSpec
114
124
  expect(subject.output).to be == "<div><strong>Hello</strong>World!</div>"
115
125
  end
116
126
 
127
+ it "can inline fragments" do
128
+ subject.inline! do
129
+ subject.inline('a') do
130
+ subject << "Hello"
131
+ end
132
+
133
+ subject.inline('a') do
134
+ subject << "World"
135
+ end
136
+ end
137
+
138
+ expect(subject.output).to be == "<a>Hello</a><a>World</a>"
139
+ end
140
+
117
141
  it "escapes attributes and text correctly" do
118
142
  subject.inline :foo, :bar => %Q{"Hello World"} do
119
143
  subject.text %Q{if x < 10}
@@ -121,30 +145,37 @@ module Trenni::BuilderSpec
121
145
 
122
146
  expect(subject.output).to be == %Q{<foo bar="&quot;Hello World&quot;">if x &lt; 10</foo>}
123
147
  end
124
-
125
- it "should support compact attributes" do
126
- subject.tag :option, :required => true
127
- expect(subject.output).to be == %Q{<option required/>}
128
- end
129
-
130
- it "should output without changing escaped characters" do
131
- subject.tag "section", :'data-text' => 'foo\nbar'
132
- expect(subject.output).to be == '<section data-text="foo\nbar"/>'
148
+ end
149
+
150
+ describe '#<<' do
151
+ it 'can append text' do
152
+ subject << 'text'
153
+ expect(subject.output).to be == "text"
133
154
  end
134
155
 
135
- it "should order array attributes as specified" do
136
- subject.tag :t, [[:a, 10], [:b, 20]]
137
- expect(subject.output).to be == %Q{<t a="10" b="20"/>}
156
+ it "doesn't append nil" do
157
+ subject << nil
158
+ expect(subject.output).to be == ""
138
159
  end
139
-
140
- it "should order hash attributes as specified" do
141
- subject.tag :t, :b => 20, :a => 10
142
- expect(subject.output).to be == %Q{<t b="20" a="10"/>}
160
+ end
161
+
162
+ describe '#append' do
163
+ it 'should be able to append nil' do
164
+ expect{subject.append(nil)}.to_not raise_error
143
165
  end
144
166
 
145
- it "shouldn't output attributes with nil value" do
146
- subject.tag :t, [[:a, 10], [:b, nil]]
147
- expect(subject.output).to be == %Q{<t a="10"/>}
167
+ it 'should append existing markup' do
168
+ subject.tag("outer") do
169
+ subject.append("<inner>\n\t<nested/>\n</inner>")
170
+ end
171
+
172
+ expect(subject.output).to be == <<~HTML.chomp
173
+ <outer>
174
+ <inner>
175
+ <nested/>
176
+ </inner>
177
+ </outer>
178
+ HTML
148
179
  end
149
180
  end
150
181
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.12.0
4
+ version: 3.13.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: 2020-06-07 00:00:00.000000000 Z
11
+ date: 2020-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler