r_kit 0.4.2 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/r_kit/active_record_utility/active_record_extend.rb +31 -4
- data/lib/r_kit/active_record_utility/base/pool.rb +29 -0
- data/lib/r_kit/active_record_utility/base/publisher.rb +28 -0
- data/lib/r_kit/active_record_utility/base/series.rb +141 -0
- data/lib/r_kit/active_record_utility/base/tag.rb +17 -0
- data/lib/r_kit/active_record_utility/base.rb +70 -0
- data/lib/r_kit/active_record_utility/database_schema_error.rb +4 -4
- data/lib/r_kit/active_record_utility.rb +12 -3
- data/lib/r_kit/backtrace.rb +4 -0
- data/lib/r_kit/core/loader/dependency.rb +26 -0
- data/lib/r_kit/core/loader/load_path.rb +58 -0
- data/lib/r_kit/core/loader.rb +3 -89
- data/lib/r_kit/core.rb +10 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components/btn.scss +8 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components/pagination.scss +3 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/components.scss +1 -0
- data/lib/r_kit/css/lib/assets/stylesheets/r_kit/variables/colors.scss +1 -1
- data/lib/r_kit/css.rb +12 -5
- data/lib/r_kit/{decorator → decoration}/action_view_base_extend.rb +2 -2
- data/lib/r_kit/{decorator → decoration}/active_record_extend.rb +16 -9
- data/lib/r_kit/decoration/base.rb +35 -0
- data/lib/r_kit/decoration/class.rb +22 -0
- data/lib/r_kit/decoration.rb +19 -0
- data/lib/r_kit/dsl/base/local_params.rb +13 -0
- data/lib/r_kit/dsl/base/params.rb +38 -0
- data/lib/r_kit/dsl/base/readonly.rb +16 -0
- data/lib/r_kit/dsl/base/thrust.rb +67 -0
- data/lib/r_kit/dsl/base.rb +68 -0
- data/lib/r_kit/dsl/dsl_definition_error.rb +10 -0
- data/lib/r_kit/dsl/dsl_extend.rb +10 -0
- data/lib/r_kit/dsl/dsl_standard_error.rb +9 -0
- data/lib/r_kit/dsl/module_extend.rb +22 -0
- data/lib/r_kit/dsl/no_lambda_error.rb +10 -0
- data/lib/r_kit/dsl.rb +21 -0
- data/lib/r_kit/pagination/active_record_extend.rb +23 -0
- data/lib/r_kit/pagination/base/page.rb +53 -0
- data/lib/r_kit/pagination/base.rb +153 -0
- data/lib/r_kit/pagination.rb +23 -0
- data/lib/r_kit/struct/collection_delegator.rb +24 -0
- data/lib/r_kit/struct/safe_struct.rb +35 -0
- data/lib/r_kit/struct/strong_struct.rb +17 -0
- data/lib/r_kit/struct.rb +8 -0
- data/lib/r_kit/utility/active_record_extend.rb +7 -0
- data/lib/r_kit/utility/array_extend.rb +10 -1
- data/lib/r_kit/utility/module_extend.rb +43 -0
- data/lib/r_kit/utility/object_extend.rb +33 -0
- data/lib/r_kit/utility/proc_extend.rb +41 -0
- data/lib/r_kit/utility/simple_delegator_extend.rb +12 -0
- data/lib/r_kit/utility/string_extend.rb +20 -0
- data/lib/r_kit/utility/symbol_extend.rb +1 -1
- data/lib/r_kit/utility.rb +4 -1
- data/lib/r_kit/version.rb +1 -1
- data/lib/r_kit.rb +9 -0
- data/r_kit.gemspec +1 -1
- metadata +41 -9
- data/lib/r_kit/active_record_utility/utility/tag.rb +0 -14
- data/lib/r_kit/active_record_utility/utility.rb +0 -53
- data/lib/r_kit/decorator/base.rb +0 -34
- data/lib/r_kit/decorator.rb +0 -13
data/lib/r_kit/css.rb
CHANGED
@@ -3,17 +3,24 @@ class RKit::Css
|
|
3
3
|
with_engine __FILE__
|
4
4
|
with_sprockets __FILE__
|
5
5
|
|
6
|
+
config :colors, :black, '#111'
|
7
|
+
config :colors, :dark_black, '#000'
|
8
|
+
config :colors, :grey, '#888'
|
9
|
+
config :colors, :light_black, '#181818'
|
10
|
+
config :colors, :red, '#b62b2b'
|
6
11
|
config :colors, :white, '#fbfbfb'
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
13
|
+
alias_config :colors, :primary_color, :red
|
14
|
+
alias_config :colors, :text_color, :grey
|
15
|
+
alias_config :colors, :text_alt_color, :dark_black
|
16
|
+
alias_config :colors, :background_color, :black
|
17
|
+
alias_config :colors, :background_alt_color, :light_black
|
12
18
|
|
13
19
|
alias_config :colors, :btn_color, :background_color
|
14
20
|
alias_config :colors, :btn_background_color, :primary_color
|
21
|
+
alias_config :colors, :btn_disabled_color, :text_alt_color
|
22
|
+
alias_config :colors, :btn_disabled_background_color, :background_alt_color
|
15
23
|
|
16
|
-
alias_config :colors, :link_color, :primary_color
|
17
24
|
|
18
25
|
# unused colors
|
19
26
|
# config :colors, :secondary_color, 'cornflowerblue'
|
@@ -1,7 +1,7 @@
|
|
1
|
-
module RKit::
|
1
|
+
module RKit::Decoration::ActionViewBaseExtend
|
2
2
|
|
3
3
|
def assign new_assigns
|
4
|
-
_decorate_assigns new_assigns if RKit::
|
4
|
+
_decorate_assigns new_assigns if RKit::Decoration.config.auto_decoration
|
5
5
|
|
6
6
|
super
|
7
7
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
module RKit::
|
1
|
+
module RKit::Decoration::ActiveRecordExtend
|
2
|
+
|
2
3
|
attr_accessor :decorator_klass
|
3
4
|
|
4
5
|
def acts_as_decorables base = nil, &block
|
@@ -9,6 +10,7 @@ module RKit::Decorator::ActiveRecordExtend
|
|
9
10
|
# 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 !
|
10
11
|
def define_decorator arg
|
11
12
|
@decorator_klass = decorator_klass_from arg
|
13
|
+
@decorator_klass
|
12
14
|
end
|
13
15
|
|
14
16
|
|
@@ -21,14 +23,14 @@ module RKit::Decorator::ActiveRecordExtend
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def decorator_klass_from_class base
|
24
|
-
if base <=> RKit::
|
26
|
+
if base <=> RKit::Decoration::Base
|
25
27
|
base
|
26
28
|
else
|
27
29
|
base.tap do |base|
|
28
|
-
base.send :include, Module.new{ include refine(RKit::
|
29
|
-
base.extend Module.new{ include refine(RKit::
|
30
|
-
|
31
|
-
|
30
|
+
base.send :include, Module.new{ include refine(RKit::Decoration::Base){} }
|
31
|
+
base.extend Module.new{ include refine(RKit::Decoration::Base.singleton_class){} }
|
32
|
+
base.instance_variable_set "@decorated_klass", self
|
33
|
+
base.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
|
32
34
|
end
|
33
35
|
end
|
34
36
|
end
|
@@ -38,16 +40,21 @@ module RKit::Decorator::ActiveRecordExtend
|
|
38
40
|
const_name = mod.name.demodulize
|
39
41
|
|
40
42
|
namespace.send :remove_const, const_name
|
41
|
-
namespace.const_set const_name, Class.new(
|
43
|
+
namespace.const_set const_name, RKit::Decoration::Class.new(self){ include mod }
|
42
44
|
end
|
43
45
|
|
44
46
|
def decorator_klass_from_proc block
|
45
47
|
(name.deconstantize.presence || 'Object')
|
46
48
|
.constantize
|
47
|
-
.const_set "#{ name.demodulize }Decorator", Class.new(
|
49
|
+
.const_set "#{ name.demodulize }Decorator", RKit::Decoration::Class.new(self, &block)
|
48
50
|
end
|
49
51
|
|
50
|
-
|
52
|
+
# TODO: this couls move in "ennumerable", cause if the AR::relation is mapped into an array
|
53
|
+
# or if we create an array with decorables objects in it
|
54
|
+
# this will fail
|
55
|
+
# --
|
56
|
+
# in addition, make a "safe_decorate" for collections, wich will decorate if respond_to_decorate,
|
57
|
+
# and will not raise error
|
51
58
|
def decorate view_context: nil
|
52
59
|
all.map{ |record| record.decorate view_context: view_context }
|
53
60
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
class RKit::Decoration::Base < SimpleDelegator
|
4
|
+
|
5
|
+
singleton_attr_reader :decorated_klass
|
6
|
+
singleton_attr_reader :after_initialize_procs, default: proc{ [] }
|
7
|
+
|
8
|
+
def self.after_initialize &block
|
9
|
+
after_initialize_procs << block
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize obj, view_context: nil
|
13
|
+
@_view_context = view_context
|
14
|
+
super obj
|
15
|
+
|
16
|
+
decorator_klass.after_initialize_procs.each{ |after_initialize_proc| self.instance_eval &after_initialize_proc }
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :decorator_klass :class
|
20
|
+
delegate :class, to: :__getobj__
|
21
|
+
|
22
|
+
|
23
|
+
def _view_context
|
24
|
+
backtrace{ |obj| obj.is_a? ActionView::Base } || backtrace{ |obj| obj.respond_to? :view_context }.view_context
|
25
|
+
end
|
26
|
+
|
27
|
+
def view
|
28
|
+
@_view_context ||= _view_context
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def === object
|
33
|
+
self == object || __getobj__ == object
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class RKit::Decoration::Class
|
2
|
+
|
3
|
+
module OpenClass
|
4
|
+
refine Class do
|
5
|
+
def new super_class = Object, **options, &block
|
6
|
+
super(super_class, &block).tap do |klass|
|
7
|
+
options.each{ |key, value| klass.instance_variable_set "@#{ key }", value }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
using OpenClass
|
13
|
+
|
14
|
+
# TODO: improve this "new" method, in order to move the creation of the decoraor klass for ARextend to here
|
15
|
+
# ot should be able to accept a proc, a module, a class, or nil(autodetect)
|
16
|
+
# -- While doing so, U could move the logic of Class.to_module && Module.to_class && Proc.to_class in "utilities" (or new rkit service)
|
17
|
+
def self.new decorated_klass, &block
|
18
|
+
Class.new(RKit::Decoration::Base, decorated_klass: decorated_klass, &block).tap do |klass|
|
19
|
+
klass.class_eval{ alias :"#{ decorated_klass.demodulize.underscore }" :__getobj__ }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class RKit::Decoration
|
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
|
+
dependency :backtrace
|
9
|
+
|
10
|
+
|
11
|
+
load_path __FILE__, 'base.rb'
|
12
|
+
load_path __FILE__, 'class.rb'
|
13
|
+
|
14
|
+
load_path __FILE__, 'action_view_base_extend.rb'
|
15
|
+
load_path __FILE__, 'active_record_extend.rb'
|
16
|
+
|
17
|
+
|
18
|
+
config :auto_decoration, true
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class RKit::Dsl::Base::Params
|
2
|
+
attr_reader :params, :params_lambda
|
3
|
+
|
4
|
+
def initialize params_lambda
|
5
|
+
raise NoLambdaError unless params_lambda.lambda?
|
6
|
+
|
7
|
+
@params_lambda = params_lambda
|
8
|
+
@params = Hash.new{ |hash, key| hash[key] = params_struct.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
def try_parameters *args, &block
|
13
|
+
@params_lambda.call *args, &block
|
14
|
+
end
|
15
|
+
|
16
|
+
def extract_parameters base, *args, &block
|
17
|
+
@params[base] = params_struct.new @params_lambda.extract_parameters(*args, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
# TODO: extract local variables may be an independant service of rkit
|
22
|
+
def extract_local_variables base
|
23
|
+
base.singleton_class.send :prepend, RKit::Dsl::Base::LocalParams
|
24
|
+
base.persisting_binding.eval(
|
25
|
+
@params[base].to_hash.map{ |name, value| "#{ name }=#{ value.inspect }" }.join(";")
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private def params_names
|
31
|
+
@params_names ||= @params_lambda.parameters.map{ |(_, name)| name }
|
32
|
+
end
|
33
|
+
|
34
|
+
private def params_struct
|
35
|
+
@params_struct ||= StrongStruct.new allowed: params_names
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RKit::Dsl::Base::Readonly < SimpleDelegator
|
2
|
+
|
3
|
+
def dsls
|
4
|
+
__getobj__.class.dsls
|
5
|
+
end
|
6
|
+
|
7
|
+
attr_accessor :base
|
8
|
+
getobj_attr_reader :name, :method, :domain, :params, :methods
|
9
|
+
|
10
|
+
alias :basic_params :params
|
11
|
+
delegate :try_parameters, :extract_parameters,
|
12
|
+
to: :basic_params
|
13
|
+
|
14
|
+
def params() basic_params.params[base] end
|
15
|
+
def extract_local_variables() basic_params.extract_local_variables(base) end
|
16
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class RKit::Dsl::Base
|
2
|
+
module Thrust
|
3
|
+
|
4
|
+
protected def thrust_dsl!
|
5
|
+
readonly = self.readonly
|
6
|
+
name = @name
|
7
|
+
|
8
|
+
@domain.send :define_singleton_method, @name do
|
9
|
+
(instance_variable_get(name.ivar) ||
|
10
|
+
instance_variable_set(name.ivar, readonly))
|
11
|
+
.tap{ |readonly| readonly.base = self }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
protected def thrust_dsl_interface!
|
16
|
+
name = @name
|
17
|
+
|
18
|
+
@domain.send :define_singleton_method, "can_#{ @method }?" do
|
19
|
+
instance_eval &send(name).methods[:allowance]
|
20
|
+
end
|
21
|
+
|
22
|
+
@domain.send :define_singleton_method, "#{ @method }?" do
|
23
|
+
send(name).dsls[name].include? self
|
24
|
+
end
|
25
|
+
|
26
|
+
@base.send :define_singleton_method, @method do
|
27
|
+
@@dsls[name]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected def thrust_dsl_options!
|
32
|
+
name = @name
|
33
|
+
|
34
|
+
@domain.send :define_singleton_method, "#{ @name }_params=" do |*args, &block|
|
35
|
+
send(name).try_parameters(*args, &block)
|
36
|
+
send(name).extract_parameters self, *args, &block
|
37
|
+
end
|
38
|
+
|
39
|
+
@domain.send :define_singleton_method, "#{ @name }_params" do
|
40
|
+
instance_variable_get("@#{ name }_params") ||
|
41
|
+
instance_variable_set("@#{ name }_params", send(name).params)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected def thrust_dsl_extend!
|
46
|
+
name = @name
|
47
|
+
|
48
|
+
@domain.send :define_singleton_method, "try_to_#{ @method }" do |*args, &block|
|
49
|
+
send "#{ name }_params=", *args, &block
|
50
|
+
|
51
|
+
if send "can_#{ send(name).method }?"
|
52
|
+
send(name).dsls[name] << self
|
53
|
+
|
54
|
+
instance_eval &send(name).methods[:class]
|
55
|
+
class_eval &send(name).methods[:instance]
|
56
|
+
decorator_klass.class_eval &send(name).methods[:decorator] if respond_to? :decorator_klass
|
57
|
+
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
@domain.send :define_singleton_method, @method do |*args, &block|
|
63
|
+
instance_eval &send(name).methods[:restriction] unless send "try_to_#{ send(name).method }", *args, &block
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
class RKit::Dsl::Base
|
2
|
+
|
3
|
+
@@dsls = Hash.new{ |hash, key| hash[key] = Array.new }
|
4
|
+
def self.dsls
|
5
|
+
@@dsls
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_accessor :base
|
9
|
+
|
10
|
+
def initialize base
|
11
|
+
@base = base
|
12
|
+
@methods = Hash.new{ |hash, key| hash[key] = proc{} }
|
13
|
+
|
14
|
+
@methods[:allowance] = proc{ true }
|
15
|
+
@methods[:restriction] = proc{ raise DslStandardError.new(self, method_name: __method__) }
|
16
|
+
# TODO: the __method__ return 'initialize', and not the "acts_as_..." that it shoul
|
17
|
+
|
18
|
+
@params = RKit::Dsl::Base::Params.new(->(){})
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def name name
|
23
|
+
@name = name
|
24
|
+
end
|
25
|
+
|
26
|
+
def method method
|
27
|
+
@method = method
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def domain domain
|
32
|
+
raise DslDefinitionError.new(@base) if [@name, @method].none?
|
33
|
+
|
34
|
+
@domain = domain
|
35
|
+
|
36
|
+
thrust_dsl!
|
37
|
+
thrust_dsl_interface!
|
38
|
+
thrust_dsl_options!
|
39
|
+
thrust_dsl_extend!
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def params params_lambda
|
44
|
+
@params = RKit::Dsl::Base::Params.new(params_lambda)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def allowed? &block
|
49
|
+
methods :allowance, &block
|
50
|
+
end
|
51
|
+
|
52
|
+
def restricted &block
|
53
|
+
methods :restriction, &block
|
54
|
+
end
|
55
|
+
|
56
|
+
def methods context, &block
|
57
|
+
@methods[context] = block
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
include RKit::Dsl::Base::Thrust
|
62
|
+
|
63
|
+
|
64
|
+
protected def readonly
|
65
|
+
RKit::Dsl::Base::Readonly.new(self)
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class DslDefinitionError < StandardError
|
2
|
+
def initialize base
|
3
|
+
# TODO: link to the doc
|
4
|
+
super %Q{
|
5
|
+
DslDefinitionError: Wrong dsl definition order on `#{ base }',
|
6
|
+
you can't declare a `domain' unless you have previously declared a `name' AND a `method'
|
7
|
+
Please, visit XXX for more details
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class DslStandardError < StandardError
|
2
|
+
def initialize base, method_name:;
|
3
|
+
super %Q{
|
4
|
+
DslStandardError: You tried to use the `#{ method_name }' DSL on `#{ base }',
|
5
|
+
Sadly, something went wrong, it seems that you can't use that DSL on your Class
|
6
|
+
Please, refer to the corresponding documentation
|
7
|
+
}
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module RKit::Dsl::ModuleExtend
|
2
|
+
|
3
|
+
def act_as_a_dsl
|
4
|
+
extend RKit::Dsl::DslExtend
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
def acts_as *names
|
9
|
+
names.each do |name|
|
10
|
+
send "acts_as_#{ name }"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def try_to_acts_as *names
|
15
|
+
names.each do |name|
|
16
|
+
send "try_to_acts_as_#{ name }"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
Module.send :include, self
|
22
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class NoLambdaError < StandardError
|
2
|
+
def initialize
|
3
|
+
# TODO: add a link to smthng that explain the difference between proc & lambda
|
4
|
+
# TODO: why not one of my videos ;)
|
5
|
+
super %Q{
|
6
|
+
NoLambdaError: You need to use a lambda, not a proc
|
7
|
+
Use the fancy ruby2 `->(){}', or the good old `lambda{}' syntax
|
8
|
+
}
|
9
|
+
end
|
10
|
+
end
|
data/lib/r_kit/dsl.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class RKit::Dsl
|
2
|
+
|
3
|
+
dependency :struct
|
4
|
+
|
5
|
+
load_path __FILE__, 'base.rb'
|
6
|
+
load_path __FILE__, 'base/local_params.rb'
|
7
|
+
load_path __FILE__, 'base/params.rb'
|
8
|
+
load_path __FILE__, 'base/readonly.rb'
|
9
|
+
load_path __FILE__, 'base/thrust.rb', priority: 1
|
10
|
+
|
11
|
+
load_path __FILE__, 'dsl_definition_error.rb'
|
12
|
+
load_path __FILE__, 'dsl_standard_error.rb'
|
13
|
+
load_path __FILE__, 'no_lambda_error.rb'
|
14
|
+
|
15
|
+
load_path __FILE__, 'dsl_extend.rb'
|
16
|
+
load_path __FILE__, 'module_extend.rb'
|
17
|
+
|
18
|
+
|
19
|
+
load_path __FILE__, 'test.rb'
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module RKit::Pagination::ActiveRecordExtend
|
2
|
+
|
3
|
+
# TODO: use rkit::dsl for this
|
4
|
+
# class X < RKit::Dsl::Base
|
5
|
+
# for Y #this is the targeted class
|
6
|
+
# name :act_as_xable
|
7
|
+
# instance_interfere do; end #class methods
|
8
|
+
# class_interfere do; end #instance_methods
|
9
|
+
# decorator_interfere do; end #decorator_methods
|
10
|
+
# can_interfere? do; #auth to load the dsl in a specific class
|
11
|
+
# end
|
12
|
+
# All of this is largely inspired by the work on ARutility
|
13
|
+
|
14
|
+
def acts_as_paginables
|
15
|
+
define_singleton_method "paginate", ->(page: nil, per_page: nil) do
|
16
|
+
RKit::Pagination::Base.new(all, page: page, per_page: per_page)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# we need to create a "paginate" scope, that will create a Pagination::base object
|
21
|
+
|
22
|
+
ActiveRecord::Base.extend self
|
23
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class RKit::Pagination::Base::Page
|
2
|
+
|
3
|
+
attr_accessor :base, :page
|
4
|
+
|
5
|
+
def initialize base, page: page
|
6
|
+
@base = base
|
7
|
+
@page = page
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
extend RKit::Decoration::ActiveRecordExtend
|
12
|
+
acts_as_decorables do
|
13
|
+
|
14
|
+
# TODO: we tried to cancel the underscored alias of __getobj__
|
15
|
+
# cause the class name is also an attr_name
|
16
|
+
# but this doesn't work, cause when you use a block, the decorator class creation will be processed after
|
17
|
+
# so, in decoration, we might whant to alias only if method not already defined
|
18
|
+
def page
|
19
|
+
__getobj__.page
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
after_initialize do
|
24
|
+
if __getobj__.page == base.page
|
25
|
+
alias :page_tag :disabled_link_to_page
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
def page_tag name = __getobj__.page
|
31
|
+
link_to_page name
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def link_to_page name = __getobj__.page
|
36
|
+
view.link_to name, view.url_for(page: __getobj__.page), class: :btn
|
37
|
+
end
|
38
|
+
|
39
|
+
def disabled_link_to_page name = __getobj__.page
|
40
|
+
view.content_tag :span, name, class: :'btn-disabled'
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
# this need
|
49
|
+
# current_page
|
50
|
+
|
51
|
+
# and a decorator
|
52
|
+
|
53
|
+
end
|