html-renderer 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: ec832ffacb22bbaa8114f23fc302ceda89ba7b6622945587d54d2c3dc0cbe25d
4
- data.tar.gz: '0813e1a9e2185e7f656934ddffc2cde7eb9ecc92e3b028ef0646272742d7c2fb'
3
+ metadata.gz: 4d2be4cf32a612a0e2fa528a0d50e85df36f732e40c408ed3183b6a041c60558
4
+ data.tar.gz: 1500874bc627082bf07f2e0912ba5b2020cad6987cd9cd29c4add0abe0e5d0db
5
5
  SHA512:
6
- metadata.gz: 2412e685c804211d8f9d4c9101a1287d3a97e55f3d60f65bce810559cc9499081e0f343bcd7c353e3ba3eb8abddb9eea2454149966b29f22bf1e54579d3bfa31
7
- data.tar.gz: a3ecf047cd4c5e2dd99d5f9ef79ee9d8b8855e9732fabcf59a94121102bea0ee7d07d08cf5899491c93ce156bd3f6edae48353913b7c84e4e37bb12dab30018c
6
+ metadata.gz: eda1c880bebd51ed462ca2c07fcec4abfcb80cc30cc9b16b2c7366d4abc46637f3d3f778d36689e3cb6472b60fa28fda2282fea64c49262f6a4246c45468d2d9
7
+ data.tar.gz: 26dec9aa2c27f6356101c92ed5aabf164249aaec89a99febbb55ecbd4aafe9db1e44d9e914344b49f4919f501cd01d568427f48e267db353d4d7952ba9f36b25
data/Rakefile CHANGED
@@ -1,20 +1,20 @@
1
+ pkgname = "html-renderer"
1
2
  gem_version = File.read("VERSION").strip
2
- gem_name = "html-renderer"
3
+
4
+ gemfile = "#{pkgname}-#{gem_version}.gem"
3
5
 
4
6
  task :build do
5
7
  system "gem build .gemspec"
8
+ system "mkdir pkg/" unless File.directory? "pkg"
9
+ system "mv #{gemfile} pkg/"
6
10
  end
7
-
11
+
8
12
  task :release => :build do
9
- system "gem push #{gem_name}-#{gem_version}.gem"
13
+ system "gem push pkg/#{gemfile}"
10
14
  end
11
15
 
12
- task :install => :build do
13
- system "gem install --local #{gem_name}-#{gem_version}.gem"
14
- end
16
+ task :gem => :build
15
17
 
16
- task :pry do
17
- system "pry --gem"
18
+ task :install => :build do
19
+ system "gem install pkg/#{gemfile}"
18
20
  end
19
-
20
- task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -39,10 +39,6 @@ public
39
39
  text
40
40
  end
41
41
 
42
- def raw_html(html)
43
- ''
44
- end
45
-
46
42
  def underline(content)
47
43
  content.magenta.bold
48
44
  end
@@ -65,12 +61,20 @@ public
65
61
  end
66
62
  end
67
63
 
64
+ def anchor(name, title=nil, content=nil)
65
+ result = "Anchor: ##{name}"
66
+ result << " (#{title})" if title
67
+ result << "\n"
68
+ result << "#{content}\n" if content
69
+ result
70
+ end
71
+
68
72
  def image(link, title, content)
69
73
  link(link, nil, title)
70
74
  end
71
75
 
72
76
  def italic(text)
73
- text.light_yellow
77
+ text.yellow.bold
74
78
  end
75
79
 
76
80
  def block_code(code, language)
@@ -147,6 +151,14 @@ public
147
151
  end
148
152
  end
149
153
 
154
+ def definition_list(defs)
155
+ defs.each do |dt, dd|
156
+ puts "<15>#{dt}<7>:".colorize
157
+ puts " #{dd}"
158
+ puts
159
+ end
160
+ end
161
+
150
162
  def table(header, rows)
151
163
  if header
152
164
  table = Terminal::Table.new(headings: header, rows: rows)
@@ -164,5 +176,5 @@ end
164
176
 
165
177
 
166
178
  if __FILE__ == $0
167
- puts ANSIRenderer.render(open("test.html"))
168
- end
179
+ puts ANSIRenderer.render(open(ARGV.first || "test.html"))
180
+ end
@@ -69,9 +69,14 @@ private
69
69
  when "a"
70
70
  url = node["href"]
71
71
  title = node["title"]
72
+ name = node["name"]
72
73
  content = render_children(node, state)
73
74
 
74
- link(url, title, content)
75
+ if name and not url
76
+ anchor(name, title, content)
77
+ else
78
+ link(url, title, content)
79
+ end
75
80
 
76
81
  when "img"
77
82
  link = node["src"]
@@ -98,11 +103,12 @@ private
98
103
  when "hr"
99
104
  separator
100
105
 
101
- when "p"
106
+ when "p", "dl"
102
107
  paragraph(render_children(node, state).strip)
103
- when "div"
108
+ when "div", "option", "dd", "dt"
104
109
  div(render_children(node, state))
105
110
 
111
+ # TODO: Pass a complete array to list callbacks (similar to "table")
106
112
  when "ul"
107
113
  list(render_children(node, state), state.list_order)
108
114
  when "ol"
@@ -144,7 +150,8 @@ private
144
150
 
145
151
  when "html", "body", "nav", "span", "form", "label", "input", "button", "section", "fieldset",
146
152
  "menu", "article", "header", "time", "aside", "footer", "nobr", "wbr",
147
- "table", "tr", "td", "th", "thead", "tbody", "noscript"
153
+ "table", "tr", "td", "th", "thead", "tbody", "noscript", "select",
154
+ "address"
148
155
  render_children(node, state)
149
156
 
150
157
  when "head", "script", "link", "style"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-renderer
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
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2018-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oga