berns 4.0.0 → 4.1.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/README.org +23 -22
- data/lib/berns/berns.bundle +0 -0
- data/lib/berns/builder.rb +33 -19
- data/lib/berns/version.rb +1 -1
- metadata +2 -5
- data/ext/berns/sds.c +0 -1300
- data/ext/berns/sds.h +0 -274
- data/ext/berns/sdsalloc.h +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb2de0ba05a5e234fa5cef7edf3a222411222d0743c0e69492c1e1d5e53541bb
|
4
|
+
data.tar.gz: f62f2273f787a46aa18784b668f1110adb80a1bbb8c33226c9c58e585d5acec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d8fb46aeb4dc948729b36bbb6a794625618c34742ee2b18024d1cde99bda330b21bd7fb890bd241010a9b60e956c81fe401c3036464a90d28fb4ebca11ba621
|
7
|
+
data.tar.gz: c7c430ae90da5be3b93f15d1ac6ab2bba300b89558cfb131af276b2af9d2e82b118fa0691000402bf7e982e13406defc275c786e2e512304041f660afe0b53cc
|
data/README.org
CHANGED
@@ -125,12 +125,30 @@ end
|
|
125
125
|
Within the block provided to =Berns::Builder.new= every standard element method,
|
126
126
|
void element method, =#element=, and =#void= are available as methods and each
|
127
127
|
time you use one of those methods the result is appended to an internal buffer.
|
128
|
-
In addition, the =#text= method
|
129
|
-
|
128
|
+
In addition, the =#text= method appends HTML escaped text to the buffer and
|
129
|
+
=#raw= appends text to the buffer without modification.
|
130
130
|
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
The block provided to =Berns::Builder.new= can take both positional and keyword
|
132
|
+
arguments.
|
133
|
+
|
134
|
+
#+begin_src ruby
|
135
|
+
template = Berns::Builder.new do |content, title:|
|
136
|
+
h1 { title }
|
137
|
+
p(class: 'paragraph') { content }
|
138
|
+
end
|
139
|
+
|
140
|
+
template.call('Some text.', title: 'The title') # =>
|
141
|
+
# <h1>
|
142
|
+
# The title
|
143
|
+
# </h1>
|
144
|
+
# <p>
|
145
|
+
# Some text.
|
146
|
+
# </p>
|
147
|
+
#+end_src
|
148
|
+
|
149
|
+
Once initialized, the =#call= method will render the template to a string. Any
|
150
|
+
arguments, positional or keyword, are passed through as-is to the block provided
|
151
|
+
to =#new=.
|
134
152
|
|
135
153
|
#+begin_src ruby
|
136
154
|
string = template.call # =>
|
@@ -168,23 +186,6 @@ end # =>
|
|
168
186
|
# </p>
|
169
187
|
#+end_src
|
170
188
|
|
171
|
-
Lastly, the block provided to =Berns::Builder.new= can take both positional and
|
172
|
-
keyword arguments.
|
173
|
-
|
174
|
-
#+begin_src ruby
|
175
|
-
template = Berns::Builder.new do |content, title:|
|
176
|
-
h1 { title }
|
177
|
-
p(class: 'paragraph') { content }
|
178
|
-
end
|
179
|
-
|
180
|
-
template.call('Some text.', title: 'The title') # =>
|
181
|
-
# <h1>
|
182
|
-
# The title
|
183
|
-
# </h1>
|
184
|
-
# <p>
|
185
|
-
# Some text.
|
186
|
-
# </p>
|
187
|
-
#+end_src
|
188
189
|
|
189
190
|
*** Standard and void elements
|
190
191
|
|
data/lib/berns/berns.bundle
CHANGED
Binary file
|
data/lib/berns/builder.rb
CHANGED
@@ -5,22 +5,28 @@ module Berns
|
|
5
5
|
# An HTML builder DSL using Berns' HTML methods.
|
6
6
|
class Builder
|
7
7
|
def initialize(&block)
|
8
|
+
raise(ArgumentError, 'Berns::Builder initialized without a block argument', caller) unless block
|
9
|
+
|
8
10
|
@block = block
|
9
|
-
@buffer = +''
|
10
11
|
end
|
11
12
|
|
12
13
|
# @return [String]
|
13
|
-
def call(*args, **
|
14
|
-
|
15
|
-
|
16
|
-
end
|
14
|
+
def call(*args, **kwargs)
|
15
|
+
@buffer = +''
|
16
|
+
content = instance_exec(*args, **kwargs, &@block)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
@buffer.
|
18
|
+
# This is a special case where the buffer hasn't been appended to but the
|
19
|
+
# block returned a string.
|
20
|
+
if @buffer.empty? && content.is_a?(String)
|
21
|
+
Berns.escape_html(content).freeze
|
22
|
+
else
|
23
|
+
@buffer.freeze
|
24
|
+
end
|
21
25
|
end
|
26
|
+
alias to_s call
|
27
|
+
alias to_str call
|
22
28
|
|
23
|
-
# Append text to the buffer.
|
29
|
+
# Append HTML escaped text to the buffer.
|
24
30
|
#
|
25
31
|
# @param string [String]
|
26
32
|
# @return [String]
|
@@ -28,31 +34,39 @@ module Berns
|
|
28
34
|
@buffer << Berns.escape_html(string.to_s)
|
29
35
|
end
|
30
36
|
|
37
|
+
# Append raw text to the buffer.
|
38
|
+
#
|
39
|
+
# @param string [String]
|
40
|
+
# @return [String]
|
41
|
+
def raw(string)
|
42
|
+
@buffer << string.to_s
|
43
|
+
end
|
44
|
+
|
31
45
|
# Append an arbitrary standard element to the buffer.
|
32
46
|
#
|
33
47
|
# @return [String]
|
34
|
-
def element(*args, **
|
35
|
-
content = Builder.new
|
36
|
-
@buffer << Berns.element(*args, **
|
48
|
+
def element(elm, *args, **kwargs, &block)
|
49
|
+
content = Builder.new(&block).call if block
|
50
|
+
@buffer << Berns.element(elm, *args, **kwargs) { content }
|
37
51
|
end
|
38
52
|
|
39
53
|
# Append an arbitrary void element to the buffer.
|
40
54
|
#
|
41
55
|
# @return [String]
|
42
|
-
def void(
|
43
|
-
@buffer << Berns.void(
|
56
|
+
def void(...)
|
57
|
+
@buffer << Berns.void(...)
|
44
58
|
end
|
45
59
|
|
46
60
|
Berns::STANDARD.each do |meth|
|
47
|
-
define_method(meth) do |*args, **
|
48
|
-
content = Builder.new
|
49
|
-
@buffer << Berns.send(meth, *args, **
|
61
|
+
define_method(meth) do |*args, **kwargs, &block|
|
62
|
+
content = Builder.new(&block).call if block
|
63
|
+
@buffer << Berns.send(meth, *args, **kwargs) { content }
|
50
64
|
end
|
51
65
|
end
|
52
66
|
|
53
67
|
Berns::VOID.each do |meth|
|
54
|
-
define_method(meth) do |*args, **
|
55
|
-
@buffer << Berns.send(meth, *args, **
|
68
|
+
define_method(meth) do |*args, **kwargs|
|
69
|
+
@buffer << Berns.send(meth, *args, **kwargs)
|
56
70
|
end
|
57
71
|
end
|
58
72
|
end
|
data/lib/berns/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: berns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taylor Beck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A utility library for generating HTML strings.
|
15
15
|
email:
|
@@ -26,9 +26,6 @@ files:
|
|
26
26
|
- ext/berns/extconf.rb
|
27
27
|
- ext/berns/hescape.c
|
28
28
|
- ext/berns/hescape.h
|
29
|
-
- ext/berns/sds.c
|
30
|
-
- ext/berns/sds.h
|
31
|
-
- ext/berns/sdsalloc.h
|
32
29
|
- lib/berns.rb
|
33
30
|
- lib/berns/berns.bundle
|
34
31
|
- lib/berns/builder.rb
|