elaine_crud 0.1.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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/LICENSE +21 -0
  4. data/README.md +225 -0
  5. data/Rakefile +9 -0
  6. data/TODO.md +496 -0
  7. data/app/controllers/elaine_crud/base_controller.rb +228 -0
  8. data/app/helpers/elaine_crud/base_helper.rb +787 -0
  9. data/app/helpers/elaine_crud/search_helper.rb +132 -0
  10. data/app/javascript/controllers/dropdown_controller.js +18 -0
  11. data/app/views/elaine_crud/base/_edit_row.html.erb +60 -0
  12. data/app/views/elaine_crud/base/_export_button.html.erb +88 -0
  13. data/app/views/elaine_crud/base/_foreign_key_select_refresh.html.erb +52 -0
  14. data/app/views/elaine_crud/base/_form.html.erb +45 -0
  15. data/app/views/elaine_crud/base/_form_fields.html.erb +45 -0
  16. data/app/views/elaine_crud/base/_index_table.html.erb +58 -0
  17. data/app/views/elaine_crud/base/_modal.html.erb +71 -0
  18. data/app/views/elaine_crud/base/_pagination.html.erb +110 -0
  19. data/app/views/elaine_crud/base/_per_page_selector.html.erb +30 -0
  20. data/app/views/elaine_crud/base/_search_bar.html.erb +75 -0
  21. data/app/views/elaine_crud/base/_show_details.html.erb +29 -0
  22. data/app/views/elaine_crud/base/_view_row.html.erb +96 -0
  23. data/app/views/elaine_crud/base/edit.html.erb +51 -0
  24. data/app/views/elaine_crud/base/index.html.erb +74 -0
  25. data/app/views/elaine_crud/base/new.html.erb +12 -0
  26. data/app/views/elaine_crud/base/new_modal.html.erb +37 -0
  27. data/app/views/elaine_crud/base/not_found.html.erb +49 -0
  28. data/app/views/elaine_crud/base/show.html.erb +32 -0
  29. data/docs/ARCHITECTURE.md +410 -0
  30. data/docs/CSS_GRID_LAYOUT.md +126 -0
  31. data/docs/DEMO.md +693 -0
  32. data/docs/DSL_EXAMPLES.md +313 -0
  33. data/docs/FOREIGN_KEY_EXAMPLE.rb +100 -0
  34. data/docs/FOREIGN_KEY_SUPPORT.md +197 -0
  35. data/docs/HAS_MANY_IMPLEMENTATION.md +154 -0
  36. data/docs/LAYOUT_EXAMPLES.md +301 -0
  37. data/docs/TROUBLESHOOTING.md +170 -0
  38. data/elaine_crud.gemspec +46 -0
  39. data/lib/elaine_crud/dsl_methods.rb +348 -0
  40. data/lib/elaine_crud/engine.rb +37 -0
  41. data/lib/elaine_crud/export_handling.rb +164 -0
  42. data/lib/elaine_crud/field_configuration.rb +422 -0
  43. data/lib/elaine_crud/field_configuration_methods.rb +152 -0
  44. data/lib/elaine_crud/layout_calculation.rb +55 -0
  45. data/lib/elaine_crud/parameter_handling.rb +48 -0
  46. data/lib/elaine_crud/record_fetching.rb +150 -0
  47. data/lib/elaine_crud/relationship_handling.rb +220 -0
  48. data/lib/elaine_crud/routing.rb +33 -0
  49. data/lib/elaine_crud/search_and_filtering.rb +285 -0
  50. data/lib/elaine_crud/sorting_concern.rb +65 -0
  51. data/lib/elaine_crud/version.rb +5 -0
  52. data/lib/elaine_crud.rb +25 -0
  53. data/lib/tasks/demo.rake +111 -0
  54. data/lib/tasks/spec.rake +26 -0
  55. metadata +264 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d420c3bf1695740a2f4c8681c27718bf7291439f31ee33024130340052d042eb
4
+ data.tar.gz: b753bc127d554534dd1afe6d09feedd8239c37e0e535dbc442c18ffb4ecdfd4c
5
+ SHA512:
6
+ metadata.gz: efb078bfecaa663340d1b093e8aea548f900ee3fac8bd2823d00ebb5e21c628885e95b1df9ffe85cb86b57d8df6042448d303d1f45b85c40581db8ac682f5f51
7
+ data.tar.gz: 4b58dd75dd0d3a672c2e08fc0d8cdf18238c874b9926f808253552ccfdc727bf1f1958942aabf3977eccc65e69751de4e3e5c904369232e0765b0a9557e0852c
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --require spec_helper
2
+ --color
3
+ --format documentation
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Juho Mäkinen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # ElaineCrud
2
+
3
+ A Rails engine for rapidly generating CRUD interfaces for ActiveRecord models with minimal configuration.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Zero Configuration**: Works out of the box with any ActiveRecord model
8
+ - ✅ **Minimal Code**: Just specify model and permitted params
9
+ - ✅ **Modern UI**: Clean, responsive interface with TailwindCSS
10
+ - ✅ **Extensible**: Override any view or behavior in your host app
11
+ - ✅ **Rails Conventions**: Follows standard Rails patterns
12
+
13
+ ## Installation
14
+
15
+ Add to your `Gemfile`:
16
+
17
+ ```ruby
18
+ gem 'elaine_crud'
19
+ ```
20
+
21
+ Then run:
22
+ ```bash
23
+ bundle install
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ### 1. Create a Controller
29
+
30
+ ```ruby
31
+ class PeopleController < ElaineCrud::BaseController
32
+ layout 'application' # Specify your app's layout
33
+
34
+ model Person
35
+ permit_params :name, :email, :phone, :active
36
+ end
37
+ ```
38
+
39
+ ### 2. Add Routes
40
+
41
+ ```ruby
42
+ # config/routes.rb
43
+ resources :people
44
+ ```
45
+
46
+ ### 3. Configure TailwindCSS (Important!)
47
+
48
+ Add the gem's files to your `tailwind.config.js`. You need to include the gem's path in Tailwind's content scanning:
49
+
50
+ ```javascript
51
+ const path = require('path')
52
+ const execSync = require('child_process').execSync
53
+
54
+ // Get the gem path from bundler
55
+ const gemPath = execSync('bundle show elaine_crud', { encoding: 'utf-8' }).trim()
56
+
57
+ module.exports = {
58
+ content: [
59
+ './app/views/**/*.html.erb',
60
+ './app/helpers/**/*.rb',
61
+ './app/assets/stylesheets/**/*.css',
62
+ './app/javascript/**/*.js',
63
+ // Add ElaineCrud gem views and helpers
64
+ path.join(gemPath, 'app/views/**/*.html.erb'),
65
+ path.join(gemPath, 'app/helpers/**/*.rb')
66
+ ],
67
+ // ... rest of your config
68
+ }
69
+ ```
70
+
71
+ ### 4. Restart Your Server
72
+
73
+ ```bash
74
+ rails server
75
+ ```
76
+
77
+ Navigate to `/people` and you'll have a fully functional CRUD interface!
78
+
79
+ ## Usage
80
+
81
+ ### Basic Controller
82
+
83
+ The minimal controller setup:
84
+
85
+ ```ruby
86
+ class ArticlesController < ElaineCrud::BaseController
87
+ layout 'application' # Host app controls layout (header/footer/styling)
88
+
89
+ model Article
90
+ permit_params :title, :content, :published
91
+ end
92
+ ```
93
+
94
+ ### DSL Reference
95
+
96
+ - `model(ModelClass)` - Specify the ActiveRecord model to manage
97
+ - `permit_params(*attrs)` - Define permitted attributes for strong parameters
98
+ - `columns(config)` - (Future) Configure column display options
99
+
100
+ ### Customization
101
+
102
+ #### Override Views
103
+
104
+ Create views in your app with the same names to override engine views:
105
+
106
+ ```
107
+ app/views/articles/index.html.erb # Overrides engine's index view
108
+ ```
109
+
110
+ #### Override Controller Methods
111
+
112
+ ```ruby
113
+ class ArticlesController < ElaineCrud::BaseController
114
+ model Article
115
+ permit_params :title, :content, :published
116
+
117
+ private
118
+
119
+ # Custom record fetching with scoping
120
+ def fetch_records
121
+ Article.published.order(:title)
122
+ end
123
+
124
+ # Custom column selection
125
+ def determine_columns
126
+ %w[title published created_at]
127
+ end
128
+ end
129
+ ```
130
+
131
+ #### Custom Helpers
132
+
133
+ Override the display helper in your application:
134
+
135
+ ```ruby
136
+ # app/helpers/application_helper.rb
137
+ def display_column_value(record, column)
138
+ case column
139
+ when 'published'
140
+ record.published? ? '📘 Published' : '📝 Draft'
141
+ else
142
+ super # Call the engine's helper
143
+ end
144
+ end
145
+ ```
146
+
147
+ ## Requirements
148
+
149
+ - Rails 6.0+
150
+ - TailwindCSS (for styling)
151
+
152
+ ## Examples
153
+
154
+ ### Complete Example: Managing Blog Posts
155
+
156
+ ```ruby
157
+ # app/controllers/posts_controller.rb
158
+ class PostsController < ElaineCrud::BaseController
159
+ layout 'application' # Use your app's layout
160
+
161
+ model Post
162
+ permit_params :title, :content, :published, :category_id
163
+
164
+ private
165
+
166
+ def fetch_records
167
+ Post.includes(:category).order(created_at: :desc)
168
+ end
169
+ end
170
+
171
+ # config/routes.rb
172
+ resources :posts
173
+
174
+ # Navigate to /posts for instant CRUD interface
175
+ ```
176
+
177
+ ### Example Output
178
+
179
+ The generated interface includes:
180
+ - **Index Page**: Responsive table with all records
181
+ - **Smart Formatting**: Dates, booleans, and nil values formatted nicely
182
+ - **Action Buttons**: Edit and Delete functionality
183
+ - **Empty States**: Helpful messages when no records exist
184
+ - **Modern Styling**: Clean TailwindCSS design
185
+
186
+ ## Architecture
187
+
188
+ ElaineCrud follows a **separation of concerns** approach:
189
+
190
+ - **Engine provides**: CRUD logic, data formatting, content templates
191
+ - **Host app provides**: Layout, styling, HTML structure, navigation
192
+
193
+ ### Layout Control
194
+
195
+ The gem doesn't impose any layout - your app controls the HTML structure:
196
+
197
+ ```ruby
198
+ class UsersController < ElaineCrud::BaseController
199
+ layout 'admin' # Use admin layout
200
+ # or layout 'public' # Use public layout
201
+ # or layout false # No layout (API mode)
202
+
203
+ model User
204
+ permit_params :name, :email
205
+ end
206
+ ```
207
+
208
+ This means:
209
+ - ✅ **Your app controls**: Headers, footers, navigation, CSS frameworks
210
+ - ✅ **Engine provides**: Table content, buttons, data formatting
211
+ - ✅ **Zero view files needed**: No templates to create in your app
212
+
213
+ See [ARCHITECTURE.md](docs/ARCHITECTURE.md) for detailed technical documentation.
214
+
215
+ ## Contributing
216
+
217
+ 1. Fork the repository
218
+ 2. Create a feature branch
219
+ 3. Make your changes
220
+ 4. Add tests
221
+ 5. Submit a pull request
222
+
223
+ ## License
224
+
225
+ MIT License. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ # Load demo tasks
7
+ Dir.glob('lib/tasks/*.rake').each { |r| load r }
8
+
9
+ task default: :spec