html-native 0.2.4 → 0.3.4
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/html-native.rb +16 -1
- data/lib/html-native/builder.rb +8 -8
- data/lib/html-native/constants.rb +1 -1
- data/lib/html-native/logic.rb +54 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed3076751962fc9a51ff463fbe86f2716fc06522f838def97ba375270ca81099
|
4
|
+
data.tar.gz: b03dca13fa0ff38781755ab1912cb3890fa8f2210b1cbb2bc9cb5de8f469a6fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a55f9561c6e3cc998e3616bf685a0ff5700284bfe3a68c08cc1b9583e6f2daadd9c48cb7f448abf3479f16024f29906d6f3b70ca7a99289f566a2a1a02ed2e5
|
7
|
+
data.tar.gz: a184b3ddfe8cd71beb7fcb30b9ef460ca16ea9874c53b056b3ee67ffa9292c8ee6a4fb457a02d1f7b2640f0de4349a0e78fa6fbfe480ff2a43acbb49df2da416
|
data/lib/html-native.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require "html-native/constants"
|
2
2
|
require "html-native/builder"
|
3
|
+
require "html-native/logic"
|
3
4
|
|
4
5
|
module HTMLComponent
|
5
|
-
|
6
|
+
|
6
7
|
# Generates generation methods for each HTML5-valid tag. These methods have the
|
7
8
|
# name of the tag. Note that this interferes with the builtin `p` method.
|
8
9
|
TAG_LIST.each do |tag|
|
@@ -17,6 +18,20 @@ module HTMLComponent
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
21
|
+
def doctype(type)
|
22
|
+
Builder.new("<!DOCTYPE #{type}>")
|
23
|
+
end
|
24
|
+
|
25
|
+
def _label(attrs = {}, &block)
|
26
|
+
attrs ||= {}
|
27
|
+
if block
|
28
|
+
body = block.call
|
29
|
+
Builder.new("<label#{attributes_list(:label, attrs)}>") + body + "</label>"
|
30
|
+
else
|
31
|
+
Builder.new("<label#{attributes_list(:label, attrs)}/>")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
20
35
|
# Creates a module that encompasses the given block in an HTMLComponent
|
21
36
|
# context. This gives access to methods in the block as though the block was
|
22
37
|
# declared as the `render` function in a module extending HTMLComponent
|
data/lib/html-native/builder.rb
CHANGED
@@ -9,14 +9,14 @@ module HTMLComponent
|
|
9
9
|
# the initial value.
|
10
10
|
def initialize(strings = [])
|
11
11
|
@strings = []
|
12
|
-
@cache =
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
@cache =
|
13
|
+
if strings.kind_of? Array
|
14
|
+
strings.join
|
15
|
+
elsif strings.kind_of? Enumerable
|
16
|
+
strings.to_a.join
|
17
|
+
else
|
18
|
+
strings.to_s
|
19
|
+
end
|
20
20
|
@cached = true
|
21
21
|
end
|
22
22
|
|
@@ -17,7 +17,7 @@ module HTMLComponent
|
|
17
17
|
:canvas, :noscript, :script,
|
18
18
|
:del, :ins,
|
19
19
|
:caption, :col, :colgroup, :table, :tbody, :td, :tfoot, :th, :thead, :tr,
|
20
|
-
:button, :datalist, :fieldset, :form, :input, :
|
20
|
+
:button, :datalist, :fieldset, :form, :input, :legend, :meter, :optgroup,
|
21
21
|
:option, :output, :progress, :select, :textarea,
|
22
22
|
:details, :dialog, :menu, :summary,
|
23
23
|
:slot, :template
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module HTMLComponent
|
2
|
+
class Builder
|
3
|
+
define_method(:if) do |bool|
|
4
|
+
if bool
|
5
|
+
self
|
6
|
+
else
|
7
|
+
Builder.new
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
define_method(:unless) do |bool|
|
12
|
+
if bool
|
13
|
+
Builder.new
|
14
|
+
else
|
15
|
+
self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def _if(bool, &block)
|
21
|
+
if bool
|
22
|
+
Builder.new(block.call)
|
23
|
+
else
|
24
|
+
Builder.new
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def _unless(bool, &block)
|
29
|
+
unless bool
|
30
|
+
Builder.new(block.call)
|
31
|
+
else
|
32
|
+
Builder.new
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class String
|
38
|
+
define_method(:if) do |bool|
|
39
|
+
if bool
|
40
|
+
HTMLComponent::Builder.new(self)
|
41
|
+
else
|
42
|
+
HTMLComponent::Builder.new
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
define_method(:unless) do |bool|
|
47
|
+
# BAd form, purely for symmetry
|
48
|
+
unless bool
|
49
|
+
HTMLComponent::Builder.new(self)
|
50
|
+
else
|
51
|
+
HTMLComponent::Builder.new
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html-native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kellen Watt
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- lib/html-native/builder.rb
|
21
21
|
- lib/html-native/collections.rb
|
22
22
|
- lib/html-native/constants.rb
|
23
|
+
- lib/html-native/logic.rb
|
23
24
|
homepage: https://github.com/KellenWatt/html-native
|
24
25
|
licenses:
|
25
26
|
- MIT
|