passionview 0.1.1 → 0.2.2
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 +5 -5
- data/lib/passion_view/actionable.rb +22 -1
- data/lib/passion_view/delegatable.rb +35 -0
- data/lib/passion_view/filter/base.rb +7 -2
- data/lib/passion_view/filter/simple_filter.rb +3 -1
- data/lib/passion_view/filterable.rb +13 -15
- data/lib/passion_view/form/base.rb +4 -0
- data/lib/passion_view/paginable.rb +2 -20
- data/lib/passion_view/railstie.rb +8 -0
- data/lib/passion_view/relation.rb +8 -24
- data/lib/passion_view/resourceful.rb +0 -14
- data/lib/passion_view/routable.rb +34 -33
- data/lib/passion_view/sortable.rb +0 -18
- data/lib/passion_view/view_model/base.rb +1 -1
- data/lib/passion_view/view_model/list.rb +5 -1
- data/lib/passion_view.rb +2 -0
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5718490892e384b45b6dade16f47453507efef16a8f25145cc250050365c0028
|
4
|
+
data.tar.gz: 5d12ab028481f3a94ab39bbef2823cdc99e5e9682e671288c16f3af0cee7d9a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c064b4008f3426b7ab8c8c8c7c9f141a61fe1f9ee1eff6c0803ef4e1520a8a90bb66deeeb5a807fd36190afb80ee7d2f084c803e79143d737a7e4865b58dd7f
|
7
|
+
data.tar.gz: fb96e51720c8bfa9b174e29b19bddc2e2c52449112f65cb61e4a2a40eb5e4383a07828aa4cbac52cad58b3c1b890e164dfc7b776a8c2e30c9a2f81a1b42d2c5a
|
@@ -55,7 +55,28 @@ module PassionView::Actionable
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def actions
|
59
|
+
return @actions unless @actions.nil?
|
60
|
+
@actions = ActionList.new
|
61
|
+
|
62
|
+
self.class.action_blocks.each do |block|
|
63
|
+
options = instance_eval(&block)
|
64
|
+
next if options.nil?
|
65
|
+
|
66
|
+
@actions << Action.new(options)
|
67
|
+
end
|
68
|
+
|
69
|
+
@actions
|
70
|
+
end
|
71
|
+
|
58
72
|
module ClassMethods
|
59
|
-
def
|
73
|
+
def action_blocks
|
74
|
+
@action_blocks || []
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_action(&block)
|
78
|
+
@action_blocks ||= []
|
79
|
+
@action_blocks << block
|
80
|
+
end
|
60
81
|
end
|
61
82
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PassionView::Delegatable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def delegate_prefix(*method_names)
|
6
|
+
@prefixes ||= {}
|
7
|
+
@prefixes["#{method_names.join('_')}_"] = method_names
|
8
|
+
end
|
9
|
+
|
10
|
+
def prefixes
|
11
|
+
@prefixes || {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(m, *args, &block)
|
16
|
+
self.class.prefixes.each do |prefix, method_names|
|
17
|
+
next unless m.to_s.start_with?(prefix)
|
18
|
+
|
19
|
+
last_m = m.to_s.gsub(prefix, '').to_sym
|
20
|
+
return method_names.inject(resource) do |result, method|
|
21
|
+
break if result.nil?
|
22
|
+
|
23
|
+
result.send method
|
24
|
+
end&.send(last_m)
|
25
|
+
end
|
26
|
+
|
27
|
+
return resource.send(m, *args, &block) if resource.respond_to?(m)
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def respond_to_missing?(m, _)
|
33
|
+
resource.respond_to?(m)
|
34
|
+
end
|
35
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class PassionView::Filter::Base < PassionView::ViewModel::Base
|
2
|
-
def initialize(name, options = {})
|
3
|
-
super
|
2
|
+
def initialize(name, options = {}, &block)
|
3
|
+
super(name, options)
|
4
4
|
@name = name
|
5
5
|
@value = options[:value]
|
6
|
+
@block = block
|
6
7
|
end
|
7
8
|
|
8
9
|
def skip?
|
@@ -10,4 +11,8 @@ class PassionView::Filter::Base < PassionView::ViewModel::Base
|
|
10
11
|
end
|
11
12
|
|
12
13
|
attr_reader :name, :value
|
14
|
+
|
15
|
+
def apply(items)
|
16
|
+
return @block.call(items, value) if @block
|
17
|
+
end
|
13
18
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class PassionView::Filter::SimpleFilter < PassionView::Filter::Base
|
2
|
-
def initialize(name, field:, value: [])
|
2
|
+
def initialize(name, field:, value: [], &block)
|
3
3
|
super
|
4
4
|
@field = field
|
5
5
|
end
|
6
6
|
|
7
7
|
def apply(items)
|
8
|
+
super
|
9
|
+
|
8
10
|
items.where(field => value)
|
9
11
|
end
|
10
12
|
|
@@ -3,19 +3,29 @@ module PassionView::Filterable
|
|
3
3
|
|
4
4
|
def initialize(items, options = {})
|
5
5
|
super
|
6
|
-
filters = options.delete(:filters) || {}
|
6
|
+
filters = filters_default.merge(options.delete(:filters) || {})
|
7
7
|
|
8
8
|
filter_with(filters)
|
9
9
|
end
|
10
10
|
|
11
11
|
def items
|
12
|
-
filters.reduce(super)
|
12
|
+
filters.reduce(super) do |items, filter|
|
13
|
+
filter.skip? ? items : filter.apply(items)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def filter_path
|
18
|
+
url_options
|
13
19
|
end
|
14
20
|
|
15
21
|
attr_reader :filters
|
16
22
|
|
17
23
|
private
|
18
24
|
|
25
|
+
def filters_default
|
26
|
+
{}
|
27
|
+
end
|
28
|
+
|
19
29
|
def url_options
|
20
30
|
super.merge(filterable_params)
|
21
31
|
end
|
@@ -32,10 +42,6 @@ module PassionView::Filterable
|
|
32
42
|
extend ActiveSupport::Concern
|
33
43
|
|
34
44
|
def filter_params
|
35
|
-
action = params[:action]&.to_sym
|
36
|
-
|
37
|
-
raise "Unfilterable action: #{action.inspect}" unless self.class.filter?(action)
|
38
|
-
|
39
45
|
params[:filters]&.to_unsafe_h || {}
|
40
46
|
end
|
41
47
|
|
@@ -43,20 +49,12 @@ module PassionView::Filterable
|
|
43
49
|
def filter(*actions)
|
44
50
|
filtered_actions.push(*actions)
|
45
51
|
end
|
46
|
-
|
47
|
-
def filter?(action)
|
48
|
-
filtered_actions.include?(action)
|
49
|
-
end
|
50
|
-
|
51
|
-
def filtered_actions
|
52
|
-
@filtered_actions ||= []
|
53
|
-
end
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
57
55
|
class FilterList < Array
|
58
56
|
def present
|
59
|
-
reject
|
57
|
+
reject(&:skip?)
|
60
58
|
end
|
61
59
|
end
|
62
60
|
end
|
@@ -19,7 +19,7 @@ module PassionView::Paginable
|
|
19
19
|
.per(current_per)
|
20
20
|
end
|
21
21
|
|
22
|
-
def next_pages(count = 2
|
22
|
+
def next_pages(count = 2)
|
23
23
|
(-count..count).each do |idx|
|
24
24
|
target = current_page + idx
|
25
25
|
yield target, next_page_path(idx) if block_given? && !out_of_range?(target)
|
@@ -85,7 +85,7 @@ module PassionView::Paginable
|
|
85
85
|
end
|
86
86
|
|
87
87
|
def page_path(options = {})
|
88
|
-
|
88
|
+
options
|
89
89
|
end
|
90
90
|
|
91
91
|
def url_options
|
@@ -112,25 +112,7 @@ module PassionView::Paginable
|
|
112
112
|
extend ActiveSupport::Concern
|
113
113
|
|
114
114
|
def pagination_params
|
115
|
-
action = params[:action]&.to_sym
|
116
|
-
|
117
|
-
raise "Unpaginable action: #{action.inspect}" unless self.class.paginate?(action)
|
118
|
-
|
119
115
|
params.permit(:page, :per).to_h
|
120
116
|
end
|
121
|
-
|
122
|
-
module ClassMethods
|
123
|
-
def paginate(*actions)
|
124
|
-
paginated_actions.push(*actions)
|
125
|
-
end
|
126
|
-
|
127
|
-
def paginate?(action)
|
128
|
-
paginated_actions.include?(action)
|
129
|
-
end
|
130
|
-
|
131
|
-
def paginated_actions
|
132
|
-
@paginated_actions ||= []
|
133
|
-
end
|
134
|
-
end
|
135
117
|
end
|
136
118
|
end
|
@@ -24,35 +24,19 @@ module PassionView::Relation
|
|
24
24
|
item_view_model(items.first)
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
items.count
|
29
|
-
end
|
27
|
+
delegate :count, to: :items
|
30
28
|
|
31
|
-
|
32
|
-
items.size
|
33
|
-
end
|
29
|
+
delegate :size, to: :items
|
34
30
|
|
35
|
-
|
36
|
-
items.include?(obj)
|
37
|
-
end
|
31
|
+
delegate :include?, to: :items
|
38
32
|
|
39
|
-
|
40
|
-
items.empty?
|
41
|
-
end
|
33
|
+
delegate :empty?, to: :items
|
42
34
|
|
43
|
-
|
44
|
-
items.to_sql
|
45
|
-
end
|
35
|
+
delegate :to_sql, to: :items
|
46
36
|
|
47
|
-
|
48
|
-
items.offset_value
|
49
|
-
end
|
37
|
+
delegate :offset_value, to: :items
|
50
38
|
|
51
|
-
|
52
|
-
items.total_count
|
53
|
-
end
|
39
|
+
delegate :total_count, to: :items
|
54
40
|
|
55
|
-
|
56
|
-
items.limit_value
|
57
|
-
end
|
41
|
+
delegate :limit_value, to: :items
|
58
42
|
end
|
@@ -10,25 +10,11 @@ module PassionView::Resourceful
|
|
10
10
|
@parent_resource = options[:parent]
|
11
11
|
end
|
12
12
|
|
13
|
-
def resource_path(options = {})
|
14
|
-
routes.polymorphic_path(polymorphic_components, options)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
13
|
def resource
|
20
14
|
@resource
|
21
15
|
end
|
22
16
|
|
23
|
-
def polymorphic_components
|
24
|
-
options[:polymorphic_path] || [@parent_resource, nested_resource_path].compact
|
25
|
-
end
|
26
|
-
|
27
17
|
def resource_class
|
28
18
|
@resource.klass #### @objects
|
29
19
|
end
|
30
|
-
|
31
|
-
def nested_resource_path
|
32
|
-
resource_class
|
33
|
-
end
|
34
20
|
end
|
@@ -1,42 +1,43 @@
|
|
1
1
|
# Routable exposes contextualized routes in an object
|
2
2
|
module PassionView::Routable
|
3
3
|
extend ActiveSupport::Concern
|
4
|
+
attr_reader :controller
|
4
5
|
|
5
|
-
def contextualize_routes(
|
6
|
-
|
6
|
+
def contextualize_routes(controller)
|
7
|
+
@controller = controller
|
8
|
+
routes.contextualize(controller)
|
7
9
|
end
|
8
10
|
|
9
11
|
def routes
|
10
|
-
@_routes_context ||=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end.new
|
12
|
+
@_routes_context ||= RouteContext.new
|
13
|
+
end
|
14
|
+
|
15
|
+
class RouteContext
|
16
|
+
def default_url_options
|
17
|
+
@_context ? @_context.default_url_options : {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def _routes_context
|
21
|
+
self
|
22
|
+
end
|
23
|
+
|
24
|
+
def _with_routes(routes)
|
25
|
+
old_routes, @_routes = @_routes, routes
|
26
|
+
yield
|
27
|
+
ensure
|
28
|
+
@_routes = old_routes
|
29
|
+
end
|
30
|
+
|
31
|
+
def contextualized?
|
32
|
+
!@_context.nil?
|
33
|
+
end
|
34
|
+
|
35
|
+
def contextualize(obj)
|
36
|
+
@_context = obj
|
37
|
+
end
|
38
|
+
|
39
|
+
def without_context
|
40
|
+
self.class.new
|
41
|
+
end
|
41
42
|
end
|
42
43
|
end
|
@@ -79,25 +79,7 @@ module PassionView::Sortable
|
|
79
79
|
extend ActiveSupport::Concern
|
80
80
|
|
81
81
|
def sort_params
|
82
|
-
action = params[:action]&.to_sym
|
83
|
-
|
84
|
-
raise "Unsortable action: #{action.inspect}" unless self.class.sort?(action)
|
85
|
-
|
86
82
|
params.permit(:sort, :direction).to_h
|
87
83
|
end
|
88
|
-
|
89
|
-
module ClassMethods
|
90
|
-
def sort(*actions)
|
91
|
-
sorted_actions.push(*actions)
|
92
|
-
end
|
93
|
-
|
94
|
-
def sort?(action)
|
95
|
-
sorted_actions.include?(action)
|
96
|
-
end
|
97
|
-
|
98
|
-
def sorted_actions
|
99
|
-
@sorted_actions ||= []
|
100
|
-
end
|
101
|
-
end
|
102
84
|
end
|
103
85
|
end
|
@@ -18,7 +18,11 @@ module PassionView::ViewModel::List
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def item_view_model(item)
|
21
|
-
item_view_model_class.new(item)
|
21
|
+
card = item_view_model_class.new(item)
|
22
|
+
|
23
|
+
card.contextualize_auth(user)
|
24
|
+
card.contextualize_routes(@controller) if @controller
|
25
|
+
card
|
22
26
|
end
|
23
27
|
|
24
28
|
private
|
data/lib/passion_view.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: passionview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ADHOC-GTI
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2019-07-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.46.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.46.0
|
13
27
|
description: |2
|
14
28
|
Get view logic out of persistence models and controllers and put it into
|
15
29
|
view models.
|
@@ -25,6 +39,7 @@ files:
|
|
25
39
|
- lib/passion_view/card.rb
|
26
40
|
- lib/passion_view/card/base.rb
|
27
41
|
- lib/passion_view/card/collection.rb
|
42
|
+
- lib/passion_view/delegatable.rb
|
28
43
|
- lib/passion_view/filter.rb
|
29
44
|
- lib/passion_view/filter/base.rb
|
30
45
|
- lib/passion_view/filter/simple_filter.rb
|
@@ -33,6 +48,7 @@ files:
|
|
33
48
|
- lib/passion_view/form/base.rb
|
34
49
|
- lib/passion_view/paginable.rb
|
35
50
|
- lib/passion_view/pathable.rb
|
51
|
+
- lib/passion_view/railstie.rb
|
36
52
|
- lib/passion_view/relation.rb
|
37
53
|
- lib/passion_view/resourceful.rb
|
38
54
|
- lib/passion_view/routable.rb
|
@@ -61,9 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
77
|
version: '0'
|
62
78
|
requirements: []
|
63
79
|
rubyforge_project:
|
64
|
-
rubygems_version: 2.6
|
80
|
+
rubygems_version: 2.7.6
|
65
81
|
signing_key:
|
66
82
|
specification_version: 4
|
67
83
|
summary: Love your views
|
68
84
|
test_files: []
|
69
|
-
has_rdoc:
|