tybo 0.0.7 → 0.0.9

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: 9adcf1453a167d928120910dee95eb19b31e018593b09cff193c5fea7f1148e1
4
- data.tar.gz: 45d9027230f376f2634e42b0c9584d0e772792f36444f30b9d594200d8cbd6b1
3
+ metadata.gz: daa02ecc2547566ac774ab1e182054ff7a9cfbaa7c45561338e2b706536eafe8
4
+ data.tar.gz: 8f506d40fe83c7856efceb1f1b5eb55ebdee15a5769ae4e59332850f2d18bfc7
5
5
  SHA512:
6
- metadata.gz: c1fd62b3a41a0638c9da59f555198aac3d0349031095210167ecd4267255b999ad0715b57c821e96e0e7b943e85af6071dd8862c01fec8129c9a8c84cc4bd20a
7
- data.tar.gz: 9be1f03398c851dcf2c31b29e0ddebaa4d26911118c61b5d4cf214ac413cc3b7276d82332b26a5b60778ac3120e405733879934fae05844f7b571a13f71e88e7
6
+ metadata.gz: 0dfda4edfd7ed96a710117404e4247ab4a99b65af0da16b9ed71416e142c1c3ce01adff087dd463c474751d6d2aa07be437d02267ab2abc7d3af03df2ebbdb15
7
+ data.tar.gz: 5fef87ba89d3bb1deb46b6848239e4acfa717b60cbde1b714c75112cdb84546dd35913be7c349257e3c637a86bba5e86fe434b0a6c0fe25b134d147f32198dda
@@ -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="office_user_ids"><%= @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
@@ -0,0 +1,10 @@
1
+ <div class="space-y-6 sm:space-y-5">
2
+ <div>
3
+ <h3 class="text-lg font-medium leading-6 text-gray-900"><%= @title %></h3>
4
+ </div>
5
+ <div class="space-y-6 sm:space-y-5">
6
+ <div class="sm:items-start sm:gap-4 sm:border-t sm:border-gray-200 sm:pt-5">
7
+ <%= content %>
8
+ </div>
9
+ </div>
10
+ </div>
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Forms
3
+ class HasOneFormComponent < ViewComponent::Base
4
+ def initialize(title:)
5
+ @title = title
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
1
+ <svg class="mr-3 flex-shrink-0 text-white h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
3
3
  </svg>
@@ -1,3 +1,4 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
3
3
  </svg>
4
+
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z" />
3
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M12 7.5h1.5m-1.5 3h1.5m-7.5 3h7.5m-7.5 3h7.5m3-9h3.375c.621 0 1.125.504 1.125 1.125V18a2.25 2.25 0 01-2.25 2.25M16.5 7.5V18a2.25 2.25 0 002.25 2.25M16.5 7.5V4.875c0-.621-.504-1.125-1.125-1.125H4.125C3.504 3.75 3 4.254 3 4.875V18a2.25 2.25 0 002.25 2.25h13.5M6 7.5h3v3H6v-3z" />
3
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
3
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M8.228 9c.549-1.165 2.03-2 3.772-2 2.21 0 4 1.343 4 3 0 1.4-1.278 2.575-3.006 2.907-.542.104-.994.54-.994 1.093m0 3h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
3
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6" xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white" xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
2
2
  <path strokeLinecap="round" strokeLinejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
3
3
  </svg>
@@ -1,3 +1,3 @@
1
- <svg class="mr-3 flex-shrink-0 h-6 w-6 text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
1
+ <svg class="mr-3 flex-shrink-0 h-6 w-6 text-white text-sidebar-50" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
2
2
  <path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"/>
3
3
  </svg>
@@ -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
@@ -13,20 +13,28 @@
13
13
  <%- if association.options[:class_name] == "ActionText::RichText" -%>
14
14
  <%%= f.rich_text_area :<%= association.name.to_s.singularize.to_s.remove('rich_text_' )%> %>
15
15
  <%- else -%>
16
- <%%= f.input :<%= association.foreign_key %>, collection: <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] } %>
16
+ <%%= render(Forms::HasOneFormComponent.new(title: I18n.t('bo.<%= association.name %>.one') )) do %>
17
+ <%%= f.simple_fields_for :<%= association.name.to_s %> do |<%= association.name.to_s %>_form| %>
18
+ <%- association.klass.column_names.each do |column| -%>
19
+ <%- next if excluded_columns.include?(column.to_sym) || bo_model.reflect_on_all_associations.map(&:foreign_key).include?(column) -%>
20
+ <%- simple_form_alias = simple_form_conflict_keywords.include?(column) ? ',as: :string' : nil -%>
21
+ <%%= <%= association.name.to_s %>_form.input :<%= column %> <%= simple_form_alias %> %>
22
+ <%- end -%>
23
+ <%% end %>
24
+ <%% end %>
25
+
17
26
  <%- end -%>
18
27
  <%- end -%>
19
-
20
28
  <!-- has_many Associations -->
21
29
  <%- has_many_assoc.each do |association| -%>
22
- <div class="my-5 select">
23
- <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 %>
24
31
  <%%= f.select :<%= "#{association.name.to_s.singularize}_ids" %>,
25
- <%= association.klass.name %>.all.map { |item| [item.<%=bo_model_title(association.klass.name.constantize)%>, item.id] },
26
- { include_blank: true },
27
- multiple: true,
28
- data: { controller: 'ts--select' } %>
29
- </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
+
30
38
  <%- end -%>
31
39
  <%%= render(Forms::SubmitButtonComponent.new) %>
32
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.7'
2
+ VERSION = '0.0.9'
3
3
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tybo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
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-06 00:00:00.000000000 Z
12
+ date: 2023-02-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -141,6 +141,10 @@ files:
141
141
  - app/components/forms/delete_button_component.rb
142
142
  - app/components/forms/divider_component.html.erb
143
143
  - app/components/forms/divider_component.rb
144
+ - app/components/forms/has_many_form_component.html.erb
145
+ - app/components/forms/has_many_form_component.rb
146
+ - app/components/forms/has_one_form_component.html.erb
147
+ - app/components/forms/has_one_form_component.rb
144
148
  - app/components/forms/submit_button_component.html.erb
145
149
  - app/components/forms/submit_button_component.rb
146
150
  - app/components/forms/subtitle_component.html.erb
@@ -258,7 +262,7 @@ licenses:
258
262
  - MIT
259
263
  metadata:
260
264
  homepage_uri: https://rubygems.org/gems/tybo
261
- post_install_message:
265
+ post_install_message:
262
266
  rdoc_options: []
263
267
  require_paths:
264
268
  - lib
@@ -273,8 +277,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
273
277
  - !ruby/object:Gem::Version
274
278
  version: '0'
275
279
  requirements: []
276
- rubygems_version: 3.0.3.1
277
- signing_key:
280
+ rubygems_version: 3.2.3
281
+ signing_key:
278
282
  specification_version: 4
279
283
  summary: A tailwind custom admin engine for Ruby on Rails
280
284
  test_files: []