qor_dsl 0.0.4 → 0.0.5
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/Gemfile +3 -0
- data/Gemfile.lock +14 -0
- data/lib/qor_dsl/class_method.rb +4 -4
- data/lib/qor_dsl/config.rb +2 -2
- data/lib/qor_dsl/node.rb +18 -10
- data/qor_dsl.gemspec +1 -1
- data/test/layout.rb +5 -1
- data/test/layout_test.rb +18 -5
- metadata +3 -1
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/lib/qor_dsl/class_method.rb
CHANGED
@@ -40,12 +40,12 @@ module Qor
|
|
40
40
|
node_root
|
41
41
|
end
|
42
42
|
|
43
|
-
def find(*arguments)
|
44
|
-
root.find(*arguments)
|
43
|
+
def find(*arguments, &block)
|
44
|
+
root.find(*arguments, &block)
|
45
45
|
end
|
46
46
|
|
47
|
-
def first(*arguments)
|
48
|
-
root.first(*arguments)
|
47
|
+
def first(*arguments, &block)
|
48
|
+
root.first(*arguments, &block)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
data/lib/qor_dsl/config.rb
CHANGED
@@ -26,11 +26,11 @@ module Qor
|
|
26
26
|
self.__children[type.to_sym] = child
|
27
27
|
|
28
28
|
method_defination = <<-DOC
|
29
|
-
def #{type}(name=nil,
|
29
|
+
def #{type}(name=nil, *data, &blk)
|
30
30
|
config = __children['#{type}'.to_sym]
|
31
31
|
node = Qor::Dsl::Node.new(name)
|
32
32
|
node.add_config(config)
|
33
|
-
node.
|
33
|
+
node.data = *data
|
34
34
|
node.block = blk
|
35
35
|
node.config.instance_eval(&blk) if block_given? && (config.__children.size > 0)
|
36
36
|
__node.add_child(node)
|
data/lib/qor_dsl/node.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Qor
|
2
2
|
module Dsl
|
3
3
|
class Node
|
4
|
-
attr_accessor :name, :config, :parent, :children, :options, :block
|
4
|
+
attr_accessor :name, :config, :parent, :children, :data, :options, :block
|
5
5
|
|
6
6
|
def initialize(name=nil, options={})
|
7
7
|
self.name = name
|
@@ -12,6 +12,17 @@ module Qor
|
|
12
12
|
"{#{config.__name}: #{name || 'nil'}}"
|
13
13
|
end
|
14
14
|
|
15
|
+
def options
|
16
|
+
return @options if @options.is_a?(Hash)
|
17
|
+
return data[-1] if data.is_a?(Array) && data[-1].is_a?(Hash)
|
18
|
+
return data if data.is_a?(Hash)
|
19
|
+
{}
|
20
|
+
end
|
21
|
+
|
22
|
+
def value
|
23
|
+
block.nil? ? (options[:value] || name) : block.call
|
24
|
+
end
|
25
|
+
|
15
26
|
def add_config(config)
|
16
27
|
self.config = config
|
17
28
|
config.__node = self
|
@@ -36,10 +47,11 @@ module Qor
|
|
36
47
|
children << child
|
37
48
|
end
|
38
49
|
|
39
|
-
def find(type=nil, name=nil)
|
50
|
+
def find(type=nil, name=nil, &block)
|
40
51
|
selected_children = children.select do |child|
|
41
52
|
(type.nil? ? true : (child.config.__name.to_s == type.to_s)) &&
|
42
|
-
(name.nil? ? true : (child.name.to_s == name.to_s))
|
53
|
+
(name.nil? ? true : (child.name.to_s == name.to_s)) &&
|
54
|
+
(block.nil? ? true : block.call(child))
|
43
55
|
end
|
44
56
|
|
45
57
|
return selected_children[0] if !name.nil? && selected_children.length == 1
|
@@ -47,22 +59,18 @@ module Qor
|
|
47
59
|
selected_children
|
48
60
|
end
|
49
61
|
|
50
|
-
def first(type=nil, name=nil)
|
51
|
-
selected_children = find(type, name)
|
62
|
+
def first(type=nil, name=nil, &block)
|
63
|
+
selected_children = find(type, name, &block)
|
52
64
|
selected_children.is_a?(Array) ? selected_children[0] : selected_children
|
53
65
|
end
|
54
66
|
|
55
|
-
def value
|
56
|
-
options[:value] || (block.nil? ? name : block.call)
|
57
|
-
end
|
58
|
-
|
59
67
|
def inspect
|
60
68
|
result = [
|
61
69
|
['name', name],
|
62
70
|
['parent', parent && parent.inspect_name],
|
63
71
|
['config', config.__name],
|
64
72
|
['children', children.map(&:inspect_name)],
|
65
|
-
['
|
73
|
+
['data', data],
|
66
74
|
['block', block]
|
67
75
|
].inject({}) do |s, value|
|
68
76
|
s[value[0]] = value[1] if value[1] && value[1].to_s.length > 0
|
data/qor_dsl.gemspec
CHANGED
data/test/layout.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
template do
|
1
|
+
template "daytime", "v1", :since => "09:00", :to => "12:00" do
|
2
2
|
"Hello World"
|
3
3
|
end
|
4
4
|
|
5
|
+
template "daytime", "v2", :since => "13:00", :to => "18:00" do
|
6
|
+
"Hello World2"
|
7
|
+
end
|
8
|
+
|
5
9
|
gadget :product_link, :floating => true
|
6
10
|
|
7
11
|
gadget :quick_buy, :floating => true do
|
data/test/layout_test.rb
CHANGED
@@ -7,14 +7,27 @@ describe Layout do
|
|
7
7
|
@root = Layout::Configuration.root
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
11
|
-
#
|
10
|
+
it "layout config testing" do
|
11
|
+
# Find by type
|
12
12
|
Layout::Configuration.find(:gadget).length.must_equal 2
|
13
|
-
|
13
|
+
|
14
|
+
# Find by name
|
14
15
|
Layout::Configuration.find(:gadget, 'quick_buy').name.must_equal :quick_buy
|
15
|
-
|
16
|
+
|
17
|
+
# Find by block
|
18
|
+
Layout::Configuration.first(:template) do |n|
|
19
|
+
n.options[:since] > "12:50"
|
20
|
+
end.value.must_equal 'Hello World2'
|
21
|
+
|
22
|
+
# Inherit
|
16
23
|
Layout::Configuration.find(:gadget, :product_link).find(:template)[0].value.must_equal "Hello World"
|
17
24
|
|
18
|
-
#
|
25
|
+
# Store any data
|
26
|
+
Layout::Configuration.first(:template).data.must_equal ["v1", {:since => "09:00", :to => "12:00"}]
|
27
|
+
|
28
|
+
# Options
|
29
|
+
Layout::Configuration.find(:template)[1].options.must_equal({:since => "13:00", :to => "18:00"})
|
30
|
+
|
31
|
+
# More is coming... (multi, alias_node)
|
19
32
|
end
|
20
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qor_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,8 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- Gemfile.lock
|
22
24
|
- README.md
|
23
25
|
- Rakefile
|
24
26
|
- lib/qor_dsl.rb
|