tybo 0.0.12 → 0.0.13
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/README.md +12 -0
- data/lib/generators/bo/bo_generator.rb +9 -3
- data/lib/generators/bo/templates/_form.html.erb +4 -1
- data/lib/generators/bo/templates/controller.rb +18 -2
- data/lib/generators/bo/templates/namespace_policy.rb +29 -0
- data/lib/generators/bo/templates/policy.rb +6 -0
- data/lib/generators/bo_namespace/templates/admin_controller.rb +1 -0
- data/lib/generators/bo_namespace/templates/policy.rb +4 -0
- data/lib/tybo/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2159c6fe429376273f6ba05ab4009d6714a61c09a2fe9d9ad5395c23ad679f69
|
4
|
+
data.tar.gz: fedf0c5fc19e0d446fa3ce7ba4d32d8bf6aaf82b64b6138a1fef740cf8bc8c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02e9964ddfc462d39f6f4b112bf255036fe5a6fd76e6a40cf88cefa407f5ab7349a7c9b5e5707a38a5daa627fb676cef6789f7ca7367182846351e47b5202ada
|
7
|
+
data.tar.gz: d3d971269635d970e6b1d692b3c5ee489eb948b074eb1c93d01c092d8faba236d6e06fcee2d92f5220ea29514fa3d45097f84552d3e9753a1696cfbb793f4764
|
data/README.md
CHANGED
@@ -34,6 +34,18 @@ $ bundle exec rails g tybo_install
|
|
34
34
|
|
35
35
|
```
|
36
36
|
|
37
|
+
## Policy
|
38
|
+
add your policy logic in ApplicationController eg:
|
39
|
+
```
|
40
|
+
rescue_from ActionPolicy::Unauthorized, with: :not_authorized
|
41
|
+
|
42
|
+
|
43
|
+
def not_authorized
|
44
|
+
flash[:alert] = I18n.t('bo.unauthorized')
|
45
|
+
redirect_to(request.referrer || root_path)
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
37
49
|
## Customize
|
38
50
|
|
39
51
|
**Update images**: change `logo_url` and `cover_url` in `config/initializer/tybo.rb`
|
@@ -19,6 +19,10 @@ class BoGenerator < Rails::Generators::NamedBase
|
|
19
19
|
template '_search_bar.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/_search_bar.html.erb")
|
20
20
|
template 'show.html.erb', File.join("app/views/#{options[:namespace]}", "#{plural_name}/show.html.erb")
|
21
21
|
template 'controller.rb', File.join("app/controllers/#{options[:namespace]}", "#{plural_name}_controller.rb")
|
22
|
+
template 'policy.rb', File.join("app/policies/bo/#{options[:namespace]}", "#{file_name.underscore}_policy.rb")
|
23
|
+
unless File.exists?("app/policies/bo/#{options[:namespace]}.rb")
|
24
|
+
template 'namespace_policy.rb', "app/policies/bo/#{options[:namespace]}_policy.rb"
|
25
|
+
end
|
22
26
|
create_translations
|
23
27
|
end
|
24
28
|
|
@@ -65,7 +69,7 @@ class BoGenerator < Rails::Generators::NamedBase
|
|
65
69
|
|
66
70
|
def permited_params
|
67
71
|
params = {}
|
68
|
-
action_text_columns= has_one_assoc&.select {|a| a.
|
72
|
+
action_text_columns= has_one_assoc&.select {|a| a.options[:class_name] == 'ActionText::RichText'}
|
69
73
|
model_columns&.map do |col|
|
70
74
|
params["#{col}".to_sym] = nil
|
71
75
|
end
|
@@ -76,8 +80,10 @@ class BoGenerator < Rails::Generators::NamedBase
|
|
76
80
|
params["#{association.name.to_s.singularize}_ids".to_sym] = []
|
77
81
|
end
|
78
82
|
has_one_assoc&.map do |association|
|
79
|
-
|
80
|
-
|
83
|
+
next if association.options[:class_name] == 'ActionText::RichText'
|
84
|
+
|
85
|
+
attributes = association.klass.column_names.map(&:to_sym).delete_if {|attr| excluded_columns.include?(attr)}
|
86
|
+
params["#{association.name.to_s.singularize}_attributes".to_sym] = attributes
|
81
87
|
end
|
82
88
|
params
|
83
89
|
end
|
@@ -11,7 +11,10 @@
|
|
11
11
|
<!-- has_one Associations -->
|
12
12
|
<%- has_one_assoc.each do |association| -%>
|
13
13
|
<%- if association.options[:class_name] == "ActionText::RichText" -%>
|
14
|
-
|
14
|
+
<label class="block my-5 block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600">
|
15
|
+
<%%= I18n.t('bo.<%= class_name.underscore %>.attributes.<%=- association.name.to_s.singularize.to_s.remove('rich_text_') -%>') %>
|
16
|
+
</label>
|
17
|
+
<%%= f.rich_text_area :<%= association.name.to_s.singularize.to_s.remove('rich_text_')%> %>
|
15
18
|
<%- else -%>
|
16
19
|
<%%= render(Forms::HasOneFormComponent.new(title: I18n.t('bo.<%= association.name %>.one') )) do %>
|
17
20
|
<%%= f.simple_fields_for :<%= association.name.to_s %> do |<%= association.name.to_s %>_form| %>
|
@@ -5,11 +5,15 @@ module <%= options[:namespace].camelize %>
|
|
5
5
|
before_action :set_<%= class_name.underscore %>, only: %i[show edit destroy update]
|
6
6
|
|
7
7
|
def index
|
8
|
-
@q =
|
8
|
+
@q = authorized_scope(
|
9
|
+
<%=class_name%>.all,
|
10
|
+
with: Bo::<%= options[:namespace].camelize %>::<%= class_name %>Policy
|
11
|
+
).ransack(params[:q])
|
9
12
|
@pagy, @<%= class_name.pluralize.underscore %> = pagy(@q.result(distinct: true))
|
10
13
|
end
|
11
14
|
|
12
15
|
def show
|
16
|
+
authorize! @<%= class_name.underscore %>, to: :show?, namespace:, strict_namespace: true
|
13
17
|
<%- has_one_assoc.each do |association| -%>
|
14
18
|
<%- next if association.options[:class_name] == "ActionText::RichText" -%>
|
15
19
|
@<%= class_name.underscore %>.build_<%= association.name %> if @<%= class_name.underscore %>.<%= association.name %>.nil?
|
@@ -18,16 +22,20 @@ module <%= options[:namespace].camelize %>
|
|
18
22
|
|
19
23
|
def new
|
20
24
|
@<%= class_name.underscore %> = <%= class_name %>.new
|
25
|
+
authorize! @<%= class_name.underscore %>, to: :new?, namespace:, strict_namespace: true
|
21
26
|
<%- has_one_assoc.each do |association| -%>
|
22
27
|
<%- next if association.options[:class_name] == "ActionText::RichText" -%>
|
23
28
|
@<%= class_name.underscore %>.build_<%= association.name %>
|
24
29
|
<%- end -%>
|
25
30
|
end
|
26
31
|
|
27
|
-
def edit
|
32
|
+
def edit
|
33
|
+
authorize! @<%= class_name.underscore %>, to: :edit?, namespace:, strict_namespace: true
|
34
|
+
end
|
28
35
|
|
29
36
|
def create
|
30
37
|
@<%= class_name.underscore %> = <%= class_name %>.new(<%= class_name.underscore %>_params)
|
38
|
+
authorize! @<%= class_name.underscore %>, to: :create?, namespace:, strict_namespace: true
|
31
39
|
|
32
40
|
if @<%= class_name.underscore %>.save
|
33
41
|
flash[:success] = t('bo.record.created')
|
@@ -38,6 +46,8 @@ module <%= options[:namespace].camelize %>
|
|
38
46
|
end
|
39
47
|
|
40
48
|
def update
|
49
|
+
authorize! @<%= class_name.underscore %>, to: :update?, namespace:, strict_namespace: true
|
50
|
+
|
41
51
|
if @<%= class_name.underscore %>.update(<%= class_name.underscore %>_params)
|
42
52
|
flash[:success] = t('bo.record.updated')
|
43
53
|
redirect_to <%="#{options[:namespace]}_#{class_name.underscore}_path"%>
|
@@ -47,6 +57,8 @@ module <%= options[:namespace].camelize %>
|
|
47
57
|
end
|
48
58
|
|
49
59
|
def destroy
|
60
|
+
authorize! @<%= class_name.underscore %>, to: :destroy?, namespace:, strict_namespace: true
|
61
|
+
|
50
62
|
@<%= class_name.underscore %>.destroy
|
51
63
|
flash[:success] = t('bo.record.destroyed')
|
52
64
|
|
@@ -70,5 +82,9 @@ module <%= options[:namespace].camelize %>
|
|
70
82
|
<%- end -%>
|
71
83
|
)
|
72
84
|
end
|
85
|
+
|
86
|
+
def namespace
|
87
|
+
@namespace ||= Bo::<%= options[:namespace].camelize %>
|
88
|
+
end
|
73
89
|
end
|
74
90
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Bo
|
2
|
+
class <%= options[:namespace].camelize %>Policy < ActionPolicy::Base
|
3
|
+
def show?
|
4
|
+
true
|
5
|
+
end
|
6
|
+
|
7
|
+
def new?
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
def edit?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def create?
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def update?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def destroy?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
relation_scope(&:all)
|
28
|
+
end
|
29
|
+
end
|
data/lib/tybo/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tybo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Delpierre
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-02-
|
12
|
+
date: 2023-02-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -241,7 +241,9 @@ files:
|
|
241
241
|
- lib/generators/bo/templates/controller.rb
|
242
242
|
- lib/generators/bo/templates/index.html.erb
|
243
243
|
- lib/generators/bo/templates/item.html.erb
|
244
|
+
- lib/generators/bo/templates/namespace_policy.rb
|
244
245
|
- lib/generators/bo/templates/new.html.erb
|
246
|
+
- lib/generators/bo/templates/policy.rb
|
245
247
|
- lib/generators/bo/templates/show.html.erb
|
246
248
|
- lib/generators/bo/utils/files/fr.json
|
247
249
|
- lib/generators/bo/utils/translations.rb
|
@@ -249,6 +251,7 @@ files:
|
|
249
251
|
- lib/generators/bo_namespace/bo_namespace_generator.rb
|
250
252
|
- lib/generators/bo_namespace/templates/admin.html.erb
|
251
253
|
- lib/generators/bo_namespace/templates/admin_controller.rb
|
254
|
+
- lib/generators/bo_namespace/templates/policy.rb
|
252
255
|
- lib/generators/bo_namespace/templates/seeds.rb
|
253
256
|
- lib/generators/bo_namespace/templates/side_bar.html.erb
|
254
257
|
- lib/generators/tybo_install/templates/application.tailwind.css
|