html_fn 0.3.0 → 0.3.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: 2bdadb6a7633289833bc0a131f58283215d27d98b8023272849a1d193519f15e
4
- data.tar.gz: 94b142e40198d2ff66b6ffee2132c6c1fb15d58a27a76207153539d7aaa99495
3
+ metadata.gz: fdefc6f385851e6d11a2d4be052f3b8a0fce71d5617eaaeeb543a6ed5a034d38
4
+ data.tar.gz: eed2a499f44f734e4f38c0432b8874fd2218a07e2c68868800aefa4fc6f0b513
5
5
  SHA512:
6
- metadata.gz: ded0251185ec75a0d6a2f682b08e144278e734f4658e889c20cea2892f62ed0d636efcd01866015538ac72b7a6ce49d0944dc36f3a146c4732e9368aeaf3ca07
7
- data.tar.gz: 05d548ec4d535b58c650393645aedfb6d4c8d685a3c073d4a64ca6c3d83f2027998e2362266f105601c442672f0cd4f4bef80d76f5fd927b052e5c76ebe0feca
6
+ metadata.gz: ef20c9fe79087a710d28c926d916faa8e097ec8aa3184fc9505df7dbcadb56f6d81f77ae3fbd9a1791db7457a7b642052d31d424902ff39d5185bf9f608361b7
7
+ data.tar.gz: d4adb6673030a814918e7f65ad83175e623ea2ec7b2410183a10cdc6379f98d41199c8e67f01bfeb6d5467c030bf849671c5d94fab7a29400a1056ea949bae5a
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- html_fn (0.3.0)
4
+ html_fn (0.3.2)
5
5
  fn_reader
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- fn_reader (0.1.0)
10
+ fn_reader (0.2.0)
11
11
  minitest (5.11.3)
12
- rake (10.5.0)
12
+ rake (13.0.3)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
@@ -18,7 +18,7 @@ DEPENDENCIES
18
18
  bundler (~> 1.17)
19
19
  html_fn!
20
20
  minitest (~> 5.0)
21
- rake (~> 10.0)
21
+ rake (>= 12.3.3)
22
22
 
23
23
  BUNDLED WITH
24
24
  1.17.2
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # HtmlFn
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/html_fn`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ DSL for building HTML without using metaprogram magic.
6
4
 
7
5
  ## Installation
8
6
 
@@ -22,7 +20,41 @@ Or install it yourself as:
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ```ruby
24
+ require 'html_fn'
25
+
26
+ include HtmlFn
27
+ include HtmlFn::Attributes
28
+
29
+ my_table =
30
+ table.([class_.("table")]).(
31
+ [thead.([]).(
32
+ [tr.([]).(
33
+ [th.([]).([text.("Name")]),
34
+ th.([]).([text.("Age")])]
35
+ )]
36
+
37
+ ),
38
+ tbody.([]).(
39
+ [tr.([]).([
40
+ td.([]).([text.("Martin")]),
41
+ td.([]).([text.("34")]),
42
+ ])]
43
+ )]
44
+ )
45
+ ```
46
+
47
+ Note that the html will not be formated. If you want to format it, you can use a function as such:
48
+
49
+ ```ruby
50
+ def pretty_print(a)
51
+ require "rexml/document"
52
+ d = REXML::Document.new(a)
53
+ d.write(s = "", 2)
54
+ s
55
+ end
56
+
57
+ ```
26
58
 
27
59
  ## Development
28
60
 
data/html_fn.gemspec CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = ["lib"]
38
38
 
39
39
  spec.add_development_dependency "bundler", "~> 1.17"
40
- spec.add_development_dependency "rake", "~> 10.0"
40
+ spec.add_development_dependency "rake", ">= 12.3.3"
41
41
  spec.add_development_dependency "minitest", "~> 5.0"
42
42
  spec.add_dependency "fn_reader"
43
43
  end
@@ -2,11 +2,11 @@
2
2
  module HtmlFn
3
3
  module Attributes
4
4
  fn_reader :merge_attrs, :attrs_to_s, :string_property,
5
- :class_, :style, :name, :content, :href, :rel
5
+ :class_, :style, :name_, :content, :href, :rel
6
6
 
7
7
  # Your code goes here...
8
8
  # module HtmlFnc
9
- @@merge_attrs = -> hash {
9
+ @@merge_attrs = ->hash {
10
10
  hash.inject({}) do |group, (key, values)|
11
11
  group[key] ||= []
12
12
  group[key] += [values]
@@ -14,25 +14,25 @@ module HtmlFn
14
14
  end.map { |key, val| [key, val.join(" ")] }.to_h
15
15
  }
16
16
 
17
- @@attrs_to_s = -> attrs {
17
+ @@attrs_to_s = ->attrs {
18
18
  merged = @@merge_attrs.(attrs)
19
19
  merged.map do |(attr_name, values)|
20
20
  %{#{attr_name}="#{values}"}
21
21
  end.join(" ")
22
22
  }
23
23
 
24
- @@string_property = -> name, string {
24
+ @@string_property = ->name, string {
25
25
  [name, string]
26
26
  }.curry
27
27
 
28
- @@style = -> styles {
28
+ @@style = ->styles {
29
29
  string_property.("style").
30
30
  (styles.map { |(key, val)| %{#{key}: #{val};} }.join(" "))
31
31
  }
32
32
 
33
33
  @@class_ = string_property.(:class)
34
34
  @@id_ = string_property.(:id)
35
- @@name = string_property.(:name)
35
+ @@name_ = string_property.(:name)
36
36
  @@content = string_property.(:content)
37
37
  @@href = string_property.(:href)
38
38
  @@rel = string_property.(:rel)
@@ -1,3 +1,3 @@
1
1
  module HtmlFn
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.2"
3
3
  end
data/lib/html_fn.rb CHANGED
@@ -3,16 +3,14 @@ require "fn_reader"
3
3
  require "html_fn/attributes"
4
4
 
5
5
  module HtmlFn
6
- fn_reader :tag, :table, :thead, :tr, :th, :td, :tbody, :text, :headers, :row, :html_table,
7
- :node, :table, :thead, :th, :td, :th, :tbody, :div
8
-
9
- @@node = -> tag, attrs, elems {
6
+ fn_reader :node, :div, :table, :thead, :tr, :th, :td, :tbody, :text
7
+ @@node = ->tag, attrs, elems {
10
8
  <<EOF
11
9
  <#{tag} #{Attributes.attrs_to_s.(attrs)}>#{elems.join("\n")}</#{tag}>
12
10
  EOF
13
11
  }.curry
14
12
 
15
- @@text = -> a { [a.to_s] }
13
+ @@text = ->a { [a.to_s] }
16
14
 
17
15
  @@script = node.(:script)
18
16
  @@table = node.(:table)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html_fn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Chabot
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-26 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description:
69
+ description:
70
70
  email:
71
71
  - chabotm@gmail.com
72
72
  executables: []
@@ -93,7 +93,7 @@ licenses:
93
93
  metadata:
94
94
  homepage_uri: https://github.com/martinos/html_fn
95
95
  source_code_uri: https://github.com/martinos/html_fn
96
- post_install_message:
96
+ post_install_message:
97
97
  rdoc_options: []
98
98
  require_paths:
99
99
  - lib
@@ -108,8 +108,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.0.1
112
- signing_key:
111
+ rubygems_version: 3.4.6
112
+ signing_key:
113
113
  specification_version: 4
114
114
  summary: Bunch of lamdas for building Html
115
115
  test_files: []