hypertext 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbc01410aa9d572f48b9e75e75ea14cd66300afbe1a71c6ce7209c090f011380
4
- data.tar.gz: 79762344583a234e0a074d9dbb6adbf7827ef4cde156843766f433c0904349cd
3
+ metadata.gz: f7da5832c31f70fe8154ccb37ac65e1ac58bbefdd8b9b80a6d526467a60d2536
4
+ data.tar.gz: ff5438f31f6688805bdef36a57cfcda9d460267151c7b2390f8e0c74e4ff31b4
5
5
  SHA512:
6
- metadata.gz: ce7a3e26dd27873cafaba381462879e74ab3d6a7ab15636bb570e477ed59352cb8810609eb8ab8887d215916cdf649d6dcc22b8db1202dba6a67e76c4c8811d1
7
- data.tar.gz: ec4e97e4bfb9c949c92bb538ddc4a7278bb234198a10068981a96532133d0da4d3386e5572d098b75ca9e1d06e812899adc9ddb48de51741597d8eb33c8e9bea
6
+ metadata.gz: 674d3f48fdf9f7355466493d7ce6c2291bb6128874cf765bdc81738b0f62254e3b1eed193cae6bf16c21250cbe60f99d1abc4c6958f14643aff347c7714cdea1
7
+ data.tar.gz: 6b7e63e0c997701faf9e740ca2a51bfd6e831de25b8ad1c5cc4ec807d27c23ffd18a778a7462a68f955a596f39ec66ba2d98f25027643cf210caa7c85d8c2e9a
data/README.md CHANGED
@@ -15,7 +15,7 @@ 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
18
+ h.tag :div, "data-index-number" => 123, class: "greeting" do
19
19
  h.tag :h1 do
20
20
  h.text "hello world"
21
21
  end
@@ -30,7 +30,7 @@ end
30
30
 
31
31
  puts html.to_s
32
32
 
33
- # <div class="greeting">
33
+ # <div data-index-number="123" class="greeting">
34
34
  # <h1>
35
35
  # hello world
36
36
  # </h1>
@@ -41,6 +41,34 @@ puts html.to_s
41
41
  # </div>
42
42
  ```
43
43
 
44
+ DSL
45
+ ---
46
+
47
+ As an experimental feature, Hypertext provides a DSL for
48
+ describing an HTML document in a way that resembles
49
+ [Markaby](https://github.com/markaby/markaby).
50
+
51
+ ```ruby
52
+ require "hypertext"
53
+ require "hypertext/dsl"
54
+
55
+ person_name = "Foo Bar"
56
+
57
+ html = Hypertext::DSL.new do
58
+ form action: "/", method: "post" do
59
+ input name: "person[name]", value: person_name
60
+ input type: "submit"
61
+ end
62
+ end
63
+
64
+ puts html.to_s
65
+
66
+ # <form action="/" method="post">
67
+ # <input name="person[name]" value="Foo Bar" />
68
+ # <input type="submit" />
69
+ # </form>
70
+ ```
71
+
44
72
  Installation
45
73
  ------------
46
74
 
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.2"
3
+ s.version = "0.0.3"
4
4
  s.summary = "Hypertext authoring"
5
5
  s.description = "Hypertext authoring with Ruby"
6
6
  s.authors = ["Michel Martens"]
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+ #
3
+ # Copyright (c) 2021 Michel Martens
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ class Hypertext
24
+ class DSL
25
+ TAGS = [:a, :abbr, :address, :area, :article, :aside,
26
+ :audio, :b, :base, :bdi, :bdo, :blockquote, :body, :br,
27
+ :button, :canvas, :caption, :cite, :code, :col, :colgroup,
28
+ :data, :datalist, :dd, :del, :details, :dfn, :dialog, :div,
29
+ :dl, :dt, :em, :embed, :fieldset, :figcaption, :figure,
30
+ :footer, :form, :h1, :h2, :h3, :h4, :h5, :h6, :head,
31
+ :header, :hgroup, :hr, :html, :i, :iframe, :img, :input,
32
+ :ins, :kbd, :label, :legend, :li, :link, :main, :map,
33
+ :mark, :meta, :meter, :nav, :noscript, :object, :ol,
34
+ :optgroup, :option, :output, :p, :param, :picture, :pre,
35
+ :progress, :q, :rb, :rp, :rt, :rtc, :ruby, :s, :samp,
36
+ :script, :section, :select, :slot, :small, :source, :span,
37
+ :strong, :style, :sub, :summary, :sup, :table, :tbody, :td,
38
+ :template, :textarea, :tfoot, :th, :thead, :time, :title,
39
+ :tr, :track, :u, :ul, :var, :video, :wbr]
40
+
41
+ def initialize(&block)
42
+ @ht = Hypertext.new
43
+ instance_eval(&block)
44
+ end
45
+
46
+ TAGS.each do |tag_name|
47
+ define_method(tag_name) do |attributes = {}, &block|
48
+ @ht.tag(tag_name, attributes, &block)
49
+ end
50
+ end
51
+
52
+ def text(content)
53
+ @ht.text(content)
54
+ end
55
+
56
+ def to_s
57
+ @ht.to_s
58
+ end
59
+ end
60
+ end
data/test/all.rb CHANGED
@@ -72,4 +72,20 @@ scope "Hypertext" do
72
72
 
73
73
  assert_equal expected, ht.to_s("....")
74
74
  end
75
- end
75
+ end
76
+
77
+ scope "Hypertext::DSL" do
78
+ test do
79
+ expected = "<head>\n <title>\n hello world\n </title>\n</head>\n"
80
+
81
+ ht = Hypertext::DSL.new do
82
+ head do
83
+ title do
84
+ text "hello world"
85
+ end
86
+ end
87
+ end
88
+
89
+ assert_equal expected, ht.to_s
90
+ end
91
+ end
data/test/helper.rb CHANGED
@@ -1 +1,2 @@
1
1
  require_relative "../lib/hypertext"
2
+ require_relative "../lib/hypertext/dsl"
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.2
4
+ version: 0.0.3
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-07 00:00:00.000000000 Z
11
+ date: 2021-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cutest
@@ -37,6 +37,7 @@ files:
37
37
  - README.md
38
38
  - hypertext.gemspec
39
39
  - lib/hypertext.rb
40
+ - lib/hypertext/dsl.rb
40
41
  - makefile
41
42
  - test/all.rb
42
43
  - test/helper.rb