headmin 0.3.2 → 0.3.3

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +27 -23
  5. data/app/assets/images/document.docx +0 -0
  6. data/app/assets/images/document.pdf +0 -0
  7. data/app/assets/images/image.jpg +0 -0
  8. data/app/assets/images/spreadsheet.xls +0 -0
  9. data/app/assets/images/video.mp4 +0 -0
  10. data/app/assets/javascripts/headmin/controllers/table_actions_controller.js +2 -2
  11. data/app/assets/javascripts/headmin/controllers/table_controller.js +28 -13
  12. data/app/assets/javascripts/headmin/index.js +0 -4
  13. data/app/assets/javascripts/headmin.js +33 -696
  14. data/app/assets/stylesheets/headmin/form.scss +4 -4
  15. data/app/assets/stylesheets/headmin/vendor/tom-select-bootstrap.css +1 -2
  16. data/app/assets/stylesheets/headmin.css +3 -3
  17. data/app/controllers/concerns/headmin/authentication.rb +1 -1
  18. data/app/controllers/concerns/headmin/searchable.rb +1 -1
  19. data/app/controllers/concerns/headmin/sortable.rb +7 -7
  20. data/app/helpers/headmin/admin_helper.rb +1 -1
  21. data/app/helpers/headmin/bootstrap_helper.rb +2 -24
  22. data/app/helpers/headmin/documentation_helper.rb +1 -1
  23. data/app/helpers/headmin/filter_helper.rb +1 -1
  24. data/app/helpers/headmin/form_helper.rb +3 -3
  25. data/app/helpers/headmin/notification_helper.rb +21 -21
  26. data/app/helpers/headmin/request_helper.rb +3 -3
  27. data/app/models/concerns/headmin/block.rb +1 -2
  28. data/app/models/concerns/headmin/blockable.rb +1 -1
  29. data/app/models/concerns/headmin/field.rb +1 -1
  30. data/app/models/concerns/headmin/fieldable.rb +8 -8
  31. data/app/models/headmin/documentation_renderer.rb +4 -4
  32. data/app/models/headmin/form/base.rb +1 -2
  33. data/app/models/headmin/form/text.rb +5 -7
  34. data/app/models/headmin/thumbnail.rb +61 -0
  35. data/app/services/block_service.rb +53 -53
  36. data/app/views/headmin/_thumbnail.html.erb +42 -40
  37. data/app/views/headmin/dropdown/_item.html.erb +1 -1
  38. data/app/views/headmin/forms/_checkbox.html.erb +1 -1
  39. data/app/views/headmin/forms/_file.html.erb +1 -1
  40. data/app/views/headmin/forms/_repeater.html.erb +1 -1
  41. data/app/views/headmin/forms/actions/_destroy.html.erb +3 -3
  42. data/app/views/headmin/forms/fields/_group.html.erb +1 -1
  43. data/app/views/headmin/nav/item/_devise.html.erb +1 -1
  44. data/app/views/headmin/table/_actions.html.erb +1 -1
  45. data/app/views/headmin/views/devise/registrations/_edit.html.erb +2 -2
  46. data/config/initializers/customize_input_error.rb +4 -4
  47. data/lib/generators/headmin/blocks_generator.rb +8 -8
  48. data/lib/generators/headmin/devise_generator.rb +4 -4
  49. data/lib/generators/headmin/fields_generator.rb +9 -9
  50. data/lib/generators/templates/controllers/auth/confirmations_controller.rb +1 -1
  51. data/lib/generators/templates/controllers/auth/omniauth_callbacks_controller.rb +1 -1
  52. data/lib/generators/templates/controllers/auth/passwords_controller.rb +1 -1
  53. data/lib/generators/templates/controllers/auth/registrations_controller.rb +1 -1
  54. data/lib/generators/templates/controllers/auth/sessions_controller.rb +1 -1
  55. data/lib/generators/templates/controllers/auth/unlocks_controller.rb +1 -1
  56. data/lib/generators/templates/models/block.rb +1 -1
  57. data/lib/headmin/engine.rb +6 -6
  58. data/lib/headmin/version.rb +1 -1
  59. data/package.json +0 -1
  60. data/yarn.lock +1 -258
  61. metadata +9 -4
  62. data/.rubocop.yml +0 -13
@@ -1,45 +1,47 @@
1
- <%
2
- # name: headmin/thumbnail
3
- #
4
- # ==== Required parameters
5
- # * +src+ - Sourch path for the file
6
- #
7
- # ==== Optional parameters
8
- # * +width+ - Width of the thumbnail
9
- # * +height+ - Height of the thumbnail
10
- #
11
- # ==== References
12
- # https://getbootstrap.com/docs/5.1/content/images/#image-thumbnails
13
- #
14
- # ==== Examples
15
- # Basic version
16
- # <%= render 'headmin/thumbnail', src: file %#>
17
- #
18
- # Custom width and height
19
- # <%= render 'headmin/thumbnail', src: file, width: 300, height: 100 %#>
20
-
21
- width = local_assigns[:width] || 150
22
- height = local_assigns[:height] || 150
23
- class_names = ['img-thumbnail h-thumbnail', local_assigns[:class]].join(' ')
24
-
25
- mime_type = nil
26
- if src
27
- stripped_path = URI.parse(src).path
28
- extension = File.extname(stripped_path)
29
- mime_type = Rack::Mime.mime_type(extension)
30
- end
31
- %>
32
-
33
- <div class="<%= class_names %>" style="width: <%= width %>px; height: <%= height %>px;">
34
- <% if mime_type&.match?(/^image/) %>
35
- <div class="h-thumbnail-bg" style="background-image: url('<%= src %>');"></div>
1
+ <!--
2
+ <% documentation do %>
3
+ # Thumbnail
4
+ Render thumbnails for files. Whenever possible (e.g. images) previews are generated. Icons are used instead for other file types.
5
+
6
+ ```erbx
7
+ <%= render 'headmin/thumbnail', src: image_path("image.jpg") %>
8
+ ```
9
+
10
+ ## Parameters
11
+ | Name | Required | Type | Description |
12
+ | ------------ | -------- | ---------------- | ----------- |
13
+ | src | yes | String | Source of the file. Can be a local or external URL |
14
+ | width | no | Integer | Width of the thumbnail in px |
15
+ | height | no | Integer | Height of the thumbnail in px |
16
+
17
+ ## Examples
18
+
19
+ ### Sizing
20
+ ```erbx
21
+ <%= render 'headmin/thumbnail', src: image_path("image.jpg"), width: 300, height: 100 %>
22
+ ```
23
+
24
+ ### Types
25
+ ```erbx
26
+ <%= render 'headmin/thumbnail', src: asset_path("document.pdf"), width: 100, height: 100 %>
27
+ <%= render 'headmin/thumbnail', src: asset_path("document.docx"), width: 100, height: 100 %>
28
+ <%= render 'headmin/thumbnail', src: asset_path("spreadsheet.xls"), width: 100, height: 100 %>
29
+ <%= render 'headmin/thumbnail', src: asset_path("video.mp4"), width: 100, height: 100 %>
30
+ ```
31
+
32
+ ## References
33
+ - [Bootstrap](https://getbootstrap.com/docs/5.1/content/images/#image-thumbnails)
34
+ <% end %>
35
+ -->
36
+
37
+ <% thumbnail = Headmin::Thumbnail.new(local_assigns) %>
38
+
39
+ <div class="<%= thumbnail.class_names %>" style="width: <%= thumbnail.width %>px; height: <%= thumbnail.height %>px;">
40
+ <% if thumbnail.image? %>
41
+ <div class="h-thumbnail-bg" style="background-image: url('<%= thumbnail.src %>');"></div>
36
42
  <% else %>
37
43
  <div class="h-thumbnail-bg">
38
- <% if mime_type %>
39
- <%= bootstrap_icon_for_mime_type(mime_type, class: 'h-thumbnail-icon') %>
40
- <% else %>
41
- <%= bootstrap_icon('question', class: 'h-thumbnail-icon') %>
42
- <% end %>
44
+ <%= bootstrap_icon(thumbnail.icon_name, class: 'h-thumbnail-icon') %>
43
45
  </div>
44
46
  <% end %>
45
47
  </div>
@@ -12,7 +12,7 @@
12
12
  <% name = local_assigns.has_key?(:name) ? name : '' %>
13
13
 
14
14
  <li>
15
- <a class="dropdown-item" href="<%= url %>" <%= "data-method=#{method}" if method %>>
15
+ <a class="dropdown-item" href="<%= url %>" <%= "data-turbo-method=#{method}" if method %>>
16
16
  <%= name %>
17
17
  </a>
18
18
  </li>
@@ -33,7 +33,7 @@
33
33
  <div class="<%= ('mb-3 text-start' if show_label) %>">
34
34
  <%= form.check_box(attribute, options) %>
35
35
  <% if show_label %>
36
- <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
36
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, text: label, required: required %>
37
37
  <% end %>
38
38
  <%= render 'headmin/forms/validation', form: form, attribute: attribute %>
39
39
  </div>
@@ -146,7 +146,7 @@
146
146
  next unless attachment
147
147
  filename = attachment.blob.filename.to_s
148
148
  size = number_to_human_size(attachment.blob.byte_size)
149
- src = attachment.image? ? url_for(attachment.variant(resize_to_fill: [thumbnail_width, thumbnail_height], quality: 70)) : url_for(attachment)
149
+ src = attachment.image? ? url_for(attachment.variant(resize_to_fill: [thumbnail_width, thumbnail_height])) : url_for(attachment)
150
150
  %>
151
151
  <div class="h-form-file-thumbnail" title="<%= "#{filename} (#{size})" %>" data-file-preview-target="thumbnail">
152
152
  <%= ff.hidden_field(:id, disabled: destroy) %>
@@ -54,7 +54,7 @@
54
54
 
55
55
  <!-- Label -->
56
56
  <% if show_label %>
57
- <%= render 'headmin/forms/label', form: form, attribute: attribute, name: label, required: required %>
57
+ <%= render 'headmin/forms/label', form: form, attribute: attribute, text: label, required: required %>
58
58
  <% end %>
59
59
 
60
60
  <ul class="list-group <%= 'list-group-flush' if flush %>" data-repeater-target="list">
@@ -6,8 +6,8 @@
6
6
  %>
7
7
 
8
8
  <div class="d-grid">
9
- <%= link_to([:admin, form.object], class: 'btn btn-outline-danger', method: :delete, data: {confirm: t('.confirm')}) do %>
10
- <%= bootstrap_icon('trash') %>
11
- <%= t('.title') %>
9
+ <%= link_to([:admin, form.object], class: "btn btn-outline-danger", "data-turbo-method": "delete", "data-turbo-confirm": t(".confirm")) do %>
10
+ <%= bootstrap_icon("trash") %>
11
+ <%= t(".title") %>
12
12
  <% end %>
13
13
  </div>
@@ -29,7 +29,7 @@
29
29
 
30
30
  <%= render 'headmin/forms/fields/base', form: form, name: name, field_type: :group do |group, field_label| %>
31
31
  <% if show_label %>
32
- <%= render 'headmin/forms/label', form: form, attribute: :value, name: label || field_label %>
32
+ <%= render 'headmin/forms/label', form: form, attribute: :value, text: label || field_label %>
33
33
  <% end %>
34
34
 
35
35
  <li class="list-group-item mb-3">
@@ -16,6 +16,6 @@
16
16
  <%= render 'headmin/dropdown/list', id: 'nav-item-devise' do %>
17
17
  <%= render 'headmin/dropdown/item', name: t('.edit_profile'), url: polymorphic_path([:edit, singular, :registration]) %>
18
18
  <%= render 'headmin/dropdown/divider' %>
19
- <%= render 'headmin/dropdown/item', name: t('.log_out'), url: polymorphic_path([:destroy, singular, :session]), method: :delete %>
19
+ <%= render 'headmin/dropdown/item', name: t('.log_out'), url: polymorphic_path([:destroy, singular, :session]), data: { "turbo-method": "delete" } %>
20
20
  <% end %>
21
21
  <% end %>
@@ -13,7 +13,7 @@
13
13
 
14
14
  <% content_for :table_actions do %>
15
15
  <th class="h-table-actions d-none" data-controller="table-actions" data-table-actions-target="wrapper" data-table-target="actions">
16
- <%= form_with url: '', data: { 'table-actions-target': 'form' } do |form| %>
16
+ <%= form_with url: '', data: { "table-actions-target": 'form', "turbo": false } do |form| %>
17
17
  <%= form.hidden_field :authenticity_token, value: form_authenticity_token %>
18
18
  <%= form.hidden_field :_method, value: 'POST', 'data-table-actions-target': 'method' %>
19
19
  <%= query_parameter_fields(form) %>
@@ -1,5 +1,5 @@
1
1
  <div>
2
- <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put}) do |f| %>
2
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
3
3
  <%= render "headmin/views/devise/shared/error_messages", resource: resource %>
4
4
 
5
5
  <%= render 'headmin/forms/email', form: f, attribute: :email, required: true, float: true %>
@@ -19,6 +19,6 @@
19
19
  <h4><%= t('.cancel') %></h4>
20
20
 
21
21
  <p><%= t('.unhappy') %></p>
22
- <%= button_to t('.cancel'), registration_path(resource_name), class: 'btn btn-lg btn-danger w-100', data: {confirm: "Are you sure?"}, method: :delete %>
22
+ <%= button_to t('.cancel'), registration_path(resource_name), class: 'btn btn-lg btn-danger w-100', "data-turbo-confirm": "Are you sure?", "data-turbo-method": "delete" %>
23
23
  </div>
24
24
  </div>
@@ -1,9 +1,9 @@
1
- ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
1
+ ActionView::Base.field_error_proc = proc do |html_tag, instance|
2
2
  class_attr_index = html_tag.index 'class="'
3
3
 
4
4
  if class_attr_index
5
- html_tag.insert class_attr_index+7, 'error '
5
+ html_tag.insert class_attr_index + 7, "error "
6
6
  else
7
- html_tag.insert html_tag.index('>'), ' class="error"'
7
+ html_tag.insert html_tag.index(">"), ' class="error"'
8
8
  end
9
- end
9
+ end
@@ -2,21 +2,21 @@ module Headmin
2
2
  class BlocksGenerator < Rails::Generators::Base
3
3
  include Rails::Generators::Migration
4
4
 
5
- source_root File.expand_path('../../templates', __FILE__)
5
+ source_root File.expand_path("../../templates", __FILE__)
6
6
 
7
7
  def copy_models
8
- template 'models/block.rb', 'app/models/block.rb'
8
+ template "models/block.rb", "app/models/block.rb"
9
9
  end
10
10
 
11
11
  def copy_migrations
12
- migration_template 'migrations/create_blocks.rb', 'db/migrate/create_blocks.rb'
12
+ migration_template "migrations/create_blocks.rb", "db/migrate/create_blocks.rb"
13
13
  end
14
14
 
15
- private
16
-
17
- def self.next_migration_number(dirname)
18
- next_migration_number = current_migration_number(dirname) + 1
19
- ActiveRecord::Migration.next_migration_number(next_migration_number)
15
+ class << self
16
+ def next_migration_number(dirname)
17
+ next_migration_number = current_migration_number(dirname) + 1
18
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
19
+ end
20
20
  end
21
21
  end
22
22
  end
@@ -2,15 +2,15 @@ module Headmin
2
2
  class DeviseGenerator < Rails::Generators::Base
3
3
  include Rails::Generators::Migration
4
4
 
5
- source_root File.expand_path('../../templates', __FILE__)
5
+ source_root File.expand_path("../../templates", __FILE__)
6
6
 
7
7
  def copy_controllers
8
- directory 'controllers/auth', 'app/controllers/auth'
8
+ directory "controllers/auth", "app/controllers/auth"
9
9
  end
10
10
 
11
11
  def copy_views
12
- directory 'views/auth', 'app/views/auth'
13
- copy_file 'views/layouts/auth.html.erb', 'app/views/layouts/auth.html.erb'
12
+ directory "views/auth", "app/views/auth"
13
+ copy_file "views/layouts/auth.html.erb", "app/views/layouts/auth.html.erb"
14
14
  end
15
15
  end
16
16
  end
@@ -2,22 +2,22 @@ module Headmin
2
2
  class FieldsGenerator < Rails::Generators::Base
3
3
  include Rails::Generators::Migration
4
4
 
5
- source_root File.expand_path('../../templates', __FILE__)
5
+ source_root File.expand_path("../../templates", __FILE__)
6
6
 
7
7
  def copy_models
8
- template 'models/field.rb', 'app/models/field.rb'
8
+ template "models/field.rb", "app/models/field.rb"
9
9
  end
10
10
 
11
11
  def copy_migrations
12
- migration_template 'migrations/create_fields.rb', 'db/migrate/create_fields.rb'
13
- migration_template 'migrations/create_field_hierarchies.rb', 'db/migrate/create_field_hierarchies.rb'
12
+ migration_template "migrations/create_fields.rb", "db/migrate/create_fields.rb"
13
+ migration_template "migrations/create_field_hierarchies.rb", "db/migrate/create_field_hierarchies.rb"
14
14
  end
15
15
 
16
- private
17
-
18
- def self.next_migration_number(dirname)
19
- next_migration_number = current_migration_number(dirname) + 1
20
- ActiveRecord::Migration.next_migration_number(next_migration_number)
16
+ class << self
17
+ def next_migration_number(dirname)
18
+ next_migration_number = current_migration_number(dirname) + 1
19
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
20
+ end
21
21
  end
22
22
  end
23
23
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::ConfirmationsController < Devise::ConfirmationsController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # GET /resource/confirmation/new
6
6
  # def new
7
7
  # super
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::OmniauthCallbacksController < Devise::OmniauthCallbacksController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # You should configure your model like this:
6
6
  # devise :omniauthable, omniauth_providers: [:twitter]
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::PasswordsController < Devise::PasswordsController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # GET /resource/password/new
6
6
  # def new
7
7
  # super
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::RegistrationsController < Devise::RegistrationsController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # before_action :configure_sign_up_params, only: [:create]
6
6
  # before_action :configure_account_update_params, only: [:update]
7
7
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::SessionsController < Devise::SessionsController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # before_action :configure_sign_in_params, only: [:create]
6
6
 
7
7
  # GET /resource/sign_in
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Auth::UnlocksController < Devise::UnlocksController
4
- layout 'auth'
4
+ layout "auth"
5
5
  # GET /resource/unlock/new
6
6
  # def new
7
7
  # super
@@ -1,3 +1,3 @@
1
1
  class Block < ApplicationRecord
2
2
  include Headmin::Block
3
- end
3
+ end
@@ -1,10 +1,10 @@
1
1
  module Headmin
2
2
  class Engine < Rails::Engine
3
- engine_name 'headmin'
3
+ engine_name "headmin"
4
4
 
5
- require 'closure_tree'
6
- require 'redcarpet'
7
- require 'rouge'
5
+ require "closure_tree"
6
+ require "redcarpet"
7
+ require "rouge"
8
8
 
9
9
  # Add translations to main app
10
10
  config.before_configuration do
@@ -14,7 +14,7 @@ module Headmin
14
14
  # Add assets to precompilation list
15
15
  initializer "headmin.assets" do |app|
16
16
  next unless app.config.respond_to?(:assets)
17
- app.config.assets.precompile += %w( headmin.js headmin.css headmin.scss)
17
+ app.config.assets.precompile += %w[headmin.js headmin.css headmin.scss]
18
18
  end
19
19
 
20
20
  # Add importmap to main app
@@ -24,4 +24,4 @@ module Headmin
24
24
  app.config.importmap.cache_sweepers << Engine.root.join("app/assets/javascripts")
25
25
  end
26
26
  end
27
- end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Headmin
4
- VERSION = "0.3.2"
4
+ VERSION = "0.3.3"
5
5
  end
data/package.json CHANGED
@@ -24,7 +24,6 @@
24
24
  "@hotwired/stimulus": "^3.0",
25
25
  "@hotwired/stimulus-webpack-helpers": "^1.0",
26
26
  "@popperjs/core": "^2.11.2",
27
- "@rails/ujs": "^7.0.1",
28
27
  "bootstrap": "^5.1.3",
29
28
  "flatpickr": "^4.6.9",
30
29
  "sortablejs": "^1.14.0",