html_builder 0.0.1 → 0.0.2
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.
- data/README.md +3 -0
- data/lib/html/builder.rb +25 -0
- data/lib/html/list.rb +17 -0
- data/lib/html/sequence.rb +17 -0
- data/lib/html/tag.rb +12 -0
- metadata +7 -2
data/README.md
ADDED
data/lib/html/builder.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module HTML
|
2
|
+
class Builder < BasicObject
|
3
|
+
def self.build(namespace = ::HTML, &block)
|
4
|
+
new(namespace).build(&block)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(namespace = ::HTML)
|
8
|
+
@namespace = namespace
|
9
|
+
end
|
10
|
+
|
11
|
+
def build(&block)
|
12
|
+
if block.arity > 0
|
13
|
+
yield self
|
14
|
+
else
|
15
|
+
instance_eval(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing(method, *args, &block)
|
20
|
+
class_name = method.to_s.split("_").map(&:capitalize).join
|
21
|
+
klass = @namespace.const_get(class_name)
|
22
|
+
klass.new(*args).to_html
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/html/list.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "html/builder"
|
2
|
+
require "html/tag"
|
3
|
+
require "html/sequence"
|
4
|
+
|
5
|
+
module HTML
|
6
|
+
class List
|
7
|
+
def initialize(enum)
|
8
|
+
@enum = enum
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
Builder.build do |html|
|
13
|
+
html.tag(:ul, html.sequence(:li, @enum))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "html/builder"
|
2
|
+
require "html/tag"
|
3
|
+
|
4
|
+
module HTML
|
5
|
+
class Sequence
|
6
|
+
def initialize(tag, enum)
|
7
|
+
@tag = tag
|
8
|
+
@enum = enum
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
Builder.build do |html|
|
13
|
+
@enum.map { |item| html.tag @tag, item }.join
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/html/tag.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -16,7 +16,12 @@ email:
|
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
|
-
files:
|
19
|
+
files:
|
20
|
+
- lib/html/builder.rb
|
21
|
+
- lib/html/list.rb
|
22
|
+
- lib/html/sequence.rb
|
23
|
+
- lib/html/tag.rb
|
24
|
+
- README.md
|
20
25
|
homepage: https://github.com/smartlogic/html_builder
|
21
26
|
licenses: []
|
22
27
|
post_install_message:
|