infotable 1.0.0 → 1.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -2
  3. data/app/assets/javascripts/infotable/controllers/drawer_controller.js +68 -42
  4. data/app/assets/javascripts/infotable/controllers/table_controller.js +127 -23
  5. data/app/assets/tailwind/infotable/engine.css +5 -0
  6. data/app/controllers/infotable/tables_controller.rb +17 -7
  7. data/app/helpers/infotable/tables_helper.rb +64 -2
  8. data/app/views/infotable/tables/_active_filters.html.erb +24 -0
  9. data/app/views/infotable/tables/_column_visibility.html.erb +11 -11
  10. data/app/views/infotable/tables/_filter_drawer.html.erb +4 -4
  11. data/app/views/infotable/tables/_next_page_frame.html.erb +5 -5
  12. data/app/views/infotable/tables/_pagination.html.erb +12 -12
  13. data/app/views/infotable/tables/_rail.html.erb +56 -0
  14. data/app/views/infotable/tables/_side_panel.html.erb +22 -10
  15. data/app/views/infotable/tables/_table.html.erb +43 -26
  16. data/app/views/infotable/tables/_table_rows.html.erb +3 -3
  17. data/app/views/infotable/tables/filters/_boolean.html.erb +2 -2
  18. data/app/views/infotable/tables/filters/_date.html.erb +2 -30
  19. data/app/views/infotable/tables/filters/_number.html.erb +2 -32
  20. data/app/views/infotable/tables/filters/_range.html.erb +66 -0
  21. data/app/views/infotable/tables/filters/_select.html.erb +4 -4
  22. data/app/views/infotable/tables/filters/_text.html.erb +3 -3
  23. data/app/views/infotable/tables/show.html.erb +22 -13
  24. data/config/locales/en.yml +23 -0
  25. data/config/locales/pl.yml +23 -0
  26. data/config/routes.rb +1 -0
  27. data/lib/generators/infotable/install/install_generator.rb +10 -64
  28. data/lib/infotable/base.rb +66 -0
  29. data/lib/infotable/configuration.rb +3 -1
  30. data/lib/infotable/engine.rb +0 -8
  31. data/lib/infotable/formatters/action_formatter.rb +7 -7
  32. data/lib/infotable/formatters/avatar_formatter.rb +2 -2
  33. data/lib/infotable/formatters/badge_formatter.rb +9 -9
  34. data/lib/infotable/formatters/boolean_formatter.rb +2 -2
  35. data/lib/infotable/formatters/link_formatter.rb +1 -1
  36. data/lib/infotable/formatters/percent_formatter.rb +1 -1
  37. data/lib/infotable/version.rb +1 -1
  38. data/lib/infotable.rb +0 -12
  39. metadata +5 -3
  40. data/lib/generators/infotable/install/templates/TAILWIND_CONFIG.md +0 -131
  41. data/lib/tasks/infotable.rake +0 -55
@@ -72,7 +72,7 @@ module Infotable
72
72
  action[:label] || action[:icon] || view_context.t("infotable.formatters.action"),
73
73
  resolve_url(action[:url], record),
74
74
  role: "menuitem",
75
- class: "block px-3 py-1.5 text-sm whitespace-nowrap #{link_classes(action[:color])} hover:bg-gray-50",
75
+ class: "block px-3 py-1.5 text-sm whitespace-nowrap #{link_classes(action[:color])} hover:bg-gray-50 dark:hover:bg-gray-800",
76
76
  data: link_data(action[:data] || {}, action[:method] || :get, action[:confirm])
77
77
  )
78
78
  end
@@ -81,10 +81,10 @@ module Infotable
81
81
  # <details> gives open/close and keyboard support without JS
82
82
  content_tag(:details, class: "relative inline-block text-left") do
83
83
  summary = content_tag(:summary, "\u22EF".html_safe,
84
- class: "list-none cursor-pointer inline-flex items-center px-2 py-1 rounded-md border border-gray-300 bg-white text-gray-600 hover:bg-gray-50",
84
+ class: "list-none cursor-pointer inline-flex items-center px-2 py-1 rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-gray-800",
85
85
  "aria-label": view_context.t("infotable.formatters.action"), "aria-haspopup": "menu")
86
86
  menu = content_tag(:div, role: "menu",
87
- class: "absolute right-0 z-30 mt-1 min-w-36 rounded-md border border-gray-200 bg-white py-1 shadow-lg") do
87
+ class: "absolute right-0 z-30 mt-1 min-w-36 rounded-md border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 py-1 shadow-lg") do
88
88
  safe_join(actions.map { |action| render_menu_item(action, record) })
89
89
  end
90
90
  summary + menu
@@ -110,7 +110,7 @@ module Infotable
110
110
  when "success"
111
111
  "border-green-600 bg-green-600 text-white hover:bg-green-700"
112
112
  else
113
- "border-gray-300 bg-white text-gray-700 hover:bg-gray-50"
113
+ "border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800"
114
114
  end
115
115
 
116
116
  "#{base} #{color_classes}"
@@ -119,11 +119,11 @@ module Infotable
119
119
  def link_classes(color = nil)
120
120
  case color&.to_s
121
121
  when "danger"
122
- "text-red-600 hover:text-red-900"
122
+ "text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300"
123
123
  when "success"
124
- "text-green-600 hover:text-green-900"
124
+ "text-green-600 dark:text-green-400 hover:text-green-900 dark:hover:text-green-300"
125
125
  else
126
- "text-indigo-600 hover:text-indigo-900"
126
+ "text-indigo-600 dark:text-indigo-400 hover:text-indigo-900 dark:hover:text-indigo-200"
127
127
  end
128
128
  end
129
129
 
@@ -10,8 +10,8 @@ module Infotable
10
10
  class AvatarFormatter < BaseFormatter
11
11
  SIZES = { sm: "h-6 w-6 text-xs", md: "h-8 w-8 text-sm", lg: "h-10 w-10 text-base" }.freeze
12
12
  COLORS = [
13
- "bg-indigo-100 text-indigo-700", "bg-green-100 text-green-700", "bg-yellow-100 text-yellow-700",
14
- "bg-pink-100 text-pink-700", "bg-blue-100 text-blue-700", "bg-purple-100 text-purple-700"
13
+ "bg-indigo-100 dark:bg-indigo-900/40 text-indigo-700 dark:text-indigo-300", "bg-green-100 dark:bg-green-900/40 text-green-700 dark:text-green-300", "bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-300",
14
+ "bg-pink-100 dark:bg-pink-900/40 text-pink-700 dark:text-pink-300", "bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300", "bg-purple-100 dark:bg-purple-900/40 text-purple-700 dark:text-purple-300"
15
15
  ].freeze
16
16
 
17
17
  def format(value, record, options = {})
@@ -54,23 +54,23 @@ module Infotable
54
54
 
55
55
  color_classes = case color.to_s
56
56
  when "green"
57
- "bg-green-100 text-green-800"
57
+ "bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300"
58
58
  when "red"
59
- "bg-red-100 text-red-800"
59
+ "bg-red-100 dark:bg-red-900/40 text-red-800 dark:text-red-300"
60
60
  when "yellow"
61
- "bg-yellow-100 text-yellow-800"
61
+ "bg-yellow-100 dark:bg-yellow-900/40 text-yellow-800 dark:text-yellow-300"
62
62
  when "blue"
63
- "bg-blue-100 text-blue-800"
63
+ "bg-blue-100 dark:bg-blue-900/40 text-blue-800 dark:text-blue-300"
64
64
  when "indigo"
65
- "bg-indigo-100 text-indigo-800"
65
+ "bg-indigo-100 dark:bg-indigo-900/40 text-indigo-800 dark:text-indigo-300"
66
66
  when "purple"
67
- "bg-purple-100 text-purple-800"
67
+ "bg-purple-100 dark:bg-purple-900/40 text-purple-800 dark:text-purple-300"
68
68
  when "pink"
69
- "bg-pink-100 text-pink-800"
69
+ "bg-pink-100 dark:bg-pink-900/40 text-pink-800 dark:text-pink-300"
70
70
  when "cyan"
71
- "bg-cyan-100 text-cyan-800"
71
+ "bg-cyan-100 dark:bg-cyan-900/40 text-cyan-800 dark:text-cyan-300"
72
72
  else # gray
73
- "bg-gray-100 text-gray-800"
73
+ "bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200"
74
74
  end
75
75
 
76
76
  "#{base} #{size_classes} #{color_classes}"
@@ -20,9 +20,9 @@ module Infotable
20
20
 
21
21
  def format_as_badge(value, true_text, false_text)
22
22
  if value
23
- content_tag(:span, true_text, class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800")
23
+ content_tag(:span, true_text, class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300")
24
24
  else
25
- content_tag(:span, false_text, class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800")
25
+ content_tag(:span, false_text, class: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 dark:bg-gray-800 text-gray-800 dark:text-gray-200")
26
26
  end
27
27
  end
28
28
 
@@ -10,7 +10,7 @@ module Infotable
10
10
  # Without url: the value itself is the URL (handy for website columns); mailto:/tel: work too.
11
11
  class LinkFormatter < BaseFormatter
12
12
  ALLOWED_SCHEMES = %w[http https mailto tel].freeze
13
- DEFAULT_CLASSES = "text-indigo-600 hover:text-indigo-800 hover:underline".freeze
13
+ DEFAULT_CLASSES = "text-indigo-600 dark:text-indigo-400 hover:text-indigo-800 dark:hover:text-indigo-200 hover:underline".freeze
14
14
 
15
15
  def format(value, record, options = {})
16
16
  label = resolve(options[:label], record) || value
@@ -19,7 +19,7 @@ module Infotable
19
19
 
20
20
  width = number.clamp(0, 100).round
21
21
  bar = content_tag(:div, content_tag(:div, "", class: "h-full rounded-full bg-indigo-500", style: "width: #{width}%"),
22
- class: "h-1.5 w-16 rounded-full bg-gray-200 flex-none", role: "presentation")
22
+ class: "h-1.5 w-16 rounded-full bg-gray-200 dark:bg-gray-700 flex-none", role: "presentation")
23
23
  content_tag(:div, safe_join([ content_tag(:span, text, class: "tabular-nums"), bar ]), class: "flex items-center gap-2")
24
24
  end
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module Infotable
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/infotable.rb CHANGED
@@ -31,18 +31,6 @@ module Infotable
31
31
  Engine.root
32
32
  end
33
33
 
34
- # Returns the path to InfoTable views directory
35
- # For use in Tailwind CSS @source directives via ERB
36
- def self.views_path
37
- root.join("app/views/infotable").to_s
38
- end
39
-
40
- # Returns the path to InfoTable formatters directory
41
- # For use in Tailwind CSS @source directives via ERB
42
- def self.formatters_path
43
- root.join("lib/infotable/formatters").to_s
44
- end
45
-
46
34
  # Returns paths that should be scanned by Tailwind CSS
47
35
  # For use with Node-based Tailwind (tailwind.config.js)
48
36
  def self.tailwind_content_paths
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infotable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Cieślar
@@ -137,6 +137,7 @@ files:
137
137
  - app/assets/javascripts/infotable/controllers/drawer_controller.js
138
138
  - app/assets/javascripts/infotable/controllers/table_controller.js
139
139
  - app/assets/javascripts/infotable/index.js
140
+ - app/assets/tailwind/infotable/engine.css
140
141
  - app/controllers/infotable/application_controller.rb
141
142
  - app/controllers/infotable/tables_controller.rb
142
143
  - app/helpers/infotable/application_helper.rb
@@ -144,16 +145,19 @@ files:
144
145
  - app/jobs/infotable/application_job.rb
145
146
  - app/mailers/infotable/application_mailer.rb
146
147
  - app/models/infotable/application_record.rb
148
+ - app/views/infotable/tables/_active_filters.html.erb
147
149
  - app/views/infotable/tables/_column_visibility.html.erb
148
150
  - app/views/infotable/tables/_filter_drawer.html.erb
149
151
  - app/views/infotable/tables/_next_page_frame.html.erb
150
152
  - app/views/infotable/tables/_pagination.html.erb
153
+ - app/views/infotable/tables/_rail.html.erb
151
154
  - app/views/infotable/tables/_side_panel.html.erb
152
155
  - app/views/infotable/tables/_table.html.erb
153
156
  - app/views/infotable/tables/_table_rows.html.erb
154
157
  - app/views/infotable/tables/filters/_boolean.html.erb
155
158
  - app/views/infotable/tables/filters/_date.html.erb
156
159
  - app/views/infotable/tables/filters/_number.html.erb
160
+ - app/views/infotable/tables/filters/_range.html.erb
157
161
  - app/views/infotable/tables/filters/_select.html.erb
158
162
  - app/views/infotable/tables/filters/_text.html.erb
159
163
  - app/views/infotable/tables/show.html.erb
@@ -163,7 +167,6 @@ files:
163
167
  - config/locales/pl.yml
164
168
  - config/routes.rb
165
169
  - lib/generators/infotable/install/install_generator.rb
166
- - lib/generators/infotable/install/templates/TAILWIND_CONFIG.md
167
170
  - lib/generators/infotable/install/templates/initializer.rb
168
171
  - lib/generators/infotable/install/templates/tailwind.config.js
169
172
  - lib/generators/infotable/table/table_generator.rb
@@ -187,7 +190,6 @@ files:
187
190
  - lib/infotable/sql.rb
188
191
  - lib/infotable/table_resolver.rb
189
192
  - lib/infotable/version.rb
190
- - lib/tasks/infotable.rake
191
193
  homepage: https://infotable.infovation.eu/
192
194
  licenses:
193
195
  - MIT
@@ -1,131 +0,0 @@
1
- # Tailwind Configuration for InfoTable
2
-
3
- InfoTable supports both Tailwind CSS v4 (recommended) and v3.
4
-
5
- ## Tailwind v4 (CSS-based Config) - RECOMMENDED
6
-
7
- Tailwind v4 uses CSS-based configuration with `@source` directives. The installer creates a separate CSS file for InfoTable.
8
-
9
- ### What the Installer Does
10
-
11
- When you run `rails generate infotable:install`, it:
12
-
13
- 1. **Creates `app/assets/stylesheets/infotable.css`** with ENV variable references:
14
- ```css
15
- /* InfoTable Tailwind Sources */
16
-
17
- /* Local table definitions in your Rails app */
18
- @source "../../app/infotable";
19
-
20
- /* InfoTable gem paths (resolved dynamically via ENV variables) */
21
- @source "$INFOTABLE_VIEWS_PATH";
22
- @source "$INFOTABLE_FORMATTERS_PATH";
23
- ```
24
-
25
- 2. **Adds import to `application.tailwind.css`**:
26
- ```css
27
- @import "tailwindcss";
28
-
29
- /* InfoTable gem styles */
30
- @import './infotable';
31
- ```
32
-
33
- ### Why This Approach?
34
-
35
- - **Always correct**: Rails engine knows the exact gem location
36
- - **Environment-agnostic**: Works in dev, staging, production, Docker, CI
37
- - **Safe to commit**: No environment-specific paths
38
- - **Zero maintenance**: Install once, works everywhere
39
- - **Simple**: No glob patterns or complex path logic
40
-
41
- ### ENV Variable Strategy
42
-
43
- The InfoTable engine sets ENV variables at Rails boot time:
44
- ```ruby
45
- # lib/infotable/engine.rb
46
- initializer "infotable.tailwind" do
47
- ENV["INFOTABLE_VIEWS_PATH"] = root.join("app/views/infotable").to_s
48
- ENV["INFOTABLE_FORMATTERS_PATH"] = root.join("lib/infotable/formatters").to_s
49
- end
50
- ```
51
-
52
- Tailwind v4 expands these ENV variables when building:
53
- ```css
54
- @source "$INFOTABLE_VIEWS_PATH";
55
- ```
56
- → Expands to the actual gem path at build time
57
-
58
- ### Works Everywhere Automatically
59
-
60
- The same CSS file works in all environments:
61
- - **Development**: ENV variables point to your local gem location
62
- - **Production**: ENV variables point to production gem location
63
- - **CI/CD**: ENV variables point to CI gem location
64
- - **Docker**: ENV variables point to container gem location
65
-
66
- Rails `Infotable::Engine.root` always returns the correct path!
67
-
68
- You can safely commit `infotable.css` to version control!
69
-
70
- ## Tailwind v3 (JS-based Config) - FALLBACK
71
-
72
- If using Tailwind v3, the installer adds dynamic path resolution to your `tailwind.config.js`:
73
-
74
- ```javascript
75
- const { execSync } = require('child_process');
76
- const path = require('path');
77
-
78
- // Helper to resolve gem path dynamically
79
- function resolveGemPath(gemName) {
80
- try {
81
- const bundlerCmd = `bundle show ${gemName}`;
82
- const gemPath = execSync(bundlerCmd, { encoding: 'utf-8' }).trim();
83
- return gemPath;
84
- } catch (error) {
85
- console.warn(`Warning: Could not resolve ${gemName} gem path:`, error.message);
86
- return null;
87
- }
88
- }
89
-
90
- const infotableGemPath = resolveGemPath('infotable');
91
-
92
- module.exports = {
93
- content: [
94
- './app/infotable/**/*.rb',
95
- ...(infotableGemPath ? [
96
- path.join(infotableGemPath, 'app/views/infotable/**/*.{erb,rb}'),
97
- path.join(infotableGemPath, 'app/assets/javascripts/infotable/**/*.js'),
98
- path.join(infotableGemPath, 'lib/infotable/formatters/**/*.rb'),
99
- path.join(infotableGemPath, 'app/components/**/*.{erb,rb}'),
100
- ] : []),
101
- ],
102
- // ... rest of config
103
- }
104
- ```
105
-
106
- This approach dynamically resolves the gem path at **build time** (every time Tailwind builds).
107
-
108
- ## Troubleshooting
109
-
110
- ### Styles Not Appearing
111
-
112
- 1. Check your Tailwind CSS file includes InfoTable @source directives
113
- 2. Verify gem path is correct: `bundle show infotable`
114
- 3. Update paths if needed: `rake infotable:update_tailwind_paths`
115
- 4. Rebuild: `rails tailwindcss:build`
116
-
117
- ### After Changing Gem Installation Method
118
-
119
- If you switch from `path:` to `git:` or vice versa:
120
-
121
- ```bash
122
- rake infotable:update_tailwind_paths
123
- rails tailwindcss:build
124
- ```
125
-
126
- ## Why Different Approaches?
127
-
128
- - **Tailwind v4**: @source doesn't support variables, so paths must be static and resolved at install time
129
- - **Tailwind v3**: JavaScript config supports dynamic resolution via `execSync`, so paths are resolved at build time
130
-
131
- Both approaches work reliably, but v4 is recommended for better Rails integration and performance.
@@ -1,55 +0,0 @@
1
- namespace :infotable do
2
- desc "Generate infotable.css from ERB template with resolved gem paths"
3
- task generate_tailwind_sources: :environment do
4
- # Find the ERB template
5
- erb_path = if File.exist?("app/assets/stylesheets/infotable.css.erb")
6
- "app/assets/stylesheets/infotable.css.erb"
7
- elsif File.exist?("app/assets/tailwind/infotable.css.erb")
8
- "app/assets/tailwind/infotable.css.erb"
9
- else
10
- puts "⚠️ infotable.css.erb not found. Run 'rails generate infotable:install' first."
11
- next
12
- end
13
-
14
- output_path = erb_path.sub(".erb", "")
15
-
16
- # Read and process the ERB template
17
- require "erb"
18
- template = File.read(erb_path)
19
- result = ERB.new(template).result(binding)
20
-
21
- # Write the generated CSS
22
- File.write(output_path, result)
23
-
24
- puts "✅ Generated #{output_path} from ERB template"
25
- puts " Views: #{Infotable.views_path}"
26
- puts " Formatters: #{Infotable.formatters_path}"
27
- end
28
-
29
- # Alias for backwards compatibility
30
- task update_tailwind_paths: :generate_tailwind_sources
31
-
32
- desc "Display InfoTable gem paths for Tailwind CSS (for debugging)"
33
- task show_tailwind_paths: :environment do
34
- puts "\n" + "=" * 60
35
- puts "InfoTable Gem Paths"
36
- puts "=" * 60
37
- puts "Gem root: #{Infotable.root}"
38
- puts "Views path: #{Infotable.views_path}"
39
- puts "Formatters path: #{Infotable.formatters_path}"
40
- puts "=" * 60 + "\n"
41
- end
42
- end
43
-
44
- # Hook into Tailwind CSS build tasks
45
- if Rake::Task.task_defined?("tailwindcss:build")
46
- Rake::Task["tailwindcss:build"].enhance([ "infotable:generate_tailwind_sources" ])
47
- end
48
-
49
- if Rake::Task.task_defined?("tailwindcss:watch")
50
- Rake::Task["tailwindcss:watch"].enhance([ "infotable:generate_tailwind_sources" ])
51
- end
52
-
53
- if Rake::Task.task_defined?("assets:precompile")
54
- Rake::Task["assets:precompile"].enhance([ "infotable:generate_tailwind_sources" ])
55
- end