html_builder 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ [![Travis status](https://secure.travis-ci.org/smartlogic/html_builder.png)](https://secure.travis-ci.org/smartlogic/html_builder)
2
+
3
+ Documentation: https://www.relishapp.com/smartlogic/html-builder
@@ -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
@@ -0,0 +1,12 @@
1
+ module HTML
2
+ class Tag
3
+ def initialize(tag, content)
4
+ @tag = tag
5
+ @content = content
6
+ end
7
+
8
+ def to_html
9
+ "<#{@tag}>#{@content}</#{@tag}>"
10
+ end
11
+ end
12
+ end
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.1
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: