hotsheet 0.1.0 → 0.2.0

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +32 -35
  4. data/app/assets/hotsheet.css +1 -0
  5. data/app/assets/hotsheet.js +33 -0
  6. data/app/controllers/hotsheet/application_controller.rb +2 -4
  7. data/app/controllers/hotsheet/sheets_controller.rb +47 -0
  8. data/app/helpers/hotsheet/application_helper.rb +3 -3
  9. data/app/views/hotsheet/shared/_nav.html.erb +14 -0
  10. data/app/views/hotsheet/sheets/error.html.erb +1 -0
  11. data/app/views/hotsheet/sheets/index.html.erb +20 -0
  12. data/app/views/hotsheet/sheets/root.html.erb +1 -0
  13. data/app/views/layouts/hotsheet/application.html.erb +7 -7
  14. data/config/routes.rb +6 -5
  15. data/lib/generators/templates/hotsheet.rb +7 -4
  16. data/lib/hotsheet/column.rb +31 -0
  17. data/lib/hotsheet/config.rb +29 -0
  18. data/lib/hotsheet/engine.rb +5 -4
  19. data/lib/hotsheet/sheet.rb +44 -0
  20. data/lib/hotsheet/version.rb +1 -1
  21. data/lib/hotsheet.rb +38 -11
  22. metadata +17 -89
  23. data/CHANGELOG.md +0 -17
  24. data/app/assets/config/hotsheet.js +0 -2
  25. data/app/assets/javascripts/hotsheet/application.js +0 -1
  26. data/app/assets/javascripts/hotsheet/channels/consumer.js +0 -3
  27. data/app/assets/javascripts/hotsheet/channels/inline_edit_channel.js +0 -3
  28. data/app/assets/javascripts/hotsheet/controllers/application.js +0 -6
  29. data/app/assets/javascripts/hotsheet/controllers/editable_attribute_controller.js +0 -51
  30. data/app/assets/stylesheets/hotsheet/application.css +0 -86
  31. data/app/channels/application_cable/channel.rb +0 -6
  32. data/app/channels/application_cable/connection.rb +0 -6
  33. data/app/channels/inline_edit_channel.rb +0 -9
  34. data/app/controllers/hotsheet/pages_controller.rb +0 -43
  35. data/app/views/hotsheet/pages/_editable_attribute.html.erb +0 -24
  36. data/app/views/hotsheet/pages/index.html.erb +0 -27
  37. data/app/views/layouts/hotsheet/_flash.html.erb +0 -7
  38. data/app/views/layouts/hotsheet/_sidebar.html.erb +0 -11
  39. data/config/initializers/hotsheet/content_security_policy.rb +0 -14
  40. data/config/initializers/hotsheet/editable_attributes.rb +0 -43
  41. data/config/initializers/hotsheet/pagy.rb +0 -7
  42. data/config/locales/en.yml +0 -5
  43. data/lib/hotsheet/configuration.rb +0 -19
  44. data/vendor/assets/stylesheets/hotsheet/pagy.css +0 -37
@@ -1,24 +0,0 @@
1
- <%# locals: (attribute:, model:, record:) %>
2
-
3
- <%= turbo_frame_tag "#{dom_id record}-#{attribute}" do %>
4
- <div data-controller="editable-attribute"
5
- data-editable-attribute-broadcast-url-value="<%= broadcast_edit_intent_path %>"
6
- data-editable-attribute-resource-name-value="<%= model.table_name %>"
7
- data-editable-attribute-resource-id-value="<%= record.id %>">
8
- <div class="readonly-attribute"
9
- data-editable-attribute-target="readonlyAttribute"
10
- data-action="click->editable-attribute#displayInputField"
11
- role="button">
12
- <%= record.public_send attribute %>
13
- </div>
14
-
15
- <div data-editable-attribute-target="attributeForm" style="display:none">
16
- <%= form_for record, url: "#{root_path}#{model.table_name}/#{record.id}" do |f| %>
17
- <%= f.text_field attribute, class: "editable-input", data: {
18
- editable_attribute_target: "attributeFormInput",
19
- action: "keydown.enter->editable-attribute#submitForm blur->editable-attribute#submitForm"
20
- } %>
21
- <% end %>
22
- </div>
23
- </div>
24
- <% end %>
@@ -1,27 +0,0 @@
1
- <% if @model.nil? %>
2
- <h1>Hotsheet</h1>
3
- <p>Welcome to the hottest sheet around. Select a model from the sidebar to view the spreadsheet.</p>
4
- <% else %>
5
- <h1><%= @model.model_name.human %></h1>
6
- <table>
7
- <thead>
8
- <tr>
9
- <% @model.editable_attributes.each do |attribute| %>
10
- <th><%= attribute %></th>
11
- <% end %>
12
- </tr>
13
- </thead>
14
- <tbody>
15
- <% @records.each do |record| %>
16
- <tr>
17
- <% @model.editable_attributes.each do |attribute| %>
18
- <td>
19
- <%= render "editable_attribute", model: @model, record: record, attribute: attribute %>
20
- </td>
21
- <% end %>
22
- </tr>
23
- <% end %>
24
- </tbody>
25
- </table>
26
- <%== pagy_nav @pagy %>
27
- <% end %>
@@ -1,7 +0,0 @@
1
- <%# locals: () %>
2
-
3
- <% flash.each do |type, msg| %>
4
- <div class='flash <%= type %>'>
5
- <span><%= msg %></span>
6
- </div>
7
- <% end %>
@@ -1,11 +0,0 @@
1
- <%# locals: () %>
2
-
3
- <aside>
4
- <nav>
5
- <ul>
6
- <% Hotsheet.models.each do |model| %>
7
- <%= link_to model.model_name.human, "#{root_path}#{model.table_name}" %>
8
- <% end %>
9
- </ul>
10
- </nav>
11
- </aside>
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Rails.application.configure do
4
- config.content_security_policy do |csp|
5
- csp.default_src :none
6
- csp.connect_src :self
7
- csp.img_src :self
8
- csp.script_src :strict_dynamic
9
- csp.style_src :self, :unsafe_inline
10
- end
11
-
12
- config.content_security_policy_nonce_directives = %w[script-src]
13
- config.content_security_policy_nonce_generator = ->(_) { SecureRandom.base64 18 }
14
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- Rails.application.config.after_initialize do # rubocop:disable Metrics/BlockLength
4
- # Only run this initializer when running the Rails server
5
- next unless Rails.env.test? || defined? Rails::Server
6
-
7
- Hotsheet.configuration.models.each_key do |model| # rubocop:disable Metrics/BlockLength
8
- model.constantize.class_eval do
9
- class << self
10
- def editable_attributes
11
- @editable_attributes ||= fetch_editable_attributes
12
- end
13
-
14
- private
15
-
16
- def fetch_editable_attributes
17
- config = Hotsheet.configuration.models[name]
18
- excluded_attributes = config.excluded_attributes
19
-
20
- if config.included_attributes.present?
21
- raise "Can only specify either included or excluded attributes" if excluded_attributes.present?
22
-
23
- attrs_to_s(config.included_attributes)
24
- elsif excluded_attributes.present?
25
- column_names - attrs_to_s(excluded_attributes)
26
- else
27
- column_names
28
- end
29
- end
30
-
31
- def attrs_to_s(attrs)
32
- attrs.map do |attr|
33
- raise "Attribute '#{attr}' doesn't exist on model '#{name}'" if column_names.exclude? attr.to_s
34
-
35
- attr.to_s
36
- end
37
- end
38
- end
39
- end
40
-
41
- model.constantize.editable_attributes
42
- end
43
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pagy"
4
-
5
- # Pagy Variables (https://ddnexus.github.io/pagy/docs/api/pagy#variables)
6
- Pagy::DEFAULT[:limit] = 100
7
- Pagy::DEFAULT.freeze
@@ -1,5 +0,0 @@
1
- en:
2
- home: Home
3
- hotsheet:
4
- success: '%{record} updated successfully'
5
- error: '%{record} update failed: %{errors}'
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hotsheet
4
- class Configuration
5
- include ActiveSupport::Configurable
6
-
7
- config_accessor(:models) { {} }
8
-
9
- def model(name, &block)
10
- model_config = ModelConfig.new
11
- yield model_config if block
12
- models[name.to_s] = model_config
13
- end
14
-
15
- class ModelConfig
16
- attr_accessor :included_attributes, :excluded_attributes
17
- end
18
- end
19
- end
@@ -1,37 +0,0 @@
1
- /* https://ddnexus.github.io/pagy/docs/api/stylesheets */
2
-
3
- .pagy {
4
- color: #6b7280;
5
- display: flex;
6
- font-size: .875rem;
7
- font-weight: 600;
8
- margin-top: 1rem;
9
-
10
- a ~ a {
11
- margin-left: .25rem;
12
- }
13
-
14
- a:not(.gap) {
15
- background-color: #e5e7eb;
16
- border-radius: .5rem;
17
- color: inherit;
18
- display: block;
19
- padding: .25rem .75rem;
20
- text-decoration: none;
21
-
22
- &:hover {
23
- background-color: #d1d5db;
24
- }
25
-
26
- &:not([href]) {
27
- background-color: #f3f4f6;
28
- color: #d1d5db;
29
- cursor: default;
30
- }
31
-
32
- &.current {
33
- background-color: #9ca3af;
34
- color: white;
35
- }
36
- }
37
- }