qor_dsl 0.1.1 → 0.1.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.
- data/.gitignore +1 -0
- data/README.md +10 -2
- data/lib/qor_dsl/class_method.rb +17 -7
- data/lib/qor_dsl/config.rb +1 -1
- data/qor_dsl.gemspec +1 -1
- data/test/layout_test.rb +29 -5
- metadata +2 -3
- data/Gemfile.lock +0 -14
data/.gitignore
CHANGED
data/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Qor Dsl - DSL made easy!
|
|
|
35
35
|
|
|
36
36
|
3, Defining config (Sample Gemfile file used for above config)
|
|
37
37
|
|
|
38
|
-
# Gemfile
|
|
38
|
+
# Using default config file `Gemfile`
|
|
39
39
|
source 'http://rubygems.org'
|
|
40
40
|
|
|
41
41
|
gem 'rails', '3.2.8'
|
|
@@ -50,7 +50,15 @@ Qor Dsl - DSL made easy!
|
|
|
50
50
|
gem 'rspec'
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
# Or using code block
|
|
54
|
+
Gemfile.load do
|
|
55
|
+
source 'http://rubygems.org'
|
|
56
|
+
|
|
57
|
+
gem 'rails', '3.2.8'
|
|
58
|
+
gem 'unicorn'
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
4, Querying config (Please checkout the source code and play with examples under the `example` directory for more details)
|
|
54
62
|
|
|
55
63
|
# Find by type
|
|
56
64
|
Gemfile.find(:gem)
|
data/lib/qor_dsl/class_method.rb
CHANGED
|
@@ -5,6 +5,13 @@ module Qor
|
|
|
5
5
|
@node_root ||= Qor::Dsl::Node.new
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
def reset!
|
|
9
|
+
node_config = node_root.config
|
|
10
|
+
@node_root = Qor::Dsl::Node.new
|
|
11
|
+
@node_root.add_config(node_config)
|
|
12
|
+
@root = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
8
15
|
def node(type, options={}, &blk)
|
|
9
16
|
node_root.node(type, options, &blk)
|
|
10
17
|
end
|
|
@@ -25,18 +32,21 @@ module Qor
|
|
|
25
32
|
end
|
|
26
33
|
end
|
|
27
34
|
|
|
28
|
-
def load(path=nil, opts={})
|
|
29
|
-
|
|
35
|
+
def load(path=nil, opts={}, &block)
|
|
36
|
+
reset! if opts[:force] || block_given?
|
|
30
37
|
|
|
31
|
-
@
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
@root ||= if block_given? # Load from block
|
|
39
|
+
node_root.config.instance_eval(&block)
|
|
40
|
+
node_root
|
|
41
|
+
else # Load from file
|
|
42
|
+
@load_path = path || @load_path || default_config
|
|
43
|
+
load_file(@load_path)
|
|
44
|
+
end
|
|
34
45
|
end
|
|
35
46
|
|
|
36
47
|
def load_file(file)
|
|
37
48
|
return unless File.exist?(file.to_s)
|
|
38
|
-
|
|
39
|
-
node_root.config.instance_eval(content)
|
|
49
|
+
node_root.config.instance_eval(File.read(file))
|
|
40
50
|
node_root
|
|
41
51
|
end
|
|
42
52
|
|
data/lib/qor_dsl/config.rb
CHANGED
data/qor_dsl.gemspec
CHANGED
data/test/layout_test.rb
CHANGED
|
@@ -2,12 +2,8 @@ require 'minitest/autorun'
|
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'configure')
|
|
3
3
|
|
|
4
4
|
describe Layout do
|
|
5
|
-
before do
|
|
6
|
-
Layout::Configuration.load('test/layout.rb')
|
|
7
|
-
@root = Layout::Configuration.root
|
|
8
|
-
end
|
|
9
|
-
|
|
10
5
|
it "layout config testing" do
|
|
6
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
|
11
7
|
# Find by type
|
|
12
8
|
Layout::Configuration.find(:gadget).length.must_equal 2
|
|
13
9
|
Layout::Configuration.find(:template).length.must_equal 2
|
|
@@ -45,4 +41,32 @@ describe Layout do
|
|
|
45
41
|
|
|
46
42
|
# More is coming... (multi, alias_node)
|
|
47
43
|
end
|
|
44
|
+
|
|
45
|
+
it "force load" do
|
|
46
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
|
47
|
+
root = Layout::Configuration.root
|
|
48
|
+
root.find(:gadget).length.must_equal 2
|
|
49
|
+
old_object_ids = root.find(:gadget).map(&:object_id).sort
|
|
50
|
+
|
|
51
|
+
Layout::Configuration.load('test/layout.rb')
|
|
52
|
+
root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
|
|
53
|
+
|
|
54
|
+
Layout::Configuration.load('test/layout.rb', :force => true)
|
|
55
|
+
new_root = Layout::Configuration.root
|
|
56
|
+
|
|
57
|
+
new_root.find(:gadget).length.must_equal 2
|
|
58
|
+
root.find(:gadget).map(&:object_id).sort.must_equal old_object_ids
|
|
59
|
+
new_root.find(:gadget).map(&:object_id).sort.wont_be_same_as old_object_ids
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it "load config from block" do
|
|
63
|
+
Layout::Configuration.load(nil, :force => true) do
|
|
64
|
+
template "new" do
|
|
65
|
+
"New Template"
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
Layout::Configuration.find(:template).count.must_equal 1
|
|
70
|
+
Layout::Configuration.first(:template).value.must_equal "New Template"
|
|
71
|
+
end
|
|
48
72
|
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.1.
|
|
4
|
+
version: 0.1.3
|
|
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: 2012-10-
|
|
12
|
+
date: 2012-10-22 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Qor DSL is designed to be as flexible as possible while helping you to
|
|
15
15
|
create your DSLs.
|
|
@@ -21,7 +21,6 @@ extra_rdoc_files: []
|
|
|
21
21
|
files:
|
|
22
22
|
- .gitignore
|
|
23
23
|
- Gemfile
|
|
24
|
-
- Gemfile.lock
|
|
25
24
|
- README.md
|
|
26
25
|
- Rakefile
|
|
27
26
|
- example/Gemfile
|