html-builder 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/html-builder.rb +14 -8
  2. data/lib/html-template.rb +24 -0
  3. metadata +3 -2
data/lib/html-builder.rb CHANGED
@@ -45,27 +45,32 @@ end
45
45
 
46
46
  class HtmlBuilder
47
47
  def self.html *args, &block
48
- generate :html, *args, &block
48
+ self.generate {
49
+ html(*args, &block)
50
+ }
49
51
  end
50
- def self.generate root_ele, *args, &block
52
+ def self.generate *args, &block
51
53
  x = self.new
52
- x.build_tree root_ele, *args, &block
54
+ if block
55
+ x.yield_block nil, &block
56
+ else
57
+ template *args
58
+ end
53
59
  x.to_s
54
60
  end
55
61
  def initialize
56
62
  @root = nil
57
63
  @stack = []
58
64
  end
65
+ def template *args
66
+ # reimplement it if necessary
67
+ end
59
68
  def inspect
60
- nil
69
+ self.class
61
70
  end
62
71
  def to_s *args
63
72
  @root.to_s *args
64
73
  end
65
- def build_tree root_name, *args, &block
66
- @root = HtmlBuilderNode.new nil, root_name, *args
67
- yield_block @root, &block
68
- end
69
74
  def yield_block e, &block
70
75
  return unless block
71
76
  @stack << e
@@ -74,6 +79,7 @@ class HtmlBuilder
74
79
  end
75
80
  def add_child name, *args, &block
76
81
  e = HtmlBuilderNode.new @stack.last, name, *args
82
+ @root = e if not @root
77
83
  yield_block e, &block
78
84
  end
79
85
  def self.def_tag name
@@ -0,0 +1,24 @@
1
+ require 'html-builder'
2
+
3
+ class HtmlTemplate
4
+ def template opts = {}
5
+ @opts = opts
6
+ html(:xmlns => "http://www.w3.org/1999/xhtml") {
7
+ head {
8
+ title @args[:title] if @args[:title]
9
+ }
10
+ body {
11
+ div(:id => "header") {
12
+ header_part
13
+ }
14
+ div(:id => "main") {
15
+ main_part
16
+ }
17
+ }
18
+ }
19
+ end
20
+ def header_part
21
+ end
22
+ def main_part
23
+ end
24
+ 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.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-18 00:00:00.000000000 Z
12
+ date: 2014-06-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A powerful html builder
15
15
  email: jinchizhong@kingsoft.com
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/html-builder.rb
21
+ - lib/html-template.rb
21
22
  homepage: http://github.com/jinchizhong/html-builder
22
23
  licenses:
23
24
  - BSD