hypertext 0.0.1 → 0.0.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/README.md +3 -3
- data/hypertext.gemspec +1 -1
- data/lib/hypertext.rb +10 -6
- data/test/all.rb +21 -21
- 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: bbc01410aa9d572f48b9e75e75ea14cd66300afbe1a71c6ce7209c090f011380
|
4
|
+
data.tar.gz: 79762344583a234e0a074d9dbb6adbf7827ef4cde156843766f433c0904349cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce7a3e26dd27873cafaba381462879e74ab3d6a7ab15636bb570e477ed59352cb8810609eb8ab8887d215916cdf649d6dcc22b8db1202dba6a67e76c4c8811d1
|
7
|
+
data.tar.gz: ec4e97e4bfb9c949c92bb538ddc4a7278bb234198a10068981a96532133d0da4d3386e5572d098b75ca9e1d06e812899adc9ddb48de51741597d8eb33c8e9bea
|
data/README.md
CHANGED
@@ -15,14 +15,14 @@ A basic example would look like this:
|
|
15
15
|
|
16
16
|
```ruby
|
17
17
|
html = Hypertext.new do |h|
|
18
|
-
h.tag :div, class: "greeting" do
|
19
|
-
h.tag :h1 do
|
18
|
+
h.tag :div, class: "greeting" do
|
19
|
+
h.tag :h1 do
|
20
20
|
h.text "hello world"
|
21
21
|
end
|
22
22
|
|
23
23
|
h.tag :hr
|
24
24
|
|
25
|
-
h.tag :p do
|
25
|
+
h.tag :p do
|
26
26
|
h.text "nice to meet you"
|
27
27
|
end
|
28
28
|
end
|
data/hypertext.gemspec
CHANGED
data/lib/hypertext.rb
CHANGED
@@ -51,20 +51,24 @@ class Hypertext
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
def tag(name, attributes = {}
|
54
|
+
def tag(name, attributes = {})
|
55
55
|
atts = compile(attributes)
|
56
56
|
|
57
57
|
if block_given?
|
58
|
-
@dom
|
59
|
-
|
60
|
-
@dom
|
58
|
+
@dom << "<#{name}#{atts}>"
|
59
|
+
|
60
|
+
original, @dom = @dom, []
|
61
|
+
yield
|
62
|
+
@dom = original << @dom
|
63
|
+
|
64
|
+
@dom << "</#{name}>"
|
61
65
|
else
|
62
|
-
@dom
|
66
|
+
@dom << "<#{name}#{atts} />"
|
63
67
|
end
|
64
68
|
end
|
65
69
|
|
66
70
|
def text(value)
|
67
|
-
@dom
|
71
|
+
@dom << escape(value)
|
68
72
|
end
|
69
73
|
|
70
74
|
def to_a
|
data/test/all.rb
CHANGED
@@ -2,74 +2,74 @@ scope "Hypertext" do
|
|
2
2
|
test "text" do
|
3
3
|
expected = "hello world\n"
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
ht = Hypertext.new
|
6
|
+
ht.text "hello world"
|
7
7
|
|
8
|
-
assert_equal expected,
|
8
|
+
assert_equal expected, ht.to_s
|
9
9
|
end
|
10
10
|
|
11
11
|
test "self-closing tags" do
|
12
12
|
expected = "<br />\n"
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
ht = Hypertext.new
|
15
|
+
ht.tag :br
|
16
16
|
|
17
|
-
assert_equal expected,
|
17
|
+
assert_equal expected, ht.to_s
|
18
18
|
end
|
19
19
|
|
20
20
|
test "opening and closing tags" do
|
21
21
|
expected = "<span>\n hello world\n</span>\n"
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
ht = Hypertext.new
|
24
|
+
ht.tag :span do
|
25
25
|
ht.text "hello world"
|
26
26
|
end
|
27
27
|
|
28
|
-
assert_equal expected,
|
28
|
+
assert_equal expected, ht.to_s
|
29
29
|
end
|
30
30
|
|
31
31
|
test "nested tags" do
|
32
32
|
expected = "<div>\n <p>\n hello world\n </p>\n</div>\n"
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
ht.tag :p do
|
34
|
+
ht = Hypertext.new
|
35
|
+
ht.tag :div do
|
36
|
+
ht.tag :p do
|
37
37
|
ht.text "hello world"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
assert_equal expected,
|
41
|
+
assert_equal expected, ht.to_s
|
42
42
|
end
|
43
43
|
|
44
44
|
test "passing a block to Hypertext.new" do
|
45
45
|
expected = "<br />\n"
|
46
46
|
|
47
|
-
|
47
|
+
ht = Hypertext.new do |ht|
|
48
48
|
ht.tag :br
|
49
49
|
end
|
50
50
|
|
51
|
-
assert_equal expected,
|
51
|
+
assert_equal expected, ht.to_s
|
52
52
|
end
|
53
53
|
|
54
54
|
test "tags with attributes" do
|
55
55
|
expected = "<input type=\"text\" name=\"person[name]\" value=\"Foo\" />\n"
|
56
56
|
|
57
|
-
|
57
|
+
ht = Hypertext.new do |ht|
|
58
58
|
ht.tag :input, :type => "text", :name => "person[name]", :value => "Foo"
|
59
59
|
end
|
60
60
|
|
61
|
-
assert_equal expected,
|
61
|
+
assert_equal expected, ht.to_s
|
62
62
|
end
|
63
63
|
|
64
64
|
test "custom indentation" do
|
65
65
|
expected = "<p>\n....hello world\n</p>\n"
|
66
66
|
|
67
|
-
|
68
|
-
ht.tag :p do
|
67
|
+
ht = Hypertext.new do |ht|
|
68
|
+
ht.tag :p do
|
69
69
|
ht.text "hello world"
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
assert_equal expected,
|
73
|
+
assert_equal expected, ht.to_s("....")
|
74
74
|
end
|
75
|
-
end
|
75
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hypertext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cutest
|