hiccdown 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/hiccdown.rb +34 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 022a2995f052e2fa92b90580fc4428511e58b305cdf8bd6785bdd0bff3e6aa0a
4
+ data.tar.gz: ae2111eff32c9e67a4c110a9cefa467d7544c6487ff1a36e5ea722e85bb28ec9
5
+ SHA512:
6
+ metadata.gz: 51a8dd39c7c628bd866660568f8065d2d2307691ef2c42bffb55e6b03f289af3327a9f0b65956b54a596b687be2225453b29ad58660bee541bcb310186b84b8e
7
+ data.tar.gz: cc46c2515ae32a9583b12b3acf64f8b1471dc560ca04156bb0483cf88480e5232b6f70c7289ca4671afaabdbd71aa49fa8c1cee0164c6ee374f6fa5467c1d058
data/lib/hiccdown.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'byebug'
2
+
3
+ module Hiccdown
4
+ def self.standalone_tags
5
+ Set.new([:area, :base, :br, :col, :command, :embed, :hr, :img, :input, :keygen, :link, :menuitem, :meta, :param, :source, :track, :wbr])
6
+ end
7
+
8
+ def self.to_html structure
9
+ if structure.is_a? Hash
10
+ structure.reduce([]) do |acc, (key, val)|
11
+ acc + [[key.to_s, '="', val.to_s, '"'].join]
12
+ end.join(' ')
13
+ elsif structure.is_a? Array
14
+ if structure.first.is_a?(Array)
15
+ return structure.map { |s| to_html s }.join
16
+ end
17
+
18
+ if structure[1].is_a? Hash
19
+ tag, attrs, *children = structure.map { |s| to_html s }
20
+ tag_and_attrs = structure[1].any? ? [tag, ' ', attrs].join : tag
21
+ else
22
+ tag, *children = structure.map { |s| to_html s }
23
+ end
24
+
25
+ if standalone_tags.include? tag.to_sym
26
+ ['<', tag_and_attrs || tag, '/>'].join
27
+ else
28
+ ['<', tag_and_attrs || tag, '>', children.join, '</', tag, '>'].join
29
+ end
30
+ else
31
+ structure.to_s
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiccdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Dennis Hackethal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Generates an HTML string from a Hiccup structure.
14
+ email: dennis.hackethal@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hiccdown.rb
20
+ homepage: https://rubygems.org/gems/hiccdown
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.1.4
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Hiccup for Ruby
43
+ test_files: []