cafe_car 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e445b1f35396aa6ae7810eaab23e0d5b57bfb4ad6ea8fed5eb723586dbf1fa7
4
+ data.tar.gz: d914a80b54cda7f0579303a909a38093eae32dc1836d19f91a200fffb3775eee
5
+ SHA512:
6
+ metadata.gz: 52a1deab336f310203bb1e31779ed76a2da3a9616e84fdf6b7a7b3962b503f3d903d623a1c44143203c81a44a680d56a2d0a844b57f70f93dde727232538abd1
7
+ data.tar.gz: 5a3f0a0113086d9826d8952093af024f9c51091f261e7ab78b98de9796a1b69647fc436979479f4b68773d2350f5c3451853b03c6faf8c6cba45b47f71239e28
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright Jeff Peterson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # CafeCar
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "cafe_car"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install cafe_car
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ <% record_policy.editable_attributes.each do |c| %>
2
+ <%= f.input c %>
3
+ <% end %>
4
+
5
+ <% record_policy.reflect_on_editable_associations.each do |a| %>
6
+ <%= f.association a.name %>
7
+ <% end %>
File without changes
@@ -0,0 +1,22 @@
1
+ <% remote ||= false %>
2
+ <% title ||= nil %>
3
+
4
+ <%= form_for record, url: polymorphic_path(record), remote:, builder: CafeCar::FormBuilder do |f| %>
5
+ <div class="Card Card-limit">
6
+ <% if title.present? %>
7
+ <div class="Card_Head Card_Head-slim">
8
+ <h2><%= title %></h2>
9
+ </div>
10
+ <% end %>
11
+
12
+ .Card_Body.Flex
13
+ - f.object.errors.full_messages.each do |msg|
14
+ .Box.Box-error= msg
15
+ = render "fields", f: f
16
+
17
+ - if extra = render("extra_fields", f: f).presence
18
+ .Card_Body.Flex= extra
19
+
20
+ .Card_Body= f.submit class: 'btn blue', data: { disable_with: "Updating..." }
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,4 @@
1
+ module CafeCar
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module CafeCar
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cafe_car.rb ADDED
@@ -0,0 +1,181 @@
1
+ require "cafe_car/version"
2
+ require "cafe_car/railtie"
3
+
4
+ module CafeCar
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def model(model)
9
+ define_method(:record_model) { @record_model ||= model }
10
+ end
11
+ end
12
+
13
+ included do
14
+ helper_method :record_model, :record_name, :records_name, :record, :records, :record_policy
15
+ rescue_from ActiveRecord::RecordInvalid, with: :render_invalid_record
16
+ prepend_view_path 'app/views/cafe_car'
17
+ end
18
+
19
+ def index
20
+ self.records = records.page(params[:page]).per(params[:per] || 100)
21
+ self.records = filtered(records) if respond_to?(:filtered, true)
22
+ self.records = paginated(records) if respond_to?(:paginated, true)
23
+ self.records = sorted(records) if respond_to?(:sorted, true)
24
+ self.records = records.includes(*includes) if respond_to?(:includes, true)
25
+
26
+ validate_filter_scope(records)
27
+
28
+ authorize records
29
+ end
30
+
31
+ def show
32
+ self.record = record!
33
+ authorize record
34
+ end
35
+
36
+ def new
37
+ self.record = new_record
38
+ authorize record
39
+ end
40
+
41
+ def edit
42
+ self.record = record!
43
+ authorize record
44
+ end
45
+
46
+ def create
47
+ self.record = new_record
48
+ authorize record
49
+ record.assign_attributes(permitted_attributes(record))
50
+
51
+ record.save!
52
+ created
53
+
54
+ respond_to do |f|
55
+ f.js { created_js }
56
+ f.html { created_redirect }
57
+ f.json {}
58
+ end
59
+ end
60
+
61
+ def update
62
+ self.record = record!
63
+ authorize record
64
+
65
+ record.update!(permitted_attributes(record))
66
+ updated
67
+ respond_to do |f|
68
+ f.js { updated_js }
69
+ f.html { updated_redirect }
70
+ f.json {}
71
+ end
72
+ end
73
+
74
+ def destroy
75
+ self.record = record!
76
+ authorize record
77
+
78
+ destroy_record
79
+
80
+ destroyed
81
+ respond_to do |f|
82
+ f.js { destroyed_js }
83
+ f.html { destroyed_redirect }
84
+ f.json {}
85
+ end
86
+ end
87
+
88
+ def alter_tags
89
+ self.record = record!
90
+ authorize record
91
+ # tag_list compares tags case-insensitively when adding, but not when removing
92
+ remove = [*params[:remove]].map { |t| record.tag_list.find { |t2| t.casecmp(t2).zero? } }
93
+ tags = record.tag_list.remove(*remove).add(*params[:add])
94
+ if record.save
95
+ render json: { tags: }
96
+ else
97
+ render json: { errors: record.errors.full_messages }, status: :bad_request
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def new_record
104
+ record_scope.new
105
+ end
106
+
107
+ def record!
108
+ if record_model.respond_to?(:[])
109
+ record_scope[params[:id]]
110
+ else
111
+ record_scope.find(params[:id])
112
+ end
113
+ end
114
+
115
+ def record_scope
116
+ record_model.all
117
+ end
118
+
119
+ def destroy_record
120
+ record.destroy
121
+ end
122
+
123
+ def records!
124
+ policy_scope(record_scope.all)
125
+ end
126
+
127
+ def records
128
+ instance_variable_get("@#{records_name}") || (self.records = records!)
129
+ end
130
+
131
+ def records=(value)
132
+ instance_variable_set("@#{records_name}", value)
133
+ end
134
+
135
+ def record
136
+ instance_variable_get("@#{record_name}") || (self.record = record!)
137
+ end
138
+
139
+ def record=(value)
140
+ instance_variable_set("@#{record_name}", value)
141
+ end
142
+
143
+ def record_model
144
+ @record_model ||= self.class.name.gsub(/.*::|Controller$/, '').singularize.constantize
145
+ end
146
+
147
+ def record_policy = @policy ||= policy record
148
+ def record_name = record_model.model_name.singular
149
+ def records_name = record_model.model_name.plural
150
+ def render_invalid_record = render record.persisted? ? 'edit' : 'new'
151
+
152
+ def created_redirect = redirect_back fallback_location: [records_name.to_sym]
153
+ def destroyed_redirect = redirect_to [records_name.to_sym]
154
+
155
+ def updated_redirect
156
+ return destroyed_redirect if record.destroyed?
157
+ redirect_to record
158
+ end
159
+
160
+ def created_js
161
+ render 'create'
162
+ rescue ActionView::MissingTemplate
163
+ created_redirect
164
+ end
165
+
166
+ def updated_js
167
+ render 'update'
168
+ rescue ActionView::MissingTemplate
169
+ updated_redirect
170
+ end
171
+
172
+ def destroyed_js
173
+ render 'destroy'
174
+ rescue ActionView::MissingTemplate
175
+ destroyed_redirect
176
+ end
177
+
178
+ def created; end
179
+ def updated; end
180
+ def destroyed; end
181
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cafe_car do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cafe_car
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Peterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.3.2
27
+ description: Rails UI and admin panels.
28
+ email:
29
+ - jeff@yak.sh
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - app/views/cafe_car/application/_actions.html.erb
38
+ - app/views/cafe_car/application/_aside.html.erb
39
+ - app/views/cafe_car/application/_extra_fields.html.erb
40
+ - app/views/cafe_car/application/_fields.html.erb
41
+ - app/views/cafe_car/application/_filters.html.erb
42
+ - app/views/cafe_car/application/_form.html.erb
43
+ - lib/cafe_car.rb
44
+ - lib/cafe_car/railtie.rb
45
+ - lib/cafe_car/version.rb
46
+ - lib/tasks/cafe_car_tasks.rake
47
+ homepage: https://concept.love/cafe_car
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://concept.love/cafe_car
52
+ source_code_uri: https://github.com/craft-concept/cafe_car
53
+ changelog_uri: https://github.com/craft-concept/cafe_car
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.5.3
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Rails UI and admin panels.
73
+ test_files: []