hypertext 0.0.3 → 0.0.4

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: f7da5832c31f70fe8154ccb37ac65e1ac58bbefdd8b9b80a6d526467a60d2536
4
- data.tar.gz: ff5438f31f6688805bdef36a57cfcda9d460267151c7b2390f8e0c74e4ff31b4
3
+ metadata.gz: b974b055063680c076cf29632fd9213845f29cded66964e0b4d94eeb12dce3b6
4
+ data.tar.gz: 763f98b84eac1550e2cafd5314a8b41b5d3245e9697db63e5fa6cebc250a8e74
5
5
  SHA512:
6
- metadata.gz: 674d3f48fdf9f7355466493d7ce6c2291bb6128874cf765bdc81738b0f62254e3b1eed193cae6bf16c21250cbe60f99d1abc4c6958f14643aff347c7714cdea1
7
- data.tar.gz: 6b7e63e0c997701faf9e740ca2a51bfd6e831de25b8ad1c5cc4ec807d27c23ffd18a778a7462a68f955a596f39ec66ba2d98f25027643cf210caa7c85d8c2e9a
6
+ metadata.gz: f0325888451cf71a459f91c854a3992fc08c337e5c4a1caf25a03759ce9fc368b9f434901bd33fa4b980119a57cd2be103003ec9a0bd15886d963093c9b1051c
7
+ data.tar.gz: ac7af6f6f5a0f1166115923876bc6ceced66f721830be0b7b1e0db715f23bd849a32d1c16125e96da933ccb6e5f120ce2f524f1ecd190a218cc99fe3be5b0ac7
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.3"
3
+ s.version = "0.0.4"
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
@@ -30,11 +30,13 @@ class Hypertext
30
30
  }
31
31
 
32
32
  def self.render(array, indent = " ", level = 0)
33
+ indentation = indent * level
34
+
33
35
  array.map do |element|
34
36
  if Array === element
35
37
  render(element, indent, level + 1)
36
38
  else
37
- sprintf "%s%s\n", indent * level, element
39
+ sprintf "%s%s\n", indentation, element
38
40
  end
39
41
  end.join
40
42
  end
@@ -51,24 +53,28 @@ class Hypertext
51
53
  end
52
54
  end
53
55
 
56
+ def append(value)
57
+ @dom.push(*value)
58
+ end
59
+
54
60
  def tag(name, attributes = {})
55
61
  atts = compile(attributes)
56
62
 
57
63
  if block_given?
58
- @dom << "<#{name}#{atts}>"
64
+ append("<#{name}#{atts}>")
59
65
 
60
66
  original, @dom = @dom, []
61
67
  yield
62
68
  @dom = original << @dom
63
69
 
64
- @dom << "</#{name}>"
70
+ append("</#{name}>")
65
71
  else
66
- @dom << "<#{name}#{atts} />"
72
+ append("<#{name}#{atts} />")
67
73
  end
68
74
  end
69
75
 
70
76
  def text(value)
71
- @dom << escape(value)
77
+ append(escape(value))
72
78
  end
73
79
 
74
80
  def to_a
data/lib/hypertext/dsl.rb CHANGED
@@ -49,10 +49,18 @@ class Hypertext
49
49
  end
50
50
  end
51
51
 
52
+ def append(content)
53
+ @ht.append(content)
54
+ end
55
+
52
56
  def text(content)
53
57
  @ht.text(content)
54
58
  end
55
59
 
60
+ def to_a
61
+ @ht.to_a
62
+ end
63
+
56
64
  def to_s
57
65
  @ht.to_s
58
66
  end
data/test/all.rb CHANGED
@@ -1,4 +1,13 @@
1
1
  scope "Hypertext" do
2
+ test "append" do
3
+ expected = "hello &rarr; world\n"
4
+
5
+ ht = Hypertext.new
6
+ ht.append "hello &rarr; world"
7
+
8
+ assert_equal expected, ht.to_s
9
+ end
10
+
2
11
  test "text" do
3
12
  expected = "hello world\n"
4
13
 
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.3
4
+ version: 0.0.4
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-10 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest