tybo 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d93a3e02b0858c49f45215e8457294b3dbe7a70e66c9cdce463324a86cc65414
4
- data.tar.gz: '09ca1b2fadff5a2bc2d8c0c32192bd506618916c9cb734341831b2e3478b1d37'
3
+ metadata.gz: b1b3c4530961254cdb6ef8c5931b6596eecf9f1b2b9b26281906631db4a5ae9b
4
+ data.tar.gz: 45f675158171c7ce693e741f1aa34c499eaef8b61e3fda02a6e537b4e5605bb2
5
5
  SHA512:
6
- metadata.gz: 74f8a9aaafeeea63b8a26d8336a9d77d7d945e04c106b3e2703c1d4900e1d0a0f7a11398aa87b2ee0e948c86cd8c24959737d3263eff66360baca567a61a9ce0
7
- data.tar.gz: 237dc58da09eee1ce80bd2295778acd88cc715089726e067755b9b6340530f58dda6c84b707fc7115b450a8f5a4e81733e22da099492470f4975b18b548c240f
6
+ metadata.gz: e2d620781d5f140fce8acbf7a27a7436b5c5a12a08d3b811a78771af38877f5ac2afb750215ad4aef6c1649987284335685a7d4d225b872be3ad2b8fe54c5756
7
+ data.tar.gz: 0e927000a3d8db43bee7a97d9df82ea15a012d066d93158139806bd297bde7173c606fcef4c45c6c30ce8668bd6dc40b24eaeabdfced8f5a705375d2799c5fed
@@ -0,0 +1,5 @@
1
+ <!-- has_many Associations -->
2
+ <div class="my-5 select">
3
+ <label class="block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600" for="<%= @title %>"><%= @title %></label>
4
+ <%= content %>
5
+ </div>
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Forms
3
+ class HasManyFormComponent < ViewComponent::Base
4
+ def initialize(title:)
5
+ @title = title
6
+ end
7
+ end
8
+ end
@@ -6,6 +6,7 @@ class BoGenerator < Rails::Generators::NamedBase
6
6
 
7
7
  check_class_collision suffix: 'bo'
8
8
  class_option :namespace, type: :string, default: 'administrators'
9
+
9
10
  def create_bo_file
10
11
  # Template method
11
12
  # First argument is the name of the template
@@ -21,12 +22,11 @@ class BoGenerator < Rails::Generators::NamedBase
21
22
  create_translations
22
23
  end
23
24
 
24
- def bo_model
25
- class_name.constantize
26
- end
27
25
 
28
- def plural_name
29
- file_name.pluralize
26
+ def add_link_to_side_bar
27
+ inject_into_file "app/views/#{options[:namespace]}/layouts/_side_bar.html.erb", before: " <%= sidebar.with_current_user_card(user: current_#{options[:namespace].singularize}) %>\n" do
28
+ " <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n"
29
+ end
30
30
  end
31
31
 
32
32
  def create_routes
@@ -35,10 +35,24 @@ class BoGenerator < Rails::Generators::NamedBase
35
35
  end
36
36
  end
37
37
 
38
+ private
39
+
40
+ def bo_model
41
+ class_name.constantize
42
+ end
43
+
44
+ def plural_name
45
+ file_name.pluralize
46
+ end
47
+
38
48
  def model_columns
39
49
  bo_model.column_names.map(&:to_sym)
40
50
  end
41
51
 
52
+ def simple_form_conflict_keywords
53
+ %w[country country_code]
54
+ end
55
+
42
56
  def bo_model_title(model=nil)
43
57
  return unless model
44
58
 
@@ -61,6 +75,10 @@ class BoGenerator < Rails::Generators::NamedBase
61
75
  has_many_assoc&.map do |association|
62
76
  params["#{association.name.to_s.singularize}_ids".to_sym] = []
63
77
  end
78
+ has_one_assoc&.map do |association|
79
+ attributes = association.klass.column_names.map(&:to_sym).delete_if {|attr| excluded_columns.include?(attr)}
80
+ params["#{association.name.to_s.singularize}_attributes".to_sym] = attributes
81
+ end
64
82
  params
65
83
  end
66
84
 
@@ -80,9 +98,4 @@ class BoGenerator < Rails::Generators::NamedBase
80
98
  model_columns - excluded_columns
81
99
  end
82
100
 
83
- def add_link_to_side_bar
84
- inject_into_file "app/views/#{options[:namespace]}/layouts/_side_bar.html.erb", before: " <%= sidebar.with_current_user_card(user: current_#{options[:namespace].singularize}) %>\n" do
85
- " <%= sidebar.with_item(path: #{options[:namespace]}_#{plural_name}_path, icon: Icons::UsersComponent, label: I18n.t('bo.#{file_name}.others').capitalize) %>\n"
86
- end
87
- end
88
101
  end
@@ -17,24 +17,24 @@
17
17
  <%%= f.simple_fields_for :<%= association.name.to_s %> do |<%= association.name.to_s %>_form| %>
18
18
  <%- association.klass.column_names.each do |column| -%>
19
19
  <%- next if excluded_columns.include?(column.to_sym) || bo_model.reflect_on_all_associations.map(&:foreign_key).include?(column) -%>
20
- <%- simple_form_alias = %w[country country_code].include?(column) ? ',as: :string' : nil -%>
20
+ <%- simple_form_alias = simple_form_conflict_keywords.include?(column) ? ',as: :string' : nil -%>
21
21
  <%%= <%= association.name.to_s %>_form.input :<%= column %> <%= simple_form_alias %> %>
22
22
  <%- end -%>
23
- <%% end %>
23
+ <%% end %>
24
24
  <%% end %>
25
+
25
26
  <%- end -%>
26
27
  <%- end -%>
27
-
28
28
  <!-- has_many Associations -->
29
29
  <%- has_many_assoc.each do |association| -%>
30
- <div class="my-5 select">
31
- <label class="block text-sm font-medium text-gray-700 string optional text-sm font-medium text-gray-600" for="<%= "#{class_name.underscore}_#{association.name.to_s.singularize}_ids" %>"><%= association.name.to_s.singularize%></label>
30
+ <%%= render(Forms::HasManyFormComponent.new(title: I18n.t('bo.<%= association.name.to_s.singularize%>.others') )) do %>
32
31
  <%%= f.select :<%= "#{association.name.to_s.singularize}_ids" %>,
33
- <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] },
34
- { include_blank: true },
35
- multiple: true,
36
- data: { controller: 'ts--select' } %>
37
- </div>
32
+ <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] },
33
+ { include_blank: true },
34
+ multiple: true,
35
+ data: { controller: 'ts--select' } %>
36
+ <%% end %>
37
+
38
38
  <%- end -%>
39
39
  <%%= render(Forms::SubmitButtonComponent.new) %>
40
40
  <%% end %>
@@ -1,4 +1,4 @@
1
- <div class="relative inline-block text-left" data-controller="dropdown">
1
+ <div class="relative mt-3 inline-block text-left" data-controller="dropdown">
2
2
  <div>
3
3
  <button data-action="click->dropdown#toggle click@window->dropdown#hide" type="button" class="inline-flex w-full justify-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none " id="menu-button" aria-expanded="true" aria-haspopup="true">
4
4
  <%%= I18n.t('bo.filters') %>
@@ -9,26 +9,34 @@ module <%= options[:namespace].camelize %>
9
9
  @pagy, @<%= class_name.pluralize.underscore %> = pagy(@q.result(distinct: true))
10
10
  end
11
11
 
12
- def show; end
12
+ def show
13
+ <%- has_one_assoc.each do |association| -%>
14
+ <%- next if association.options[:class_name] == "ActionText::RichText" -%>
15
+ @<%= class_name.underscore %>.build_<%= association.name %> if @<%= class_name.underscore %>.<%= association.name %>.nil?
16
+ <%- end -%>
17
+ end
13
18
 
14
19
  def new
15
20
  @<%= class_name.underscore %> = <%= class_name %>.new
21
+ <%- has_one_assoc.each do |association| -%>
22
+ <%- next if association.options[:class_name] == "ActionText::RichText" -%>
23
+ @<%= class_name.underscore %>.build_<%= association.name %>
24
+ <%- end -%>
16
25
  end
17
26
 
27
+ def edit; end
28
+
18
29
  def create
19
30
  @<%= class_name.underscore %> = <%= class_name %>.new(<%= class_name.underscore %>_params)
20
31
 
21
32
  if @<%= class_name.underscore %>.save
22
33
  flash[:success] = t('bo.record.created')
23
34
  redirect_to <%="#{options[:namespace]}_#{class_name.underscore.pluralize}_path"%>
24
-
25
35
  else
26
36
  render :new, status: :unprocessable_entity
27
37
  end
28
38
  end
29
39
 
30
- def edit; end
31
-
32
40
  def update
33
41
  if @<%= class_name.underscore %>.update(<%= class_name.underscore %>_params)
34
42
  flash[:success] = t('bo.record.updated')
@@ -44,7 +52,7 @@ module <%= options[:namespace].camelize %>
44
52
 
45
53
  redirect_to <%="#{options[:namespace]}_#{class_name.underscore.pluralize}_path"%>, status: :see_other
46
54
  end
47
-
55
+
48
56
  private
49
57
 
50
58
  def set_<%= class_name.underscore %>
@@ -57,7 +65,7 @@ module <%= options[:namespace].camelize %>
57
65
  <%- if value.nil? -%>
58
66
  :<%= key %><%=permited_params.count == (index +1) ? '' : ',' %>
59
67
  <%- else -%>
60
- <%= "#{key}: []" %><%=permited_params.count == (index +1) ? '' : ',' %>
68
+ <%= "#{key}: %i[#{value.join(" ")}]" %><%=permited_params.count == (index +1) ? '' : ',' %>
61
69
  <%- end -%>
62
70
  <%- end -%>
63
71
  )
data/lib/tybo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tybo
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.10'
3
3
  end
metadata CHANGED
@@ -1,20 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tybo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Delpierre
8
8
  - Julien Camblan
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-02-07 00:00:00.000000000 Z
12
+ date: 2023-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '7.0'
18
21
  - - ">="
19
22
  - !ruby/object:Gem::Version
20
23
  version: 7.0.4.1
@@ -22,6 +25,9 @@ dependencies:
22
25
  prerelease: false
23
26
  version_requirements: !ruby/object:Gem::Requirement
24
27
  requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '7.0'
25
31
  - - ">="
26
32
  - !ruby/object:Gem::Version
27
33
  version: 7.0.4.1
@@ -141,6 +147,8 @@ files:
141
147
  - app/components/forms/delete_button_component.rb
142
148
  - app/components/forms/divider_component.html.erb
143
149
  - app/components/forms/divider_component.rb
150
+ - app/components/forms/has_many_form_component.html.erb
151
+ - app/components/forms/has_many_form_component.rb
144
152
  - app/components/forms/has_one_form_component.html.erb
145
153
  - app/components/forms/has_one_form_component.rb
146
154
  - app/components/forms/submit_button_component.html.erb
@@ -260,7 +268,7 @@ licenses:
260
268
  - MIT
261
269
  metadata:
262
270
  homepage_uri: https://rubygems.org/gems/tybo
263
- post_install_message:
271
+ post_install_message:
264
272
  rdoc_options: []
265
273
  require_paths:
266
274
  - lib
@@ -275,8 +283,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
275
283
  - !ruby/object:Gem::Version
276
284
  version: '0'
277
285
  requirements: []
278
- rubygems_version: 3.2.3
279
- signing_key:
286
+ rubygems_version: 3.0.3.1
287
+ signing_key:
280
288
  specification_version: 4
281
289
  summary: A tailwind custom admin engine for Ruby on Rails
282
290
  test_files: []