instant_dsl 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +9 -3
- data/VERSION +1 -1
- data/lib/instant_dsl.rb +14 -1
- metadata +3 -3
data/README
CHANGED
@@ -16,12 +16,18 @@ require 'instant_dsl'
|
|
16
16
|
|
17
17
|
PageDSL = InstantDSL[:title, :items]
|
18
18
|
|
19
|
-
|
19
|
+
@name = 'Janosch'
|
20
|
+
|
21
|
+
page = PageDSL.new(self)
|
22
|
+
# the (optional) parameter is the scope from which
|
23
|
+
# instance variables are copied
|
20
24
|
|
21
25
|
page.instance_eval do
|
22
|
-
title 'hey'
|
26
|
+
title 'hey ' + @name
|
23
27
|
items 'box', 'bib'
|
24
28
|
items 'bob'
|
25
29
|
end
|
26
30
|
|
27
|
-
page.
|
31
|
+
page.items 'blab'
|
32
|
+
|
33
|
+
page.dsl_values # => {:title => ['hey Janosch'], :items => ['box', 'bib', 'bob', 'blab']}
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/lib/instant_dsl.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
|
2
2
|
module InstantDSL
|
3
|
+
|
4
|
+
# returns a module that can be mixed in or used to extend
|
3
5
|
def self.new(*actions)
|
4
6
|
mod = Module.new
|
5
7
|
|
@@ -9,7 +11,8 @@ module InstantDSL
|
|
9
11
|
|
10
12
|
actions.each do |act|
|
11
13
|
mod.send :define_method, act do |*args|
|
12
|
-
@__instant_dsl_values ||=
|
14
|
+
@__instant_dsl_values ||=
|
15
|
+
Hash.new {|hsh,k| hsh[k] = [] }
|
13
16
|
@__instant_dsl_values[act] += args
|
14
17
|
self
|
15
18
|
end
|
@@ -17,9 +20,19 @@ module InstantDSL
|
|
17
20
|
mod
|
18
21
|
end
|
19
22
|
|
23
|
+
# returns a class with the module mixed in already
|
20
24
|
def self.[](*actions)
|
21
25
|
kls = Class.new
|
22
26
|
kls.send :include, self.new(*actions)
|
27
|
+
# copy instance variables on class initialization
|
28
|
+
kls.send :define_method, :initialize do |source_scope=Object.new|
|
29
|
+
source_scope.instance_variables.each do |name|
|
30
|
+
unless self.instance_variable_defined?(name)
|
31
|
+
self.instance_variable_set(name,
|
32
|
+
source_scope.instance_variable_get(name))
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
23
36
|
kls
|
24
37
|
end
|
25
38
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 6
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- jbe
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-09 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|