fun_html 0.3.0 → 0.3.2
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/fun_html/attribute.rb +7 -1
- data/lib/fun_html/template.rb +18 -1
- data/lib/fun_html/version.rb +1 -1
- data/lib/fun_html/writer.rb +9 -6
- data/rbi/fun_html.rbi +5 -0
- data/rbi/fun_html.rbx +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42c0e91bac640eb6118eb6905396a24e3cb7913c1c1dcff1adfea7a6b2b42d7
|
4
|
+
data.tar.gz: 11f959d558113fccd719e4455efcefe65c76163d9814dbdcd208db2e29319fc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42ff2f6eb4ae91f8a511c7b1f6e68362aeb9eb0e099e7fb3f65423c6c9bc1b4eec6799ade19d4bde04607b2a748c139c55d2e4e8c0b6553e4dc6b4784a9cf3fb
|
7
|
+
data.tar.gz: 48c4bc781e7467655e5b1fd02bd9bb202cf76e8a3794360fa74f8dfcebfadb4b40da9a4e60a8beb88ecda7515ee392bf967bd79a14f077a09dc9be46a5515b45
|
data/lib/fun_html/attribute.rb
CHANGED
@@ -32,7 +32,9 @@ module FunHtml
|
|
32
32
|
|
33
33
|
# only allow nil or objects that respond to `safe_attribute`
|
34
34
|
def self.to_html(attr)
|
35
|
-
attr
|
35
|
+
return '' if attr.nil?
|
36
|
+
|
37
|
+
attr.safe_attribute
|
36
38
|
end
|
37
39
|
|
38
40
|
# create a new Attribute object to create reuseable attributes
|
@@ -55,6 +57,10 @@ module FunHtml
|
|
55
57
|
write(" data-#{suffix}=\"", value)
|
56
58
|
end
|
57
59
|
|
60
|
+
def attribute(name, value)
|
61
|
+
write(" #{name}=\"", value)
|
62
|
+
end
|
63
|
+
|
58
64
|
# CSS class name(s) for styling, the name changed to protect the Ruby.
|
59
65
|
def klass(value)
|
60
66
|
write(' class="', value)
|
data/lib/fun_html/template.rb
CHANGED
@@ -55,9 +55,26 @@ module FunHtml
|
|
55
55
|
obj
|
56
56
|
end
|
57
57
|
|
58
|
+
JOIN_ERROR = <<~TXT.freeze
|
59
|
+
You can not join templates which are created by the parent template.
|
60
|
+
|
61
|
+
This will fail:
|
62
|
+
|
63
|
+
FunHtml::Template.start { |t| t.join [t.text("hello")] }
|
64
|
+
|
65
|
+
Instead only join new templates
|
66
|
+
FunHtml::Template.start do |t|
|
67
|
+
t.join [FunHtml::Template.start { |x| x.text('hello') }]
|
68
|
+
end
|
69
|
+
TXT
|
70
|
+
|
58
71
|
# join an array of other templates into this template.
|
59
72
|
def join(templates)
|
60
|
-
templates.each
|
73
|
+
templates.each do |t|
|
74
|
+
raise JOIN_ERROR if t == self
|
75
|
+
|
76
|
+
@__buffer << t.render
|
77
|
+
end
|
61
78
|
self
|
62
79
|
end
|
63
80
|
|
data/lib/fun_html/version.rb
CHANGED
data/lib/fun_html/writer.rb
CHANGED
@@ -10,15 +10,15 @@ module FunHtml
|
|
10
10
|
include Kernel
|
11
11
|
|
12
12
|
def initialize
|
13
|
-
@__buffer =
|
13
|
+
@__buffer = String.new(capacity: 1024)
|
14
14
|
end
|
15
15
|
|
16
16
|
# Render produces the HTML string and clears the buffer.
|
17
17
|
def render
|
18
|
-
@__buffer
|
19
|
-
ensure
|
18
|
+
result = @__buffer
|
20
19
|
# empty the buffer to prevent double rendering
|
21
|
-
@__buffer =
|
20
|
+
@__buffer = String.new(capacity: 1024)
|
21
|
+
result
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
@@ -33,9 +33,12 @@ module FunHtml
|
|
33
33
|
CLOSE_VOID = '/>'
|
34
34
|
|
35
35
|
def write(open, close, attr = nil, closing_char: CLOSE, &block)
|
36
|
-
|
36
|
+
if attr
|
37
|
+
@__buffer << open << Attribute.to_html(attr) << closing_char
|
38
|
+
else
|
39
|
+
@__buffer << open << closing_char
|
40
|
+
end
|
37
41
|
|
38
|
-
@__buffer << closing_char
|
39
42
|
yield self if block
|
40
43
|
@__buffer << close
|
41
44
|
|
data/rbi/fun_html.rbi
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
module FunHtml
|
5
5
|
class Template
|
6
|
+
JOIN_ERROR = T.let(T.unsafe(nil), String)
|
7
|
+
|
6
8
|
include FunHtml::Writer
|
7
9
|
include FunHtml::SpecElements::HTMLAllElements
|
8
10
|
|
@@ -70,6 +72,9 @@ module FunHtml
|
|
70
72
|
sig { params(suffix: String, value: String).returns(FunHtml::Attribute) }
|
71
73
|
def data(suffix, value); end
|
72
74
|
|
75
|
+
sig { params(name: String, value: String).returns(FunHtml::Attribute) }
|
76
|
+
def attribute(name, value); end
|
77
|
+
|
73
78
|
sig { params(value: String).returns(FunHtml::Attribute) }
|
74
79
|
def klass(value); end
|
75
80
|
|
data/rbi/fun_html.rbx
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
module FunHtml
|
5
5
|
class Template
|
6
|
+
JOIN_ERROR = T.let(T.unsafe(nil), String)
|
7
|
+
|
6
8
|
include FunHtml::Writer
|
7
9
|
include FunHtml::SpecElements::HTMLAllElements
|
8
10
|
|
@@ -70,6 +72,9 @@ module FunHtml
|
|
70
72
|
sig { params(suffix: String, value: String).returns(FunHtml::Attribute) }
|
71
73
|
def data(suffix, value); end
|
72
74
|
|
75
|
+
sig { params(name: String, value: String).returns(FunHtml::Attribute) }
|
76
|
+
def attribute(name, value); end
|
77
|
+
|
73
78
|
sig { params(value: String).returns(FunHtml::Attribute) }
|
74
79
|
def klass(value); end
|
75
80
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fun_html
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Weir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: It probably is not much fun, despite the name.
|
14
14
|
email:
|