hotsheet 0.2.0 → 0.2.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a5cc231b679617e535c8fb71bc077fbf8c735935967149af191484baa07d5cb
4
- data.tar.gz: 4a9f48ce2ed52a96b313bb691b0908f141b18aea5807c41385753bca97671cf5
3
+ metadata.gz: 9b1074112914dc017affebb383fba9eaa3bbab56e59b40355510d94ddf0f21f9
4
+ data.tar.gz: 54d77d78f488cd563ee2377c3c5585580fa6d692d4c90de9126de82233ddfc3e
5
5
  SHA512:
6
- metadata.gz: df1ce187b96c8dde0699ac26cbef9d4c28c08d1835d591537e0329beb308e6fafd4b9b1fbc08d851d30aa4a137cb006109b95fd77202f1663d963a928427e901
7
- data.tar.gz: 5eacbcbadf7cac7f8ff7cde1a058ff8233ecd9e2f962de90a792b5eaa51c48dc2d2d7ee6c2db1b03a7c9579bb137d363a3ebe0b8873357d45eef4301e742880c
6
+ metadata.gz: 400ea189cbefc49907da08f1d22c3f3f40f9f28a7e7c0ad92a8469b4b18014f2f3767a2a57c03dbc81ff369366c107ab2252dad2c3c3e43a1deec3ac95b5bf4b
7
+ data.tar.gz: 64b2a5ca09604b2adacaa2da16e43bf95429d233c728e3f8175009b71fef00f0ac217a193711d1be4823bdc8870c56929d52316facc38b3130e68129fc2653a7
data/README.md CHANGED
@@ -16,25 +16,45 @@
16
16
 
17
17
  ## Usage
18
18
 
19
- After installing, you can directly go to `/hotsheet` within your app by default.
19
+ After the installation, you can start the Rails server and visit
20
+ [/hotsheet](http://localhost:3000/hotsheet) to view the spreadsheet.
20
21
 
21
22
  ### Configuration
22
23
 
23
24
  You can configure which models ('sheets') this gem should manage, and specify which
24
25
  database columns should be editable or viewable in the spreadsheet. This can be
25
- done by configuring the initializer file created by the install command:
26
+ done by editing the [config/initializers/hotsheet.rb](https://github.com/renuo/hotsheet/blob/main/lib/generators/templates/hotsheet.rb)
27
+ file created by the install command:
26
28
 
27
29
  ```rb
28
- # config/initializers/hotsheet.rb
29
-
30
30
  Hotsheet.configure do
31
+ # Configure the visible and editable columns for each model.
32
+ # The ID is included as the first column by default.
31
33
  sheet :User do
32
34
  column :name
33
- column :birthdate, editable: false
35
+ column :email, editable: false
36
+ column :birthdate, editable: -> { rand > 0.5 }
34
37
  end
38
+
39
+ # Leave the block out to include all database columns.
40
+ sheet :Post
35
41
  end
36
42
  ```
37
43
 
44
+ ### Basic Authentication
45
+
46
+ If you don't want everyone to have access to Hotsheet, you can set a
47
+ basic auth environment variable:
48
+
49
+ ```sh
50
+ HOTSHEET_BASIC_AUTH="admin:password"
51
+ ```
52
+
53
+ ### Internationalization
54
+
55
+ You can create custom translations by overwriting the default locales defined in
56
+ [config/locales/en.yml](https://github.com/renuo/hotsheet/blob/main/config/locales/en.yml).
57
+
38
58
  ## Contributing
39
59
 
40
60
  See [Contributing Guide](https://github.com/renuo/hotsheet/blob/main/CONTRIBUTING.md) and please
@@ -48,7 +68,7 @@ This is a newly created gem, and we will firstly focus on:
48
68
  1. Configuration and access permissions
49
69
  1. Concurrent users (broadcasting, conflict resolution)
50
70
 
51
- Feel free to look at our [planned enhancements](https://github.com/renuo/hotsheet/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement)
71
+ Feel free to look at our [planned enhancements](https://github.com/renuo/hotsheet/issues?q=is:open+is:issue+label:feature)
52
72
  or add your own.
53
73
 
54
74
  ## License
@@ -2,4 +2,10 @@
2
2
 
3
3
  class Hotsheet::ApplicationController < ActionController::Base
4
4
  protect_from_forgery with: :exception
5
+
6
+ # :nocov:
7
+ ENV["HOTSHEET_BASIC_AUTH"]&.split(":")&.then do |name, password|
8
+ http_basic_authenticate_with name:, password:
9
+ end
10
+ # :nocov:
5
11
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Hotsheet::HomeController < Hotsheet::ApplicationController
4
+ def show; end
5
+
6
+ def error
7
+ render "error", status: :not_found
8
+ end
9
+ end
@@ -18,27 +18,25 @@ class Hotsheet::SheetsController < Hotsheet::ApplicationController
18
18
  end
19
19
  end
20
20
 
21
- def error
22
- render "error", status: :not_found
23
- end
24
-
25
21
  private
26
22
 
27
23
  def set_sheet
28
24
  @sheet = Hotsheet.sheets[params[:sheet_name]]
25
+
26
+ render "hotsheet/home/error", status: :not_found if @sheet.nil?
29
27
  end
30
28
 
31
29
  def set_column
32
30
  @column = @sheet.columns[params[:column_name]]
33
- return respond Hotsheet.t "errors.not_found" if @column.nil?
31
+ return respond Hotsheet.t "error_not_found" if @column.nil?
34
32
 
35
- respond Hotsheet.t "errors.forbidden" unless @column.editable?
33
+ respond Hotsheet.t "error_forbidden" unless @column.editable?
36
34
  end
37
35
 
38
36
  def set_resource
39
37
  @resource = @sheet.model.find_by id: params[:id]
40
38
 
41
- respond Hotsheet.t "errors.not_found" if @resource.nil?
39
+ respond Hotsheet.t "error_not_found" if @resource.nil?
42
40
  end
43
41
 
44
42
  def respond(message = "")
@@ -0,0 +1 @@
1
+ <h1><%= Hotsheet.t "error_not_found" %></h1>
@@ -6,7 +6,7 @@
6
6
  <% Hotsheet.sheets.each_with_index do |entry, index| %>
7
7
  <li>
8
8
  <% sheet_name, sheet = entry %>
9
- <%= link_to sheet.model.model_name.human(count: 2), sheet_path_for(sheet_name),
9
+ <%= link_to sheet.model.model_name.human(count: 2), sheets_path(sheet_name),
10
10
  class: ("active" if params[:sheet_name] == sheet_name), data: { x: index } %>
11
11
  </li>
12
12
  <% end %>
@@ -0,0 +1,5 @@
1
+ en:
2
+ hotsheet:
3
+ error_forbidden: Forbidden
4
+ error_not_found: Not found
5
+ title: Hotsheet
data/config/routes.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Hotsheet::Engine.routes.draw do
4
- next unless defined? Rails::Server
4
+ root "home#show"
5
5
 
6
- Hotsheet.sheets.each_key do |sheet_name|
7
- resources sheet_name, sheet_name:, controller: :sheets, only: %i[index update]
6
+ scope ":sheet_name" do
7
+ resources controller: :sheets, only: %i[index update], as: :sheets
8
8
  end
9
9
 
10
- root "sheets#root"
11
- match "*path", to: "sheets#error", via: :all
10
+ match "*path", to: "home#error", via: :all
12
11
  end
@@ -1,12 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Configure the models to be used by Hotsheet.
4
- # See https://github.com/renuo/hotsheet?tab=readme-ov-file#usage.
5
- # The ID is included by default. It is always the first column.
4
+ # See https://github.com/renuo/hotsheet/blob/main/README.md#usage.
6
5
 
7
6
  Hotsheet.configure do
7
+ # Configure the visible and editable columns for each model.
8
+ # The ID is included as the first column by default.
9
+
8
10
  # sheet :User do
9
11
  # column :name
10
- # column :birthdate, editable: false
12
+ # column :email, editable: false
13
+ # column :birthdate, editable: -> { rand > 0.5 }
11
14
  # end
15
+
16
+ # Leave the block out to include all database columns.
17
+
18
+ # sheet :Post
12
19
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hotsheet
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
data/lib/hotsheet.rb CHANGED
@@ -12,10 +12,10 @@ module Hotsheet
12
12
  class << self
13
13
  include Config
14
14
 
15
- CONFIG = {}.freeze
16
-
17
15
  attr_reader :config
18
16
 
17
+ CONFIG = {}.freeze
18
+
19
19
  def configure(config = {}, &sheets)
20
20
  @config = [merge_config!(CONFIG, config), sheets]
21
21
  self
@@ -29,10 +29,10 @@ module Hotsheet
29
29
  end
30
30
  end
31
31
 
32
+ I18N = Psych.load_file(Hotsheet::Engine.root.join("config/locales/en.yml"))["en"]["hotsheet"].freeze
33
+
32
34
  def t(key)
33
- I18n.t key, scope: "hotsheet"
34
- rescue I18n::MissingTranslationData
35
- I18n.with_locale(:en) { I18n.t key, scope: "hotsheet" }
35
+ I18n.t "hotsheet.#{key}", default: I18N[key]
36
36
  end
37
37
 
38
38
  private
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renuo AG
@@ -38,13 +38,14 @@ files:
38
38
  - app/assets/hotsheet.css
39
39
  - app/assets/hotsheet.js
40
40
  - app/controllers/hotsheet/application_controller.rb
41
+ - app/controllers/hotsheet/home_controller.rb
41
42
  - app/controllers/hotsheet/sheets_controller.rb
42
- - app/helpers/hotsheet/application_helper.rb
43
+ - app/views/hotsheet/home/error.html.erb
44
+ - app/views/hotsheet/home/show.html.erb
43
45
  - app/views/hotsheet/shared/_nav.html.erb
44
- - app/views/hotsheet/sheets/error.html.erb
45
46
  - app/views/hotsheet/sheets/index.html.erb
46
- - app/views/hotsheet/sheets/root.html.erb
47
47
  - app/views/layouts/hotsheet/application.html.erb
48
+ - config/locales/en.yml
48
49
  - config/routes.rb
49
50
  - lib/generators/hotsheet/install_generator.rb
50
51
  - lib/generators/templates/hotsheet.rb
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hotsheet::ApplicationHelper
4
- def sheet_path_for(sheet_name, **args)
5
- hotsheet.public_send :"#{sheet_name}_path", **args
6
- end
7
- end
@@ -1 +0,0 @@
1
- <h1><%= Hotsheet.t "errors.not_found" %></h1>