richerb 0.0.2 → 0.0.3

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.
@@ -1,103 +1,11 @@
1
1
  require 'nokogiri'
2
+ require 'richerb/tag_node'
3
+ require 'richerb/custom_tag'
4
+ require 'richerb/panel'
5
+
2
6
 
3
7
  module RichERB
4
-
5
- class CustomTag
6
- attr_accessor :doc
7
- attr_accessor :parent
8
- attr_accessor :context
9
- attr_accessor :arity # :nodoc:
10
-
11
- def self.with root, &block
12
- new({}, root, &block)
13
- end
14
-
15
- def initialize options = {}, tag = 'div', root = nil, &block
16
- if root
17
- @doc = root.doc
18
- @parent = @doc
19
- else
20
- @doc = Node.new(tag, options)
21
- @parent = @doc
22
- end
23
-
24
- @context = nil
25
- @arity = nil
26
- @ns = nil
27
-
28
- return unless block_given?
29
-
30
-
31
- @arity = block.arity
32
- if @arity <= 0
33
- @context = eval('self', block.binding)
34
- instance_eval(&block)
35
- else
36
- yield self
37
- end
38
-
39
- @parent = @doc
40
- end
41
-
42
- def method_missing method, *args, &block
43
- if @context && @context.respond_to?(method)
44
- @context.send(method, *args, &block)
45
- else
46
- options = args[0]
47
- node = Node.new(method.to_s, options)
48
-
49
-
50
- insert(node, &block)
51
- end
52
- end
53
-
54
- def insert(node, &block)
55
- node.parent = @parent
56
-
57
- if block_given?
58
- old_parent = @parent
59
- @parent = node
60
- @arity ||= block.arity
61
- if @arity <= 0
62
- instance_eval(&block)
63
- else
64
-
65
- block.call(@doc)
66
- end
67
- @parent = old_parent
68
- end
69
- @parent.children << node
70
- end
71
- end
72
-
73
- class TagNode
74
- attr_accessor :children
75
- attr_accessor :parent
76
- attr_accessor :name
77
- attr_accessor :attributes
78
-
79
- def initialize name, attributes = {}
80
- @name = name
81
- @children = []
82
- @parent = nil
83
- @attributes = {}
84
- attributes.each {|k,v| @attributes[k.to_sym] = v } unless attributes.nil?
85
- end
86
-
87
- def to_xml_node(xml)
88
- xml.send(@name.to_sym, @attributes) {
89
- @children.each {|node| node.to_xml_node(xml) }
90
- }
91
- end
8
+ class << self
92
9
 
93
- def to_xml
94
- builder = Nokogiri::XML::Builder.new do |xml|
95
- xml.send(@name.to_sym, @attributes) {
96
- @children.each {|node| node.to_node(xml) }
97
- }
98
- end
99
-
100
- builder.doc.root.to_xml
101
- end
102
10
  end
103
11
  end
@@ -0,0 +1,71 @@
1
+ module RichERB
2
+ class CustomTag
3
+ attr_accessor :doc
4
+ attr_accessor :parent
5
+ attr_accessor :context
6
+ attr_accessor :arity
7
+
8
+ def initialize options = {}, tag = 'div', root = nil, &block
9
+ if root
10
+ @doc = root.doc
11
+ @parent = @doc
12
+ else
13
+ @doc = TagNode.new(tag, options)
14
+ @parent = @doc
15
+ end
16
+
17
+ @context = nil
18
+ @arity = nil
19
+ @ns = nil
20
+
21
+ return unless block_given?
22
+
23
+
24
+ @arity = block.arity
25
+ if @arity <= 0
26
+ @context = eval('self', block.binding)
27
+ instance_eval(&block)
28
+ else
29
+ yield self
30
+ end
31
+
32
+ @parent = @doc
33
+ end
34
+
35
+ def method_missing method, *args, &block
36
+ if @context && @context.respond_to?(method)
37
+ @context.send(method, *args, &block)
38
+ else
39
+ options, inner_text = nil, nil
40
+ if args.size == 1
41
+ options = args[0] if args[0] == Hash
42
+ inner_text = args[0] if args[0] != Hash
43
+ elsif args.size > 1
44
+ options = args[0]
45
+ inner_text = args[1]
46
+ end
47
+
48
+ node = TagNode.new(method.to_s, options, inner_text)
49
+ insert(node, &block)
50
+ end
51
+ end
52
+
53
+ def insert(node, &block)
54
+ node.parent = @parent
55
+
56
+ if block_given?
57
+ old_parent = @parent
58
+ @parent = node
59
+ @arity ||= block.arity
60
+ if @arity <= 0
61
+ instance_eval(&block)
62
+ else
63
+
64
+ block.call(@doc)
65
+ end
66
+ @parent = old_parent
67
+ end
68
+ @parent.children << node
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,12 @@
1
+ module RichERB
2
+ class Panel < RichERB::CustomTag
3
+ def initialize options = {}, root = nil, &block
4
+ @header = options[:header]
5
+ panel_options = {:class_ => 'rf-p'}
6
+ super panel_options, 'div', root do |panel|
7
+ panel.div({:class_ => 'rf-p-hdr'}, @header) unless @header.nil?
8
+ yield self if block_given?
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module RichERB
2
+ class PanelGrid < CustomTag
3
+ def initialize options = {}, root = nil, &block
4
+ super.initialize options, nil, root, &block do |panel_grid|
5
+ panel_grid.table(:width => "100%") {
6
+
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,34 @@
1
+ module RichERB
2
+ class TagNode
3
+ attr_accessor :children
4
+ attr_accessor :parent
5
+ attr_accessor :name
6
+ attr_accessor :attributes
7
+ attr_accessor :inner_text
8
+
9
+ def initialize name, attributes = {}, innter_text
10
+ @name = name
11
+ @children = []
12
+ @parent = nil
13
+ @attributes = {}
14
+ @innter_text = innter_text
15
+ attributes.each {|k,v| @attributes[k.to_sym] = v } unless attributes.nil?
16
+ end
17
+
18
+ def to_xml_node(xml)
19
+ xml.send(@name.to_sym, @attributes, @innter_text) {
20
+ @children.each {|node| node.to_xml_node(xml) }
21
+ }
22
+ end
23
+
24
+ def to_xml
25
+ builder = Nokogiri::XML::Builder.new do |xml|
26
+ xml.send(@name.to_sym, @attributes, @innter_text) {
27
+ @children.each {|node| node.to_xml_node(xml) }
28
+ }
29
+ end
30
+
31
+ builder.doc.root.to_xml
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: richerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -34,6 +34,10 @@ extensions: []
34
34
  extra_rdoc_files: []
35
35
  files:
36
36
  - lib/richerb.rb
37
+ - lib/richerb/custom_tag.rb
38
+ - lib/richerb/panel.rb
39
+ - lib/richerb/panel_grid.rb
40
+ - lib/richerb/tag_node.rb
37
41
  homepage:
38
42
  licenses: []
39
43
  post_install_message: