r_kit 0.5 → 1.0
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.
- checksums.yaml +4 -4
- data/lib/r_kit/active_record_utility/active_record_extend.rb +28 -12
- data/lib/r_kit/active_record_utility/utilities/series.rb +115 -77
- data/lib/r_kit/active_record_utility/utilities/tag.rb +6 -2
- data/lib/r_kit/active_record_utility.rb +2 -0
- data/lib/r_kit/core/loader.rb +1 -1
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/base/typography/hr.scss +5 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/base/typography/links.scss +2 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/base/typography/paragraphs.scss +3 -1
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/base/typography/titles.scss +4 -2
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/base/typography.scss +1 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components/btn.scss +3 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/alignments.scss +7 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/blocks.scss +4 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/box-shadows/curved-shadows.scss +1 -1
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/box-shadows/straight-shadows.scss +1 -1
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/links.scss +12 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins/titles.scss +6 -10
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/mixins.scss +2 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/variables/colors.scss +1 -1
- data/lib/r_kit/css/sass_extend.rb +1 -2
- data/lib/r_kit/css.rb +13 -11
- data/lib/r_kit/decoration/action_view_base_extend.rb +1 -2
- data/lib/r_kit/decoration/base/collection.rb +11 -11
- data/lib/r_kit/decoration/base/object.rb +0 -18
- data/lib/r_kit/decoration/base.rb +39 -2
- data/lib/r_kit/decoration/class.rb +26 -55
- data/lib/r_kit/decoration/dsl.rb +14 -83
- data/lib/r_kit/decoration/enumerable_extend.rb +5 -1
- data/lib/r_kit/decoration/object_extend.rb +5 -0
- data/lib/r_kit/decoration.rb +4 -7
- data/lib/r_kit/dsl/base/thrust.rb +6 -2
- data/lib/r_kit/dsl/base.rb +9 -3
- data/lib/r_kit/dsl/dsl_extend.rb +1 -1
- data/lib/r_kit/dsl/test.rb +81 -0
- data/lib/r_kit/dsl.rb +1 -6
- data/lib/r_kit/frame/collection_dsl.rb +24 -0
- data/lib/r_kit/frame/empty_frame.rb +7 -0
- data/lib/r_kit/frame/instance_dsl.rb +30 -0
- data/lib/r_kit/frame.rb +14 -0
- data/lib/r_kit/grid/base/grid.rb +69 -19
- data/lib/r_kit/grid/base/grid_col.rb +22 -19
- data/lib/r_kit/grid/base.rb +1 -15
- data/lib/r_kit/grid/binding.rb +3 -10
- data/lib/r_kit/grid/lib/assets/stylesheets/r_kit/base/grid.scss +15 -18
- data/lib/r_kit/grid/lib/assets/stylesheets/r_kit/base/grid_flex.scss +19 -0
- data/lib/r_kit/grid/lib/assets/stylesheets/r_kit/base/grid_items.scss +5 -0
- data/lib/r_kit/grid/lib/assets/stylesheets/r_kit/grid.scss +2 -0
- data/lib/r_kit/grid/lib/assets/stylesheets/r_kit/mixins/{gris.scss → grid.scss} +0 -0
- data/lib/r_kit/grid.rb +2 -3
- data/lib/r_kit/override/base.rb +125 -0
- data/lib/r_kit/override/method_extend.rb +8 -0
- data/lib/r_kit/override/module_extend.rb +53 -0
- data/lib/r_kit/override/pattern.rb +53 -0
- data/lib/r_kit/override/perfs.rb +117 -0
- data/lib/r_kit/override/test.rb +466 -0
- data/lib/r_kit/override/unbound_method_extend.rb +8 -0
- data/lib/r_kit/override.rb +15 -0
- data/lib/r_kit/pagination/base/page.rb +5 -23
- data/lib/r_kit/pagination/base.rb +32 -62
- data/lib/r_kit/pagination/dsl.rb +10 -0
- data/lib/r_kit/pagination/enumerable_extend.rb +7 -0
- data/lib/r_kit/pagination.rb +29 -2
- data/lib/r_kit/parser/base.rb +19 -0
- data/lib/r_kit/parser/leaf.rb +72 -0
- data/lib/r_kit/parser/test.rb +76 -0
- data/lib/r_kit/parser/tree.rb +22 -0
- data/lib/r_kit/parser.rb +8 -0
- data/lib/r_kit/struct/collection_delegator.rb +0 -6
- data/lib/r_kit/utility/basic_object_extend.rb +9 -0
- data/lib/r_kit/utility/kernel_extend.rb +9 -3
- data/lib/r_kit/utility/main_extend.rb +22 -0
- data/lib/r_kit/utility/module_extend.rb +18 -11
- data/lib/r_kit/utility/simple_delegator_extend.rb +1 -1
- data/lib/r_kit/utility/symbol_extend.rb +1 -1
- data/lib/r_kit/utility.rb +4 -2
- data/lib/r_kit/version.rb +1 -1
- metadata +29 -5
- data/lib/r_kit/grid/base/grid_row.rb +0 -29
- data/lib/r_kit/grid/kernel_extend.rb +0 -14
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
module RKit::Decoration::Base
|
|
2
2
|
|
|
3
|
+
def self.included base
|
|
4
|
+
base.singleton_attr_reader :decorated_class
|
|
5
|
+
base.singleton_attr_reader :after_initialize_procs, default: proc{ [] }
|
|
6
|
+
|
|
7
|
+
base.define_singleton_method :after_initialize, ->(&block) do
|
|
8
|
+
after_initialize_procs << block
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
def initialize object, view_context: nil
|
|
4
14
|
@view_context = view_context
|
|
5
|
-
|
|
15
|
+
|
|
16
|
+
super(object)
|
|
17
|
+
after_initialize!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def after_initialize!
|
|
21
|
+
decorated = self
|
|
22
|
+
__getobj__.define_singleton_method(:decorated){ decorated }
|
|
23
|
+
|
|
24
|
+
decorator_class.after_initialize_procs.each{ |after_initialize_proc| self.instance_eval &after_initialize_proc }
|
|
6
25
|
end
|
|
7
26
|
|
|
27
|
+
|
|
8
28
|
alias :decorator_class :class
|
|
9
29
|
delegate :class, to: :__getobj__
|
|
10
30
|
|
|
@@ -15,6 +35,8 @@ module RKit::Decoration::Base
|
|
|
15
35
|
|
|
16
36
|
def decorated?() true end
|
|
17
37
|
|
|
38
|
+
def need_decoration?() false end
|
|
39
|
+
|
|
18
40
|
def raw
|
|
19
41
|
__getobj__
|
|
20
42
|
end
|
|
@@ -25,7 +47,22 @@ module RKit::Decoration::Base
|
|
|
25
47
|
end
|
|
26
48
|
|
|
27
49
|
def view
|
|
28
|
-
|
|
50
|
+
(@@mutex ||= Mutex.new).synchronize do
|
|
51
|
+
@view_context ||= view_context
|
|
52
|
+
end
|
|
53
|
+
rescue ThreadError
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def method_missing method_name, *args, &block
|
|
59
|
+
closure = super
|
|
60
|
+
|
|
61
|
+
if RKit::Decoration.config.recursive_decoration && closure.need_decoration?
|
|
62
|
+
closure.decorate(view_context: view)
|
|
63
|
+
else
|
|
64
|
+
closure
|
|
65
|
+
end
|
|
29
66
|
end
|
|
30
67
|
|
|
31
68
|
end
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
class RKit::Decoration::Class
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def new *args, &block
|
|
6
|
-
basic_new(*args, &block).decorator
|
|
7
|
-
end
|
|
3
|
+
def self.new *args, &block
|
|
4
|
+
super.decorator
|
|
8
5
|
end
|
|
9
6
|
|
|
10
7
|
|
|
11
|
-
def initialize decorated, from: nil, &block
|
|
8
|
+
def initialize decorated, from: nil, sleeping: nil, &block
|
|
12
9
|
@decorated = decorated
|
|
13
10
|
@from = from
|
|
11
|
+
@sleeping = sleeping
|
|
14
12
|
@block = block || proc{}
|
|
15
13
|
end
|
|
16
14
|
|
|
@@ -18,11 +16,25 @@ class RKit::Decoration::Class
|
|
|
18
16
|
def decorator
|
|
19
17
|
decorator_from(@from)
|
|
20
18
|
.tap{ |decorator| decorator.instance_variable_set "@decorated_class", @decorated }
|
|
21
|
-
.tap{ |decorator|
|
|
19
|
+
.tap{ |decorator|
|
|
20
|
+
unless decorator.decorated_class.method_defined? :"#{ decorator.decorated_class.demodulize.underscore }"
|
|
21
|
+
decorator.class_eval{ alias :"#{ decorated_class.demodulize.underscore }" :__getobj__ }
|
|
22
|
+
end
|
|
23
|
+
}
|
|
24
|
+
.tap{ |decorator| decorator.send :include, @sleeping }
|
|
22
25
|
.tap{ |decorator| decorator.class_eval &@block }
|
|
23
26
|
end
|
|
24
27
|
|
|
25
28
|
|
|
29
|
+
def decorator_superclass
|
|
30
|
+
if @decorated <=> Enumerable
|
|
31
|
+
RKit::Decoration::Collection
|
|
32
|
+
else
|
|
33
|
+
RKit::Decoration::Object
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
26
38
|
|
|
27
39
|
protected def decorator_from from
|
|
28
40
|
send "decorator_from_#{ from.class.underscore }", from
|
|
@@ -37,7 +49,7 @@ class RKit::Decoration::Class
|
|
|
37
49
|
decorator_from(
|
|
38
50
|
@decorated
|
|
39
51
|
.namespace
|
|
40
|
-
.const_get name, default: Class.new(
|
|
52
|
+
.const_get name, default: Class.new(decorator_superclass)
|
|
41
53
|
)
|
|
42
54
|
end
|
|
43
55
|
|
|
@@ -48,64 +60,23 @@ class RKit::Decoration::Class
|
|
|
48
60
|
mod
|
|
49
61
|
.namespace
|
|
50
62
|
.const_replace mod.demodulize,
|
|
51
|
-
Class.new(
|
|
63
|
+
Class.new(decorator_superclass){ include mod }
|
|
52
64
|
end
|
|
53
65
|
|
|
54
66
|
def decorator_from_class base
|
|
55
|
-
if base <=> RKit::Decoration::
|
|
67
|
+
if base <=> RKit::Decoration::Base
|
|
56
68
|
base
|
|
57
69
|
else
|
|
58
70
|
# TODO: method class_to_module
|
|
59
71
|
# TODO: method class.add_ancestor(superclass)
|
|
72
|
+
decorator_superclass = self.decorator_superclass
|
|
73
|
+
|
|
60
74
|
base.tap do |base|
|
|
61
|
-
base.send :include, Module.new{ include refine(
|
|
62
|
-
base.extend Module.new{ include refine(
|
|
75
|
+
base.send :include, Module.new{ include refine(decorator_superclass){} }
|
|
76
|
+
base.extend Module.new{ include refine(decorator_superclass.singleton_class){} }
|
|
63
77
|
base.instance_variable_set "@decorated_class", @decorated
|
|
64
78
|
base.class_eval{ alias :"#{ decorated_class.demodulize.underscore }" :__getobj__ }
|
|
65
79
|
end
|
|
66
80
|
end
|
|
67
81
|
end
|
|
68
82
|
end
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
# # TODO: all the methods below this comment should be private, even more, they should be in a "decorator_finder_creator_definer", and not included in active_record. SRP guys !
|
|
72
|
-
# def define_decorator arg
|
|
73
|
-
# @decorator_klass = decorator_klass_from arg
|
|
74
|
-
# @decorator_klass
|
|
75
|
-
# end
|
|
76
|
-
#
|
|
77
|
-
#
|
|
78
|
-
# def decorator_klass_from arg
|
|
79
|
-
# send "decorator_klass_from_#{ arg.class.name.underscore }", arg
|
|
80
|
-
# end
|
|
81
|
-
#
|
|
82
|
-
# def decorator_klass_from_nil_class *args
|
|
83
|
-
# decorator_klass_from "#{ name }Decorator".constantize
|
|
84
|
-
# end
|
|
85
|
-
#
|
|
86
|
-
# def decorator_klass_from_class base
|
|
87
|
-
# if base <=> RKit::Decoration::Base
|
|
88
|
-
# base
|
|
89
|
-
# else
|
|
90
|
-
# base.tap do |base|
|
|
91
|
-
# base.send :include, Module.new{ include refine(RKit::Decoration::Base){} }
|
|
92
|
-
# base.extend Module.new{ include refine(RKit::Decoration::Base.singleton_class){} }
|
|
93
|
-
# base.instance_variable_set "@decorated_klass", self
|
|
94
|
-
# base.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
|
|
95
|
-
# end
|
|
96
|
-
# end
|
|
97
|
-
# end
|
|
98
|
-
#
|
|
99
|
-
# def decorator_klass_from_module mod
|
|
100
|
-
# namespace = (mod.name.deconstantize.presence || 'Object').constantize
|
|
101
|
-
# const_name = mod.name.demodulize
|
|
102
|
-
#
|
|
103
|
-
# namespace.send :remove_const, const_name
|
|
104
|
-
# namespace.const_set const_name, RKit::Decoration::Class.new(self){ include mod }
|
|
105
|
-
# end
|
|
106
|
-
#
|
|
107
|
-
# def decorator_klass_from_proc block
|
|
108
|
-
# (name.deconstantize.presence || 'Object')
|
|
109
|
-
# .constantize
|
|
110
|
-
# .const_set "#{ name.demodulize }Decorator", RKit::Decoration::Class.new(self, &block)
|
|
111
|
-
# end
|
data/lib/r_kit/decoration/dsl.rb
CHANGED
|
@@ -5,6 +5,11 @@ class RKit::Decoration::Dsl
|
|
|
5
5
|
method :acts_as_decorables
|
|
6
6
|
domain ActiveRecord::Base
|
|
7
7
|
|
|
8
|
+
before do
|
|
9
|
+
def self.decorator_class() @decorator_class ||= Module.new end
|
|
10
|
+
def decorated?() false end
|
|
11
|
+
end
|
|
12
|
+
|
|
8
13
|
|
|
9
14
|
params ->(from = nil, &block){}
|
|
10
15
|
|
|
@@ -12,110 +17,36 @@ class RKit::Decoration::Dsl
|
|
|
12
17
|
|
|
13
18
|
@decorator_class = RKit::Decoration::Class.new self,
|
|
14
19
|
from: decoration_dsl.params.from,
|
|
20
|
+
sleeping: decorator_class,
|
|
15
21
|
&decoration_dsl.params.block
|
|
16
22
|
|
|
17
23
|
def decorator_class
|
|
18
24
|
@decorator_class
|
|
19
25
|
end
|
|
20
26
|
|
|
21
|
-
# TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
|
|
22
|
-
# or if we create an array with decorables objects in it
|
|
23
|
-
# this will fail
|
|
24
|
-
# --
|
|
25
|
-
# in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
|
|
26
|
-
# and will not raise error
|
|
27
|
-
# TODO: act as paginable can not be used, because of decoration (implicit here)
|
|
28
|
-
# decorated paginated collection still work fine
|
|
29
|
-
# but non paginated collection, becomes dumb arrays
|
|
30
|
-
# def decorate view_context: nil
|
|
31
|
-
# all.map{ |record| record.decorate view_context: view_context }
|
|
32
|
-
# end
|
|
33
|
-
|
|
34
27
|
def decorate **options
|
|
35
28
|
RKit::Decoration::Collection.new all, **options
|
|
36
29
|
end
|
|
37
30
|
|
|
38
31
|
def decorated?() false end
|
|
39
32
|
|
|
33
|
+
def need_decoration?() true end
|
|
34
|
+
|
|
40
35
|
end
|
|
41
36
|
|
|
42
37
|
|
|
43
38
|
methods :instance do
|
|
44
39
|
|
|
40
|
+
delegate :decorator_class, to: :__class__
|
|
41
|
+
|
|
42
|
+
|
|
45
43
|
def decorate **options
|
|
46
|
-
|
|
44
|
+
decorator_class.new self, **options
|
|
47
45
|
end
|
|
48
46
|
|
|
49
47
|
def decorated?() false end
|
|
50
48
|
|
|
49
|
+
def need_decoration?() true end
|
|
50
|
+
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
# attr_accessor :decorator_klass
|
|
58
|
-
#
|
|
59
|
-
# def acts_as_decorables base = nil, &block
|
|
60
|
-
# define_decorator base || block
|
|
61
|
-
# define_instance_methods
|
|
62
|
-
# end
|
|
63
|
-
#
|
|
64
|
-
# # TODO: all the methods below this comment should be private, even more, they should be in a "decorator_finder_creator_definer", and not included in active_record. SRP guys !
|
|
65
|
-
# def define_decorator arg
|
|
66
|
-
# @decorator_klass = decorator_klass_from arg
|
|
67
|
-
# @decorator_klass
|
|
68
|
-
# end
|
|
69
|
-
#
|
|
70
|
-
#
|
|
71
|
-
# def decorator_klass_from arg
|
|
72
|
-
# send "decorator_klass_from_#{ arg.class.name.underscore }", arg
|
|
73
|
-
# end
|
|
74
|
-
#
|
|
75
|
-
# def decorator_klass_from_nil_class *args
|
|
76
|
-
# decorator_klass_from "#{ name }Decorator".constantize
|
|
77
|
-
# end
|
|
78
|
-
#
|
|
79
|
-
# def decorator_klass_from_class base
|
|
80
|
-
# if base <=> RKit::Decoration::Base
|
|
81
|
-
# base
|
|
82
|
-
# else
|
|
83
|
-
# base.tap do |base|
|
|
84
|
-
# base.send :include, Module.new{ include refine(RKit::Decoration::Base){} }
|
|
85
|
-
# base.extend Module.new{ include refine(RKit::Decoration::Base.singleton_class){} }
|
|
86
|
-
# base.instance_variable_set "@decorated_klass", self
|
|
87
|
-
# base.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
|
|
88
|
-
# end
|
|
89
|
-
# end
|
|
90
|
-
# end
|
|
91
|
-
#
|
|
92
|
-
# def decorator_klass_from_module mod
|
|
93
|
-
# namespace = (mod.name.deconstantize.presence || 'Object').constantize
|
|
94
|
-
# const_name = mod.name.demodulize
|
|
95
|
-
#
|
|
96
|
-
# namespace.send :remove_const, const_name
|
|
97
|
-
# namespace.const_set const_name, RKit::Decoration::Class.new(self){ include mod }
|
|
98
|
-
# end
|
|
99
|
-
#
|
|
100
|
-
# def decorator_klass_from_proc block
|
|
101
|
-
# (name.deconstantize.presence || 'Object')
|
|
102
|
-
# .constantize
|
|
103
|
-
# .const_set "#{ name.demodulize }Decorator", RKit::Decoration::Class.new(self, &block)
|
|
104
|
-
# end
|
|
105
|
-
#
|
|
106
|
-
# # TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
|
|
107
|
-
# # or if we create an array with decorables objects in it
|
|
108
|
-
# # this will fail
|
|
109
|
-
# # --
|
|
110
|
-
# # in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
|
|
111
|
-
# # and will not raise error
|
|
112
|
-
# def decorate view_context: nil
|
|
113
|
-
# all.map{ |record| record.decorate view_context: view_context }
|
|
114
|
-
# end
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
# def define_instance_methods
|
|
118
|
-
# define_method 'decorate' do |view_context: nil|
|
|
119
|
-
# self.class.decorator_klass.new self, view_context: view_context
|
|
120
|
-
# end
|
|
121
|
-
# end
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
module Enumerable
|
|
2
2
|
|
|
3
3
|
def decorate **options
|
|
4
|
-
RKit::Decoration::Collection.new(self, **options)
|
|
4
|
+
RKit::Decoration::Collection.new(self, **options)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
def decorated?() false end
|
|
8
8
|
|
|
9
|
+
def need_decoration?
|
|
10
|
+
any?(&:need_decoration?)
|
|
11
|
+
end
|
|
12
|
+
|
|
9
13
|
end
|
data/lib/r_kit/decoration.rb
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
class RKit::Decoration
|
|
2
2
|
|
|
3
|
-
# TODO: backtrace is not really a dependency,
|
|
4
|
-
# as we, most of the time, get the view context from the block
|
|
5
|
-
# and if not, we do not require the "view_context" (well, we could not, I think)
|
|
6
|
-
# (the only case is if the user define a block elswhere than in the view or in the controller, and use it)
|
|
7
|
-
# (but this case will fail today as well, I think)
|
|
8
|
-
# -> pb w/ backtrace in console (Screencast.limit(5).decorate.map{|x|x} -> infinite loop)
|
|
9
3
|
dependency :backtrace,
|
|
10
4
|
:dsl,
|
|
11
5
|
:utility
|
|
@@ -17,10 +11,13 @@ class RKit::Decoration
|
|
|
17
11
|
'base/object',
|
|
18
12
|
'class',
|
|
19
13
|
'dsl',
|
|
20
|
-
'enumerable_extend'
|
|
14
|
+
'enumerable_extend',
|
|
15
|
+
'object_extend'
|
|
21
16
|
|
|
22
17
|
load_path __FILE__, 'action_view_base_extend', if: :implicit_decoration
|
|
23
18
|
|
|
24
19
|
|
|
25
20
|
config :implicit_decoration, true
|
|
21
|
+
config :recursive_decoration, true
|
|
22
|
+
|
|
26
23
|
end
|
|
@@ -12,6 +12,10 @@ class RKit::Dsl::Base
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
protected def thrust_dsl_callback!
|
|
16
|
+
@domain.class_eval &readonly.methods[:before]
|
|
17
|
+
end
|
|
18
|
+
|
|
15
19
|
protected def thrust_dsl_interface!
|
|
16
20
|
name = @name
|
|
17
21
|
|
|
@@ -48,12 +52,12 @@ class RKit::Dsl::Base
|
|
|
48
52
|
@domain.send :define_singleton_method, "try_to_#{ @method }" do |*args, &block|
|
|
49
53
|
send "#{ name }_params=", *args, &block
|
|
50
54
|
|
|
51
|
-
if send
|
|
55
|
+
if send("can_#{ send(name).method }?") && !send("#{ send(name).method }?")
|
|
52
56
|
send(name).dsls[name] << self
|
|
53
57
|
|
|
54
58
|
instance_eval &send(name).methods[:class]
|
|
55
59
|
class_eval &send(name).methods[:instance]
|
|
56
|
-
if respond_to?(:acts_as_decorables?)
|
|
60
|
+
if respond_to?(:acts_as_decorables?)
|
|
57
61
|
decorator_class.class_eval &send(name).methods[:decorator]
|
|
58
62
|
end
|
|
59
63
|
|
data/lib/r_kit/dsl/base.rb
CHANGED
|
@@ -36,10 +36,9 @@ class RKit::Dsl::Base
|
|
|
36
36
|
|
|
37
37
|
@domain ||= domain
|
|
38
38
|
|
|
39
|
-
shadow :domain do |shadow_self|
|
|
40
|
-
shadow_self.instance_variable_set "@domain", domain
|
|
41
|
-
|
|
39
|
+
shadow domain: domain do |shadow_self|
|
|
42
40
|
thrust_dsl!
|
|
41
|
+
thrust_dsl_callback! if @methods[:before]
|
|
43
42
|
thrust_dsl_interface!
|
|
44
43
|
thrust_dsl_options!
|
|
45
44
|
thrust_dsl_extend!
|
|
@@ -47,6 +46,13 @@ class RKit::Dsl::Base
|
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
|
|
49
|
+
def before &block
|
|
50
|
+
methods :before, &block
|
|
51
|
+
|
|
52
|
+
thrust_dsl_callback!
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
50
56
|
def params params_lambda
|
|
51
57
|
@params = RKit::Dsl::Base::Params.new(params_lambda)
|
|
52
58
|
end
|
data/lib/r_kit/dsl/dsl_extend.rb
CHANGED
|
@@ -4,7 +4,7 @@ module RKit::Dsl::DslExtend
|
|
|
4
4
|
subclass.instance_variable_set "@_dsl", RKit::Dsl::Base.new(subclass)
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
delegate :name, :method, :domain, :params, :methods, :allowed?, :restricted,
|
|
7
|
+
delegate :name, :method, :domain, :before, :params, :methods, :allowed?, :restricted,
|
|
8
8
|
to: :@_dsl
|
|
9
9
|
|
|
10
10
|
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
class Yank
|
|
2
|
+
act_as_a_dsl # active la déclaration de la dsl
|
|
3
|
+
|
|
4
|
+
name :yank # définit le nom de la dsl, utilisé pour les params surtout
|
|
5
|
+
method :acts_as_yankables # définit le nom de la méthode
|
|
6
|
+
domain ActiveRecord::Base # définit la zone d'action de la dsl
|
|
7
|
+
|
|
8
|
+
# définit des méthodes directement dans la classe du domaine
|
|
9
|
+
# ce qui permet d'ajouter du comportement dans le domaine sans avoir appelé la méthode de la dsl
|
|
10
|
+
before do
|
|
11
|
+
def yanked?
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# définit si je peux exécuter ou non la dsl
|
|
17
|
+
allowed? do
|
|
18
|
+
table_exists? # && column_names.include?("yank")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# définit le comportement en si le 'allowed?' réponds 'false'
|
|
22
|
+
# il y a un "raise DslStandardError" par défaut, si rien n'est renseigné
|
|
23
|
+
restricted do
|
|
24
|
+
raise DatabaseSchemaError.new(self, method_name: 'bonjour')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# définit la structure des arguments que je peux utiliser pour la dsl
|
|
28
|
+
params ->(y_arg, *y_args){}
|
|
29
|
+
|
|
30
|
+
# définit les méthodes de classes qui seront ajoutés lors de l'utilisation de la dsl
|
|
31
|
+
methods :class do
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
yank.params.y_args # permet d'accéder aux arguments passés lors de l'appel de la dsl. c'est une Struct
|
|
35
|
+
|
|
36
|
+
yank.extract_local_variables # extrait les arguments passés lors de l'appel de la dsl en variables locales
|
|
37
|
+
y_args
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
scope :yanked, ->{ all }
|
|
41
|
+
|
|
42
|
+
def yanked?
|
|
43
|
+
true
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# définit les méthodes d'instance qui seront ajoutés lors de l'utilisation de la dsl
|
|
48
|
+
methods :instance do
|
|
49
|
+
def yank
|
|
50
|
+
"yank"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# définit les méthodes de decorator qui seront ajoutés lors de l'utilisation de la dsl
|
|
55
|
+
# uniquement si la classe "hôte" réponds à "decorator_klass" (c'est la cas si on utilise RKit::Decorator ^^)
|
|
56
|
+
methods :decorator do
|
|
57
|
+
def yank
|
|
58
|
+
"yyyyyyyyy"
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
=begin
|
|
64
|
+
# utilisation
|
|
65
|
+
class Article < ActiveRecord::Base
|
|
66
|
+
try_to_acts_as_yankables :y_arg # ne va pas trigger 'restricted' si le 'allowed?' réponds 'false'
|
|
67
|
+
acts_as_yankables :y_arg # trigger le 'restricted'
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class Commentaire < ActiveRecord::Base
|
|
71
|
+
end
|
|
72
|
+
-> Commentaire.new.yanked? #=> false
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# in main
|
|
76
|
+
Article.can_acts_as_yankables?
|
|
77
|
+
Article.acts_as_yankables?
|
|
78
|
+
Yank.acts_as_yankables #=> [Article]
|
|
79
|
+
|
|
80
|
+
DSLS #=> {yank: [Article]}
|
|
81
|
+
=end
|
data/lib/r_kit/dsl.rb
CHANGED
|
@@ -46,12 +46,6 @@ class RKit::Dsl
|
|
|
46
46
|
# -> to do that, either, interchage all the methods (painfull)
|
|
47
47
|
# -> or, try to replace the const_name when 'act_as_dsl' is used (pb when re-opening the class ?)
|
|
48
48
|
|
|
49
|
-
# TODO: rkit: on dsl, I lac of a callback when dsl is put in another class
|
|
50
|
-
# (like a 'def self.decorated(decorator)' for example).
|
|
51
|
-
# I know I can put the code in 'class methods',
|
|
52
|
-
# but I may also want a specific callback from the calling class ?
|
|
53
|
-
# (maybe smthng like "before_acts_as_X + after_act_as_X") ("self.yanked" "self.X-ed")
|
|
54
|
-
|
|
55
49
|
# TODO: make smthing to define methods on the "domain" level
|
|
56
50
|
# for example, in the series dsl, I could define a method "per_page" in all the domain, that would return '[]'
|
|
57
51
|
# and when dsl is added, that would return an array with all the series
|
|
@@ -67,6 +61,7 @@ class RKit::Dsl
|
|
|
67
61
|
# then -> def self.clas_method, -> def instance_method
|
|
68
62
|
# then, in host class -> act_as_x -> define "@X", X_delegator(self), delegate *X.methods, to: @X
|
|
69
63
|
|
|
64
|
+
|
|
70
65
|
# load_path __FILE__, 'test'
|
|
71
66
|
|
|
72
67
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class RKit::Frame::CollectionDsl
|
|
2
|
+
|
|
3
|
+
act_as_a_dsl
|
|
4
|
+
|
|
5
|
+
name :framed_collection_dsl
|
|
6
|
+
method :acts_as_frameable_collection
|
|
7
|
+
domain Enumerable
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
methods :instance do
|
|
11
|
+
|
|
12
|
+
override_method :each do |&block|
|
|
13
|
+
__olddef__ &->(obj) do
|
|
14
|
+
|
|
15
|
+
obj.shadow sy_frame: self do |obj|
|
|
16
|
+
block.call(obj)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class RKit::Frame::InstanceDsl
|
|
2
|
+
|
|
3
|
+
act_as_a_dsl
|
|
4
|
+
|
|
5
|
+
name :framed_instance_dsl
|
|
6
|
+
method :acts_as_frameable
|
|
7
|
+
domain Object
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
def frame
|
|
11
|
+
@sy_frame || RKit::Frame::EmptyFrame.instance
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def frame= value
|
|
15
|
+
@sy_frame = value
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def framed &block
|
|
20
|
+
shadow sy_frame: block.binding.eval('self') do |obj|
|
|
21
|
+
block.call obj
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def framed?
|
|
26
|
+
!!frame
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|