hypertext 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ed751f7bacf414010a50e266e61ad2124e9694b2f58e063c86c07aafdf6a7d0
4
- data.tar.gz: f49d0b5f3ebed4ca55ca4ccb1d92eb01491f52069698ab8636da2cb6acae61a0
3
+ metadata.gz: bbc01410aa9d572f48b9e75e75ea14cd66300afbe1a71c6ce7209c090f011380
4
+ data.tar.gz: 79762344583a234e0a074d9dbb6adbf7827ef4cde156843766f433c0904349cd
5
5
  SHA512:
6
- metadata.gz: 8f2fe8239fe6cf432af39a8b2382abe3097b1e9f0b092374cfadc588f5f595a1f690d42ae152c1a389e813d27d2481daa9c2f205ed4f3c10a0624a015d9d969e
7
- data.tar.gz: f6da75a9e0c066a835e35abd2583b063b85c0d39d04aa0fe35036a7648625b93e22b0bb296beecd58fef3264f593975da6666ab1d9dfa7352bbb3cd800fad308
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 |h|
19
- h.tag :h1 do |h|
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 |h|
25
+ h.tag :p do
26
26
  h.text "nice to meet you"
27
27
  end
28
28
  end
data/hypertext.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "hypertext"
3
- s.version = "0.0.1"
3
+ s.version = "0.0.2"
4
4
  s.summary = "Hypertext authoring"
5
5
  s.description = "Hypertext authoring with Ruby"
6
6
  s.authors = ["Michel Martens"]
data/lib/hypertext.rb CHANGED
@@ -51,20 +51,24 @@ class Hypertext
51
51
  end
52
52
  end
53
53
 
54
- def tag(name, attributes = {}, &block)
54
+ def tag(name, attributes = {})
55
55
  atts = compile(attributes)
56
56
 
57
57
  if block_given?
58
- @dom.push "<#{name}#{atts}>"
59
- @dom.push yield(self.class.new).to_a
60
- @dom.push "</#{name}>"
58
+ @dom << "<#{name}#{atts}>"
59
+
60
+ original, @dom = @dom, []
61
+ yield
62
+ @dom = original << @dom
63
+
64
+ @dom << "</#{name}>"
61
65
  else
62
- @dom.push "<#{name}#{atts} />"
66
+ @dom << "<#{name}#{atts} />"
63
67
  end
64
68
  end
65
69
 
66
70
  def text(value)
67
- @dom.push(escape(value))
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
- observed = Hypertext.new
6
- observed.text "hello world"
5
+ ht = Hypertext.new
6
+ ht.text "hello world"
7
7
 
8
- assert_equal expected, observed.to_s
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
- observed = Hypertext.new
15
- observed.tag :br
14
+ ht = Hypertext.new
15
+ ht.tag :br
16
16
 
17
- assert_equal expected, observed.to_s
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
- observed = Hypertext.new
24
- observed.tag :span do |ht|
23
+ ht = Hypertext.new
24
+ ht.tag :span do
25
25
  ht.text "hello world"
26
26
  end
27
27
 
28
- assert_equal expected, observed.to_s
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
- observed = Hypertext.new
35
- observed.tag :div do |ht|
36
- ht.tag :p do |ht|
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, observed.to_s
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
- observed = Hypertext.new do |ht|
47
+ ht = Hypertext.new do |ht|
48
48
  ht.tag :br
49
49
  end
50
50
 
51
- assert_equal expected, observed.to_s
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
- observed = Hypertext.new do |ht|
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, observed.to_s
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
- observed = Hypertext.new do |ht|
68
- ht.tag :p do |ht|
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, observed.to_s("....")
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.1
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-06 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest