wallaby-core 0.2.11 → 0.3.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/wallaby/resources_controller.rb +20 -7
- data/app/security/ability.rb +1 -1
- data/config/routes.rb +21 -14
- data/lib/adaptors/wallaby/custom/default_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_decorator.rb +5 -17
- data/lib/adaptors/wallaby/custom/model_finder.rb +3 -3
- data/lib/adaptors/wallaby/custom/model_pagination_provider.rb +1 -1
- data/lib/adaptors/wallaby/custom/model_service_provider.rb +1 -1
- data/lib/authorizers/wallaby/cancancan_authorization_provider.rb +12 -5
- data/lib/authorizers/wallaby/default_authorization_provider.rb +10 -1
- data/lib/authorizers/wallaby/model_authorizer.rb +41 -16
- data/lib/authorizers/wallaby/pundit_authorization_provider.rb +22 -8
- data/lib/concerns/wallaby/application_concern.rb +41 -71
- data/lib/concerns/wallaby/authentication_concern.rb +29 -127
- data/lib/concerns/wallaby/authorizable.rb +14 -57
- data/lib/concerns/wallaby/baseable.rb +24 -57
- data/lib/concerns/wallaby/configurable.rb +416 -0
- data/lib/concerns/wallaby/decoratable.rb +29 -60
- data/lib/concerns/wallaby/engineable.rb +29 -46
- data/lib/concerns/wallaby/fieldable.rb +45 -56
- data/lib/concerns/wallaby/paginatable.rb +20 -51
- data/lib/concerns/wallaby/prefixable.rb +24 -4
- data/lib/concerns/wallaby/resourcable.rb +130 -72
- data/lib/concerns/wallaby/resources_concern.rb +205 -305
- data/lib/concerns/wallaby/servicable.rb +8 -48
- data/lib/concerns/wallaby/urlable.rb +69 -0
- data/lib/decorators/wallaby/resource_decorator.rb +91 -34
- data/lib/errors/wallaby/class_not_found.rb +1 -2
- data/lib/errors/wallaby/forbidden.rb +1 -2
- data/lib/errors/wallaby/general_error.rb +1 -1
- data/lib/errors/wallaby/invalid_error.rb +1 -2
- data/lib/errors/wallaby/method_removed.rb +5 -0
- data/lib/errors/wallaby/model_not_found.rb +1 -2
- data/lib/errors/wallaby/not_authenticated.rb +1 -2
- data/lib/errors/wallaby/not_found.rb +1 -2
- data/lib/errors/wallaby/not_implemented.rb +1 -2
- data/lib/errors/wallaby/resource_not_found.rb +1 -2
- data/lib/errors/wallaby/unprocessable_entity.rb +1 -2
- data/lib/fields/wallaby/all_fields.rb +63 -0
- data/lib/forms/wallaby/form_builder.rb +1 -1
- data/lib/generators/wallaby/engine/application_generator.rb +33 -0
- data/lib/generators/wallaby/engine/authorizer/USAGE +20 -0
- data/lib/generators/wallaby/engine/authorizer/authorizer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/authorizer/templates/authorizer.rb.erb +35 -0
- data/lib/generators/wallaby/engine/controller/USAGE +20 -0
- data/lib/generators/wallaby/engine/controller/controller_generator.rb +23 -0
- data/lib/generators/wallaby/engine/controller/templates/controller.rb.erb +130 -0
- data/lib/generators/wallaby/engine/decorator/USAGE +20 -0
- data/lib/generators/wallaby/engine/decorator/decorator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/decorator/templates/decorator.rb.erb +5 -0
- data/lib/generators/wallaby/engine/install/USAGE +19 -0
- data/lib/generators/wallaby/engine/install/install_generator.rb +91 -0
- data/lib/generators/wallaby/engine/install/templates/application_authorizer.rb.erb +37 -0
- data/lib/generators/wallaby/engine/install/templates/application_controller.rb.erb +173 -0
- data/lib/generators/wallaby/engine/install/templates/application_decorator.rb.erb +7 -0
- data/lib/generators/wallaby/engine/install/templates/application_paginator.rb.erb +27 -0
- data/lib/generators/wallaby/engine/install/templates/application_servicer.rb.erb +47 -0
- data/lib/generators/wallaby/engine/install/templates/initializer.rb.erb +16 -0
- data/lib/generators/wallaby/engine/paginator/USAGE +20 -0
- data/lib/generators/wallaby/engine/paginator/paginator_generator.rb +19 -0
- data/lib/generators/wallaby/engine/paginator/templates/paginator.rb.erb +25 -0
- data/lib/generators/wallaby/engine/servicer/USAGE +20 -0
- data/lib/generators/wallaby/engine/servicer/servicer_generator.rb +19 -0
- data/lib/generators/wallaby/engine/servicer/templates/servicer.rb.erb +45 -0
- data/lib/helpers/wallaby/application_helper.rb +10 -59
- data/lib/helpers/wallaby/base_helper.rb +11 -11
- data/lib/helpers/wallaby/configuration_helper.rb +36 -4
- data/lib/helpers/wallaby/form_helper.rb +1 -1
- data/lib/helpers/wallaby/index_helper.rb +19 -9
- data/lib/helpers/wallaby/links_helper.rb +18 -85
- data/lib/helpers/wallaby/resources_helper.rb +39 -7
- data/lib/helpers/wallaby/secure_helper.rb +20 -19
- data/lib/interfaces/wallaby/mode.rb +8 -8
- data/lib/interfaces/wallaby/model_authorization_provider.rb +23 -22
- data/lib/interfaces/wallaby/model_decorator.rb +36 -48
- data/lib/interfaces/wallaby/model_finder.rb +3 -3
- data/lib/interfaces/wallaby/model_pagination_provider.rb +2 -6
- data/lib/interfaces/wallaby/model_service_provider.rb +4 -4
- data/lib/paginators/wallaby/model_paginator.rb +1 -1
- data/lib/responders/wallaby/json_api_responder.rb +10 -5
- data/lib/responders/wallaby/resources_responder.rb +10 -3
- data/lib/routes/wallaby/engines/base_route.rb +78 -0
- data/lib/routes/wallaby/engines/custom_app_route.rb +92 -0
- data/lib/routes/wallaby/engines/engine_route.rb +77 -0
- data/lib/routes/wallaby/resources_router.rb +100 -45
- data/lib/servicers/wallaby/model_servicer.rb +13 -13
- data/lib/services/wallaby/authorizer_finder.rb +23 -0
- data/lib/services/wallaby/class_finder.rb +42 -0
- data/lib/services/wallaby/controller_finder.rb +29 -0
- data/lib/services/wallaby/decorator_finder.rb +34 -0
- data/lib/services/wallaby/default_models_excluder.rb +45 -0
- data/lib/services/wallaby/engine_name_finder.rb +14 -11
- data/lib/services/wallaby/engine_url_for.rb +82 -37
- data/lib/services/wallaby/fields_regulator.rb +34 -0
- data/lib/services/wallaby/map/mode_mapper.rb +5 -5
- data/lib/services/wallaby/map/model_class_mapper.rb +1 -1
- data/lib/services/wallaby/model_class_filter.rb +29 -0
- data/lib/services/wallaby/paginator_finder.rb +24 -0
- data/lib/services/wallaby/prefixes_builder.rb +49 -8
- data/lib/services/wallaby/servicer_finder.rb +31 -0
- data/lib/services/wallaby/sorting/hash_builder.rb +9 -0
- data/lib/services/wallaby/sorting/link_builder.rb +7 -10
- data/lib/services/wallaby/sorting/next_builder.rb +1 -12
- data/lib/services/wallaby/sorting/single_builder.rb +1 -1
- data/lib/support/action_dispatch/routing/mapper.rb +29 -4
- data/lib/utils/wallaby/field_utils.rb +9 -8
- data/lib/utils/wallaby/inflector.rb +94 -0
- data/lib/utils/wallaby/locale.rb +2 -2
- data/lib/utils/wallaby/module_utils.rb +3 -10
- data/lib/utils/wallaby/utils.rb +21 -14
- data/lib/wallaby/class_array.rb +18 -13
- data/lib/wallaby/class_hash.rb +16 -14
- data/lib/wallaby/classifier.rb +4 -2
- data/lib/wallaby/configuration/features.rb +8 -2
- data/lib/wallaby/configuration/mapping.rb +66 -112
- data/lib/wallaby/configuration/metadata.rb +15 -12
- data/lib/wallaby/configuration/models.rb +27 -25
- data/lib/wallaby/configuration/pagination.rb +15 -19
- data/lib/wallaby/configuration/security.rb +88 -80
- data/lib/wallaby/configuration/sorting.rb +15 -17
- data/lib/wallaby/configuration.rb +58 -23
- data/lib/wallaby/constants.rb +21 -13
- data/lib/wallaby/core/version.rb +1 -1
- data/lib/wallaby/core.rb +34 -10
- data/lib/wallaby/deprecator.rb +81 -0
- data/lib/wallaby/engine.rb +1 -18
- data/lib/wallaby/guesser.rb +45 -0
- data/lib/wallaby/logger.rb +35 -13
- data/lib/wallaby/map.rb +11 -88
- data/lib/wallaby/preloader.rb +8 -28
- metadata +113 -14
- data/config/locales/wallaby_class.en.yml +0 -9
- data/lib/concerns/wallaby/defaultable.rb +0 -38
- data/lib/concerns/wallaby/shared_helpers.rb +0 -22
- data/lib/services/wallaby/map/model_class_collector.rb +0 -49
- data/lib/services/wallaby/type_renderer.rb +0 -40
- data/lib/utils/wallaby/model_utils.rb +0 -52
- data/lib/utils/wallaby/test_utils.rb +0 -34
@@ -0,0 +1,130 @@
|
|
1
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/controller.md
|
2
|
+
class <%= base_class %> < <%= parent_base_class %>
|
3
|
+
# Specify the model class if Wallaby doesn't get it right
|
4
|
+
# self.model_class = <%= model_name %>
|
5
|
+
|
6
|
+
# Specify the resource decorator if Wallaby doesn't get it right
|
7
|
+
# self.resource_decorator = <%= model_name %>Decorator
|
8
|
+
|
9
|
+
# Specify the model servicer if Wallaby doesn't get it right
|
10
|
+
# self.model_servicer = <%= model_name %>Servicer
|
11
|
+
|
12
|
+
# Specify the model authorizer if Wallaby doesn't get it right
|
13
|
+
# self.model_authorizer = <%= model_name %>Authorizer
|
14
|
+
|
15
|
+
# Specify the model paginator if Wallaby doesn't get it right
|
16
|
+
# self.model_paginator = <%= model_name %>Paginator
|
17
|
+
|
18
|
+
# Specify the max number of characters to truncate for index page
|
19
|
+
# self.max_text_length = 20
|
20
|
+
|
21
|
+
# Specify the default page size for pagination on index page
|
22
|
+
# config.page_size = 20
|
23
|
+
|
24
|
+
# Specify the sorting strategy to use. Valid values are:
|
25
|
+
# :multiple - default value, sorting is allowed on multiple columns
|
26
|
+
# :single - sorting is allowed on only one column
|
27
|
+
# config.sorting_strategy = :single
|
28
|
+
|
29
|
+
# Customize index page
|
30
|
+
# def index
|
31
|
+
# # do something before the original action
|
32
|
+
# index!(
|
33
|
+
# location: nil # where to redirect when successful
|
34
|
+
# ) do |format| # `respond_with` block
|
35
|
+
# # do something here before rendering
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Customize new page
|
40
|
+
# def new
|
41
|
+
# # do something before the original action
|
42
|
+
# new!(
|
43
|
+
# location: nil # where to redirect when successful
|
44
|
+
# ) do |format| # `respond_with` block
|
45
|
+
# # do something here before rendering
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
|
49
|
+
# Customize create action
|
50
|
+
# def create
|
51
|
+
# # do something before the original action
|
52
|
+
# create!(
|
53
|
+
# params: nil, # params to use for the servicer
|
54
|
+
# location: nil # where to redirect when successful
|
55
|
+
# ) do |format| # `respond_with` block
|
56
|
+
# # do something here before rendering
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
|
60
|
+
# Customize show page
|
61
|
+
# def show
|
62
|
+
# # do something before the original action
|
63
|
+
# show!(
|
64
|
+
# location: nil # where to redirect when successful
|
65
|
+
# ) do |format| # `respond_with` block
|
66
|
+
# # do something here before rendering
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
|
70
|
+
# Customize edit page
|
71
|
+
# def edit
|
72
|
+
# # do something before the original action
|
73
|
+
# edit!(
|
74
|
+
# location: nil # where to redirect when successful
|
75
|
+
# ) do |format| # `respond_with` block
|
76
|
+
# # do something here before rendering
|
77
|
+
# end
|
78
|
+
# end
|
79
|
+
|
80
|
+
# Customize update action
|
81
|
+
# def update
|
82
|
+
# # do something before the original action
|
83
|
+
# update!(
|
84
|
+
# params: nil, # params to use for the servicer
|
85
|
+
# location: nil # where to redirect when successful
|
86
|
+
# ) do |format| # `respond_with` block
|
87
|
+
# # do something here before rendering
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
|
91
|
+
# Customize destroy action
|
92
|
+
# def destroy
|
93
|
+
# # do something before the original action
|
94
|
+
# destroy!(
|
95
|
+
# params: nil, # params to use for the servicer
|
96
|
+
# location: nil # where to redirect when successful
|
97
|
+
# ) do |format| # `respond_with` block
|
98
|
+
# # do something here before rendering
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
|
102
|
+
# Customize what parameters to be white-listed for mass assignment
|
103
|
+
# def resource_params
|
104
|
+
# super # do something for all the subclasses
|
105
|
+
# end
|
106
|
+
|
107
|
+
# Customize how to return a collection
|
108
|
+
# def collection
|
109
|
+
# collection!(
|
110
|
+
# params: nil, # params to use for the servicer
|
111
|
+
# paginate: true # whether to paginate the collection
|
112
|
+
# ) do |records|
|
113
|
+
# # do something here after original query is completed
|
114
|
+
# # but before `@collection` instance variable is set
|
115
|
+
# records
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
|
119
|
+
# Customize how to return a resource
|
120
|
+
# def resource
|
121
|
+
# resource!(
|
122
|
+
# find_params: nil, # params/options for servicer's `find` action
|
123
|
+
# new_params: nil # params/options for servicer's `new` action
|
124
|
+
# ) do |record|
|
125
|
+
# # do something here after original query is completed
|
126
|
+
# # but before `@resource` instance variable is set
|
127
|
+
# record
|
128
|
+
# end
|
129
|
+
# end
|
130
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
Generate decorator for Wallaby Engine usage by given NAME.
|
3
|
+
It also takes the PARENT name and makes the generated decorator inherit from the PARENT.
|
4
|
+
|
5
|
+
For example, if 'apple' is provided as the NAME, this generator will carry out the following items:
|
6
|
+
- Generate AppleDecorator that inherits from Wallaby Engine's application decorator.
|
7
|
+
|
8
|
+
Example:
|
9
|
+
rails generate wallaby:engine:decorator admin/user
|
10
|
+
|
11
|
+
This will create:
|
12
|
+
- app/decorators/admin/user_decorator.rb
|
13
|
+
|
14
|
+
Example:
|
15
|
+
rails generate wallaby:engine:decorator admin/user admin/application
|
16
|
+
|
17
|
+
This will create:
|
18
|
+
- app/decorators/admin/user_decorator.rb
|
19
|
+
|
20
|
+
And it makes Admin::UserDecorator class inherit from Admin::ApplicationDecorator
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../application_generator'
|
4
|
+
|
5
|
+
module Wallaby
|
6
|
+
class Engine
|
7
|
+
# `wallaby:engine:decorator` generator
|
8
|
+
# @see https://github.com/wallaby-rails/wallaby-core/blob/master/lib/generators/wallaby/engine/decorator/USAGE
|
9
|
+
class DecoratorGenerator < ApplicationGenerator
|
10
|
+
source_root File.expand_path('templates', __dir__)
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def base_name
|
15
|
+
'decorator'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Description:
|
2
|
+
Install Wallaby Engine at the given NAME (default to 'admin').
|
3
|
+
|
4
|
+
For example, if 'admin' is provided as the NAME, this generator will carry out the following items:
|
5
|
+
- Mounting Wallaby Engine to `/admin` in `config/routes.rb`.
|
6
|
+
- Create initializer file `config/initializers/wallaby.rb`.
|
7
|
+
- Create basic application controller/decorator/servicer under camelized namespace `Admin`.
|
8
|
+
- Optionally, application authorizer and paginator can be created as well.
|
9
|
+
|
10
|
+
Example:
|
11
|
+
rails generate wallaby:engine:install admin --include-authorizer --include-paginator
|
12
|
+
|
13
|
+
This will create:
|
14
|
+
- config/initializer/wallaby.rb
|
15
|
+
- app/controllers/admin/application_controller.rb
|
16
|
+
- app/decorators/admin/application_decorator.rb
|
17
|
+
- app/servicers/admin/application_servicer.rb
|
18
|
+
- app/authorizers/admin/application_authorizer.rb
|
19
|
+
- app/paginators/admin/application_paginator.rb
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Wallaby
|
4
|
+
class Engine
|
5
|
+
# `wallaby:engine:install` generator
|
6
|
+
class InstallGenerator < Rails::Generators::NamedBase
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
argument :name, type: :string, default: 'admin'
|
9
|
+
|
10
|
+
class_option \
|
11
|
+
:mount_only,
|
12
|
+
type: :boolean, default: false,
|
13
|
+
aliases: :'-m',
|
14
|
+
desc: 'Only mount Wallaby to given name.'
|
15
|
+
|
16
|
+
class_option \
|
17
|
+
:include_authorizer,
|
18
|
+
aliases: :'-a',
|
19
|
+
type: :boolean, default: false,
|
20
|
+
desc: 'Include to generate application authorizer.'
|
21
|
+
|
22
|
+
class_option \
|
23
|
+
:include_paginator,
|
24
|
+
aliases: :'-g',
|
25
|
+
type: :boolean, default: false,
|
26
|
+
desc: 'Include to generate application paginator.'
|
27
|
+
|
28
|
+
class_option \
|
29
|
+
:include_partials,
|
30
|
+
aliases: :'-v',
|
31
|
+
type: :string, default: nil,
|
32
|
+
desc: 'Include to generate application partials'
|
33
|
+
|
34
|
+
# @see https://github.com/wallaby-rails/wallaby-core/blob/master/lib/generators/wallaby/engine/install/USAGE
|
35
|
+
def install
|
36
|
+
mount_wallaby_to_given_name
|
37
|
+
return if options[:mount_only]
|
38
|
+
|
39
|
+
create_wallaby_initializer_file
|
40
|
+
create_application_files
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
# Helper method for the template to comment out a line
|
46
|
+
def commenting
|
47
|
+
(file_name == self.class.arguments.first.default && '# ') || ''
|
48
|
+
end
|
49
|
+
|
50
|
+
def mount_wallaby_to_given_name # :nodoc:
|
51
|
+
route %(wallaby_mount at: '/#{file_name}')
|
52
|
+
rescue StandardError => e
|
53
|
+
Rails.logger.error "WARNING: #{e.message}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_wallaby_initializer_file # :nodoc:
|
57
|
+
template 'initializer.rb.erb', 'config/initializers/wallaby.rb'
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_application_files # :nodoc:
|
61
|
+
create_basic_files
|
62
|
+
create_application_authorizer if options[:include_authorizer]
|
63
|
+
create_application_paginator if options[:include_paginator]
|
64
|
+
create_application_partials if options[:include_partials]
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_basic_files # :nodoc:
|
68
|
+
template 'application_controller.rb.erb', "app/controllers/#{file_name}/application_controller.rb"
|
69
|
+
template 'application_decorator.rb.erb', "app/decorators/#{file_name}/application_decorator.rb"
|
70
|
+
template 'application_servicer.rb.erb', "app/servicers/#{file_name}/application_servicer.rb"
|
71
|
+
end
|
72
|
+
|
73
|
+
def create_application_authorizer # :nodoc:
|
74
|
+
template 'application_authorizer.rb.erb', "app/authorizers/#{file_name}/application_authorizer.rb"
|
75
|
+
end
|
76
|
+
|
77
|
+
def create_application_paginator # :nodoc:
|
78
|
+
template 'application_paginator.rb.erb', "app/paginators/#{file_name}/application_paginator.rb"
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_application_partials # :nodoc:
|
82
|
+
task =
|
83
|
+
case options[:include_partials]
|
84
|
+
when 'include_partials', true then 'wallaby:engine:partials'
|
85
|
+
else options[:include_partials]
|
86
|
+
end
|
87
|
+
invoke task, [name]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/authorizer.md
|
3
|
+
class ApplicationAuthorizer < Wallaby::ModelAuthorizer
|
4
|
+
# Mark current class as base/abstract
|
5
|
+
base_class!
|
6
|
+
|
7
|
+
# Specify which provider (:cancancan, :pundit or :default) to use.
|
8
|
+
# :default means no authorization will be in use.
|
9
|
+
# self.provider_name = :cancancan
|
10
|
+
|
11
|
+
# Check user's permission for given action on given subject.
|
12
|
+
# Raise Wallaby::Forbidden if user doesn't have permission
|
13
|
+
# def authorize(action, subject)
|
14
|
+
# super # do something for all the subclasses
|
15
|
+
# end
|
16
|
+
|
17
|
+
# Check and see if user is allowed to perform an action on given subject.
|
18
|
+
# def authorized?(action, subject)
|
19
|
+
# super # do something for all the subclasses
|
20
|
+
# end
|
21
|
+
|
22
|
+
# Filter the scope based on user's permission.
|
23
|
+
# def accessible_for(action, scope)
|
24
|
+
# super # do something for all the subclasses
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Assign the values based on user's permission.
|
28
|
+
# def attributes_for(action, subject)
|
29
|
+
# super # do something for all the subclasses
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Allowlist the parameters based on user's permission.
|
33
|
+
# def permit_params(action, subject)
|
34
|
+
# super # do something for all the subclasses
|
35
|
+
# end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/controller.md
|
3
|
+
class ApplicationController < Wallaby::ResourcesController
|
4
|
+
# Mark current class as base/abstract
|
5
|
+
base_class!
|
6
|
+
|
7
|
+
# Specify the responder
|
8
|
+
# self.responder = Wallaby::ResourcesResponder
|
9
|
+
|
10
|
+
# Specify the theme_name
|
11
|
+
# self.theme_name = '<%= file_name %>/application'
|
12
|
+
|
13
|
+
# Specify the engine name.
|
14
|
+
# It should be the same as the option `:as` for mounting Wallaby::Engine
|
15
|
+
# self.engine_name = 'wallaby_engine'
|
16
|
+
|
17
|
+
# Specify the application/base decorator
|
18
|
+
# self.application_decorator = <%= class_name %>::ApplicationDecorator
|
19
|
+
|
20
|
+
# Specify the application/base servicer
|
21
|
+
# self.application_servicer = <%= class_name %>::ApplicationServicer
|
22
|
+
|
23
|
+
# Specify the application/base authorizer
|
24
|
+
# self.application_authorizer = <%= class_name %>::ApplicationAuthorizer
|
25
|
+
|
26
|
+
# Specify the application/base paginator
|
27
|
+
# self.application_paginator = <%= class_name %>::ApplicationPaginator
|
28
|
+
|
29
|
+
# Specify the models that Wallaby should handle.
|
30
|
+
# NOTE: Once this is set, Wallaby will ignore `models_to_exclude` configuration
|
31
|
+
# self.models = User
|
32
|
+
|
33
|
+
# Specify the models that Wallaby should exclude. It's used by the models navigation in the header.
|
34
|
+
# self.models_to_exclude = ::ActiveRecord::SchemaMigration
|
35
|
+
|
36
|
+
# Specify the logout url helper method name that Wallaby uses to log user out
|
37
|
+
# self.logout_path = :logout_path
|
38
|
+
|
39
|
+
# Specify the HTTP verb for logging out a user
|
40
|
+
# self.logout_method = :delete
|
41
|
+
|
42
|
+
# Specify the method name that Wallaby uses to retrieve email from for user portrait display using gravatar.
|
43
|
+
# self.email_method = :email
|
44
|
+
|
45
|
+
# Specify the max number of characters to truncate for index page
|
46
|
+
# self.max_text_length = 20
|
47
|
+
|
48
|
+
# Specify the default page size for pagination on index page
|
49
|
+
# config.page_size = 20
|
50
|
+
|
51
|
+
# Specify the sorting strategy to use. Valid values are:
|
52
|
+
# :multiple - default value, sorting is allowed on multiple columns
|
53
|
+
# :single - sorting is allowed on only one column
|
54
|
+
# config.sorting_strategy = :single
|
55
|
+
|
56
|
+
# Customize how to authenticate a user. If a user is not authenticated, redirect them to the sign in page.
|
57
|
+
# def authenticate_wallaby_user!
|
58
|
+
# super # do something for all the subclasses
|
59
|
+
# end
|
60
|
+
|
61
|
+
# Customize how to return user record
|
62
|
+
# def wallaby_user
|
63
|
+
# super # do something for all the subclasses
|
64
|
+
# end
|
65
|
+
|
66
|
+
# Customize landing page
|
67
|
+
# def home
|
68
|
+
# super # do something for all the subclasses
|
69
|
+
# end
|
70
|
+
|
71
|
+
# Customize index page
|
72
|
+
# def index
|
73
|
+
# # do something before the original action
|
74
|
+
# index!(
|
75
|
+
# location: nil # where to redirect when successful
|
76
|
+
# ) do |format| # `respond_with` block
|
77
|
+
# # do something here before rendering
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
81
|
+
# Customize new page
|
82
|
+
# def new
|
83
|
+
# # do something before the original action
|
84
|
+
# new!(
|
85
|
+
# location: nil # where to redirect when successful
|
86
|
+
# ) do |format| # `respond_with` block
|
87
|
+
# # do something here before rendering
|
88
|
+
# end
|
89
|
+
# end
|
90
|
+
|
91
|
+
# Customize create action
|
92
|
+
# def create
|
93
|
+
# # do something before the original action
|
94
|
+
# create!(
|
95
|
+
# params: nil, # params to use for the servicer
|
96
|
+
# location: nil # where to redirect when successful
|
97
|
+
# ) do |format| # `respond_with` block
|
98
|
+
# # do something here before rendering
|
99
|
+
# end
|
100
|
+
# end
|
101
|
+
|
102
|
+
# Customize show page
|
103
|
+
# def show
|
104
|
+
# # do something before the original action
|
105
|
+
# show!(
|
106
|
+
# location: nil # where to redirect when successful
|
107
|
+
# ) do |format| # `respond_with` block
|
108
|
+
# # do something here before rendering
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
|
112
|
+
# Customize edit page
|
113
|
+
# def edit
|
114
|
+
# # do something before the original action
|
115
|
+
# edit!(
|
116
|
+
# location: nil # where to redirect when successful
|
117
|
+
# ) do |format| # `respond_with` block
|
118
|
+
# # do something here before rendering
|
119
|
+
# end
|
120
|
+
# end
|
121
|
+
|
122
|
+
# Customize update action
|
123
|
+
# def update
|
124
|
+
# # do something before the original action
|
125
|
+
# update!(
|
126
|
+
# params: nil, # params to use for the servicer
|
127
|
+
# location: nil # where to redirect when successful
|
128
|
+
# ) do |format| # `respond_with` block
|
129
|
+
# # do something here before rendering
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
|
133
|
+
# Customize destroy action
|
134
|
+
# def destroy
|
135
|
+
# # do something before the original action
|
136
|
+
# destroy!(
|
137
|
+
# params: nil, # params to use for the servicer
|
138
|
+
# location: nil # where to redirect when successful
|
139
|
+
# ) do |format| # `respond_with` block
|
140
|
+
# # do something here before rendering
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
|
144
|
+
# Customize what parameters to be white-listed for mass assignment
|
145
|
+
# def resource_params
|
146
|
+
# super # do something for all the subclasses
|
147
|
+
# end
|
148
|
+
|
149
|
+
# Customize how to return a collection
|
150
|
+
# def collection
|
151
|
+
# collection!(
|
152
|
+
# params: nil, # params to use for the servicer
|
153
|
+
# paginate: true # whether to paginate the collection
|
154
|
+
# ) do |records|
|
155
|
+
# # do something here after original query is completed
|
156
|
+
# # but before `@collection` instance variable is set
|
157
|
+
# records
|
158
|
+
# end
|
159
|
+
# end
|
160
|
+
|
161
|
+
# Customize how to return a resource
|
162
|
+
# def resource
|
163
|
+
# resource!(
|
164
|
+
# find_params: nil, # params/options for servicer's `find` action
|
165
|
+
# new_params: nil # params/options for servicer's `new` action
|
166
|
+
# ) do |record|
|
167
|
+
# # do something here after original query is completed
|
168
|
+
# # but before `@resource` instance variable is set
|
169
|
+
# record
|
170
|
+
# end
|
171
|
+
# end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/paginator.md
|
3
|
+
class ApplicationPaginator < Wallaby::ModelPaginator
|
4
|
+
# Mark current class as base/abstract
|
5
|
+
base_class!
|
6
|
+
|
7
|
+
# Check if the collection can be paginated
|
8
|
+
# def paginatable?
|
9
|
+
# super # do something for all the subclasses
|
10
|
+
# end
|
11
|
+
|
12
|
+
# Total count of the collection
|
13
|
+
# def total
|
14
|
+
# super # do something for all the subclasses
|
15
|
+
# end
|
16
|
+
|
17
|
+
# Page size
|
18
|
+
# def page_size
|
19
|
+
# super # do something for all the subclasses
|
20
|
+
# end
|
21
|
+
|
22
|
+
# Page number
|
23
|
+
# def page_number
|
24
|
+
# super # do something for all the subclasses
|
25
|
+
# end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/servicer.md
|
3
|
+
class ApplicationServicer < Wallaby::ModelServicer
|
4
|
+
# Mark current class as base/abstract
|
5
|
+
base_class!
|
6
|
+
|
7
|
+
# Allowlist parameters for mass assignment
|
8
|
+
# def permit(params, action)
|
9
|
+
# super # do something for all the subclasses
|
10
|
+
# end
|
11
|
+
|
12
|
+
# Fetch collection by given params
|
13
|
+
# def collection(params)
|
14
|
+
# super # do something for all the subclasses
|
15
|
+
# end
|
16
|
+
|
17
|
+
# Paginate the collection
|
18
|
+
# def paginate(query, params)
|
19
|
+
# super # do something for all the subclasses
|
20
|
+
# end
|
21
|
+
|
22
|
+
# Initialize the model class using given params
|
23
|
+
# def new(params)
|
24
|
+
# super # do something for all the subclasses
|
25
|
+
# end
|
26
|
+
|
27
|
+
# Find a resource using id
|
28
|
+
# def find(id, params)
|
29
|
+
# super # do something for all the subclasses
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Save the newly initialized resource
|
33
|
+
# def create(resource, params)
|
34
|
+
# super # do something for all the subclasses
|
35
|
+
# end
|
36
|
+
|
37
|
+
# Update the persisted resource
|
38
|
+
# def update(resource, params)
|
39
|
+
# super # do something for all the subclasses
|
40
|
+
# end
|
41
|
+
|
42
|
+
# Destroy the given resource
|
43
|
+
# def destroy(resource, params)
|
44
|
+
# super # do something for all the subclasses
|
45
|
+
# end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Wallaby.config do |config|
|
2
|
+
# Specify the relative folders where model resides.
|
3
|
+
# Please checkout `Rails.configuration.eager_load_paths` for the folders that can be set.
|
4
|
+
# config.model_paths = %w(app/models)
|
5
|
+
|
6
|
+
# Specify the base controller class that Wallaby::ResourcesController should inherit from.
|
7
|
+
# config.base_controller = ::ApplicationController
|
8
|
+
|
9
|
+
# Specify admin application controller for Wallaby::Engine
|
10
|
+
<%= commenting %>config.resources_controller = <%= class_name %>::ApplicationController
|
11
|
+
|
12
|
+
# Specify the non ActiveModel-like (ActiveRecord/Her) models that Wallaby should treat as Custom.
|
13
|
+
# Once it's set, you will need to implement an servicer for the Custom models.
|
14
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/custom.md#customization
|
15
|
+
# config.custom_models = [Array]
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Description:
|
2
|
+
Generate paginator for Wallaby Engine usage by given NAME.
|
3
|
+
It also takes the PARENT name and makes the generated paginator inherit from the PARENT.
|
4
|
+
|
5
|
+
For example, if 'apple' is provided as the NAME, this generator will carry out the following items:
|
6
|
+
- Generate ApplePaginator that inherits from Wallaby Engine's application paginator.
|
7
|
+
|
8
|
+
Example:
|
9
|
+
rails generate wallaby:engine:paginator admin/user
|
10
|
+
|
11
|
+
This will create:
|
12
|
+
- app/paginators/admin/user_paginator.rb
|
13
|
+
|
14
|
+
Example:
|
15
|
+
rails generate wallaby:engine:paginator admin/user admin/application
|
16
|
+
|
17
|
+
This will create:
|
18
|
+
- app/paginators/admin/user_paginator.rb
|
19
|
+
|
20
|
+
And it makes Admin::UserPaginator class inherit from Admin::ApplicationPaginator
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../application_generator'
|
4
|
+
|
5
|
+
module Wallaby
|
6
|
+
class Engine
|
7
|
+
# `wallaby:engine:paginator` generator
|
8
|
+
# @see https://github.com/wallaby-rails/wallaby-core/blob/master/lib/generators/wallaby/engine/paginator/USAGE
|
9
|
+
class PaginatorGenerator < ApplicationGenerator
|
10
|
+
source_root File.expand_path('templates', __dir__)
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def base_name
|
15
|
+
'paginator'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# @see https://github.com/wallaby-rails/wallaby/blob/master/docs/paginator.md
|
2
|
+
class <%= base_class %> < <%= parent_base_class %>
|
3
|
+
# Specify the model class if Wallaby doesn't get it right
|
4
|
+
# self.model_class = <%= model_name %>
|
5
|
+
|
6
|
+
# Check if the collection can be paginated
|
7
|
+
# def paginatable?
|
8
|
+
# super # do something for all the subclasses
|
9
|
+
# end
|
10
|
+
|
11
|
+
# Total count of the collection
|
12
|
+
# def total
|
13
|
+
# super # do something for all the subclasses
|
14
|
+
# end
|
15
|
+
|
16
|
+
# Page size
|
17
|
+
# def page_size
|
18
|
+
# super # do something for all the subclasses
|
19
|
+
# end
|
20
|
+
|
21
|
+
# Page number
|
22
|
+
# def page_number
|
23
|
+
# super # do something for all the subclasses
|
24
|
+
# end
|
25
|
+
end
|