effective_developer 0.1.1 → 0.2
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 +4 -4
- data/README.md +81 -13
- data/lib/effective_developer/version.rb +1 -1
- data/lib/generators/effective/ability_generator.rb +2 -2
- data/lib/generators/effective/helpers.rb +8 -4
- data/lib/generators/effective/menu_generator.rb +1 -1
- data/lib/generators/effective/route_generator.rb +2 -2
- data/lib/generators/effective/scaffold_generator.rb +7 -3
- data/lib/generators/effective/views_generator.rb +3 -1
- data/lib/scaffolds/controllers/controller.rb +3 -3
- data/lib/scaffolds/datatables/datatable.rb +3 -3
- data/lib/scaffolds/views/edit.html.haml +3 -3
- data/lib/scaffolds/views/show.html.haml +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0bc78241a7312115a37e3ea85a1e91fe356fdc5
|
4
|
+
data.tar.gz: e15e7239d99c756268644a9a897388c37319f956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f19e58ab88d396f8a03e6e05fedcf93b994ab1969f3a0cedfc17949edf1ac77fef4af3309d1e78ac1eae7c66ec3817b6847e709c0404744ad3ee7287664ead0e
|
7
|
+
data.tar.gz: c546bacc1dd23d075566de969a10246cfddaa0f618b25c8a01ad2b1271035b2053d2344094064010b4fd1badb19448c51534cad970975ec5fb274590549ef1c4
|
data/README.md
CHANGED
@@ -52,6 +52,18 @@ To release a new gem version:
|
|
52
52
|
> gem_release 1.0.0
|
53
53
|
```
|
54
54
|
|
55
|
+
## gitreset
|
56
|
+
|
57
|
+
Careful, this command will delete all your un committed changes.
|
58
|
+
|
59
|
+
A command line script to call `git reset --hard` and also delete any newly created files.
|
60
|
+
|
61
|
+
It truly resets you back to a fresh working copy. Perfect for tweaking scaffold and code generation tools.
|
62
|
+
|
63
|
+
```console
|
64
|
+
> gitreset
|
65
|
+
```
|
66
|
+
|
55
67
|
## gitsweep
|
56
68
|
|
57
69
|
A command line script to delete any git branch that has already been merged into master & develop
|
@@ -208,36 +220,94 @@ end
|
|
208
220
|
|
209
221
|
Override `before_import()` or `after_import()` to run code before or after the import.
|
210
222
|
|
211
|
-
#
|
223
|
+
# Code Generation
|
224
|
+
|
225
|
+
The goal of the `effective_developer` code generation project is to minimize the amount of hand coding required to build a rails website.
|
226
|
+
|
227
|
+
Only the rails model file should be written by a human.
|
212
228
|
|
213
|
-
|
229
|
+
All database migrations, controllers, forms and views should be generated.
|
214
230
|
|
215
|
-
|
231
|
+
Creating a new working in-place CRUD feature should be a 1-liner.
|
232
|
+
|
233
|
+
A huge head start to the interesting part of the code.
|
234
|
+
|
235
|
+
## effective scaffolds
|
236
|
+
|
237
|
+
Scaffolding is the fastest way to build a CRUD rails app.
|
238
|
+
|
239
|
+
The effective scaffolds generally follow the same pattern as the (rails generate)[http://guides.rubyonrails.org/command_line.html#rails-generate] commands.
|
240
|
+
|
241
|
+
To create an entire CRUD resource from the command line:
|
216
242
|
|
217
243
|
```ruby
|
218
244
|
rails generate effective:scaffold thing name:string description:text
|
219
|
-
|
245
|
+
rails generate effective:scaffold thing name:string description:text --actions index show mark_as_paid
|
220
246
|
rails generate effective:scaffold admin/thing name:string description:text
|
247
|
+
rails generate effective:scaffold admin/thing name:string description:text --actions crud-show
|
221
248
|
|
222
|
-
rails generate effective:scaffold thing name:string description:text --actions crud archive
|
223
|
-
|
224
|
-
rails generate effective:scaffold admin/thing name:string description:text --actions crud-show unarchive
|
225
249
|
```
|
226
250
|
|
227
|
-
Or
|
251
|
+
Or to skip the model & migration:
|
228
252
|
|
229
253
|
```ruby
|
230
254
|
rails generate effective:scaffold_controller thing
|
255
|
+
rails generate effective:scaffold_controller thing index show
|
256
|
+
rails generate effective:scaffold_controller admin/thing crud mark_as_paid
|
257
|
+
rails generate effective:scaffold_controller admin/thing crud-show
|
258
|
+
```
|
259
|
+
|
260
|
+
### model file
|
231
261
|
|
232
|
-
rails
|
262
|
+
If there is a regular rails model file present, all attributes, belong_tos, scopes and has_many accepts_nested_attributes
|
263
|
+
will be considered when generating the scaffold.
|
264
|
+
|
265
|
+
Make a model file like this (or generate it with `rails generate effective:model post name:string body:text` and tweak from there):
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
class Post < ApplicationRecord
|
269
|
+
belongs_to :user
|
270
|
+
belongs_to :category
|
271
|
+
|
272
|
+
# Attributes
|
273
|
+
# name :string
|
274
|
+
# body :text
|
275
|
+
# published_at :datetime
|
276
|
+
|
277
|
+
validates :name, presence: true
|
278
|
+
validates :description, presence: true
|
279
|
+
|
280
|
+
has_many :comments
|
281
|
+
accepts_nested_attributes_for :comments
|
282
|
+
|
283
|
+
scope :published, -> { where.not(published_at: nil) }
|
284
|
+
|
285
|
+
def to_s
|
286
|
+
name || 'New Post'
|
287
|
+
end
|
288
|
+
end
|
289
|
+
```
|
290
|
+
|
291
|
+
and then run
|
292
|
+
|
293
|
+
```console
|
294
|
+
rails generate scaffold post
|
295
|
+
rails generate scaffold_controller admin/post
|
233
296
|
```
|
234
297
|
|
235
|
-
|
298
|
+
Tweak from here
|
299
|
+
|
300
|
+
### all scaffolds
|
301
|
+
|
302
|
+
You can call scaffolds one at a time:
|
236
303
|
|
237
304
|
```ruby
|
305
|
+
# These two accept attributes on the command line. like effective:scaffold
|
238
306
|
rails generate effective:model thing name:string description:text
|
239
307
|
rails generate effective:migration thing name:string description:text
|
240
|
-
|
308
|
+
|
309
|
+
# Thes accept actions on the command line. with --attributes. like effective:scaffold_controller
|
310
|
+
rails generate effective:controller thing # /admin/thing
|
241
311
|
rails generate effective:route thing
|
242
312
|
rails generate effective:ability thing # CanCanCan
|
243
313
|
rails generate effective:menu thing # If app/views/*namespaces/_navbar.html.haml is present
|
@@ -246,8 +316,6 @@ rails generate effective:views thing
|
|
246
316
|
rails generate effective:form thing
|
247
317
|
```
|
248
318
|
|
249
|
-
These scaffold generators are still an ongoing work in progress. There is a lot more inspect the model and do the right thing type functionality to be implemented "soon".
|
250
|
-
|
251
319
|
## License
|
252
320
|
|
253
321
|
MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
|
@@ -58,8 +58,8 @@ module Effective
|
|
58
58
|
abilities += (crud_actions & invoked_actions)
|
59
59
|
end
|
60
60
|
|
61
|
-
if
|
62
|
-
abilities +=
|
61
|
+
if non_crud_actions.present?
|
62
|
+
abilities += non_crud_actions
|
63
63
|
end
|
64
64
|
|
65
65
|
abilities = ['manage'] if abilities.blank? || abilities == (crud_actions - ['show'])
|
@@ -12,6 +12,10 @@ module Effective
|
|
12
12
|
%w(index new create show edit update destroy)
|
13
13
|
end
|
14
14
|
|
15
|
+
def non_crud_actions
|
16
|
+
invoked_actions - crud_actions
|
17
|
+
end
|
18
|
+
|
15
19
|
# --actions crud another
|
16
20
|
# --actions crud-show another
|
17
21
|
def invoked_actions
|
@@ -50,10 +54,10 @@ module Effective
|
|
50
54
|
klass_attributes = resource.klass_attributes
|
51
55
|
|
52
56
|
if klass_attributes.blank?
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
if ActiveRecord::Migrator.new(:up, ActiveRecord::Migrator.migrations(ActiveRecord::Migrator.migrations_paths)).pending_migrations.present?
|
58
|
+
migrate = ask("Unable to read the attributes of #{resource.klass || resource.name}. There are pending migrations. Run db:migrate now? [y/n]")
|
59
|
+
system('bundle exec rake db:migrate') if migrate.to_s.include?('y')
|
60
|
+
end
|
57
61
|
|
58
62
|
klass_attributes = resource.klass_attributes
|
59
63
|
end
|
@@ -64,8 +64,8 @@ module Effective
|
|
64
64
|
resources << ']'
|
65
65
|
end
|
66
66
|
|
67
|
-
if
|
68
|
-
[resources + ' do'] +
|
67
|
+
if non_crud_actions.present?
|
68
|
+
[resources + ' do'] + non_crud_actions.map { |action| "get :#{action}, on: :member" } + ['end']
|
69
69
|
else
|
70
70
|
resources
|
71
71
|
end
|
@@ -18,11 +18,15 @@ module Effective
|
|
18
18
|
class_option :actions, type: :array, default: ['crud'], desc: 'Included actions', banner: 'index show'
|
19
19
|
|
20
20
|
def invoke_model
|
21
|
-
|
21
|
+
if File.exists?(resource.model_file)
|
22
|
+
say_status(:skipped, :model, :yellow) and return
|
23
|
+
end
|
24
|
+
|
25
|
+
Rails::Generators.invoke('effective:model', [name] + invokable(invoked_attributes))
|
22
26
|
end
|
23
27
|
|
24
28
|
def invoke_migration
|
25
|
-
Rails::Generators.invoke('effective:migration', [name] + invoked_attributes)
|
29
|
+
Rails::Generators.invoke('effective:migration', [name] + invokable(invoked_attributes))
|
26
30
|
end
|
27
31
|
|
28
32
|
def invoke_controller
|
@@ -58,7 +62,7 @@ module Effective
|
|
58
62
|
say_status(:skipped, :form, :yellow) and return
|
59
63
|
end
|
60
64
|
|
61
|
-
Rails::Generators.invoke('effective:form', [name] + invoked_attributes)
|
65
|
+
Rails::Generators.invoke('effective:form', [name] + invokable(invoked_attributes))
|
62
66
|
end
|
63
67
|
|
64
68
|
end
|
@@ -30,7 +30,9 @@ module Effective
|
|
30
30
|
template "views/#{action}.html.haml", resource.view_file(action)
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
if invoked_actions.include?('show') || non_crud_actions.present?
|
34
|
+
template 'views/_resource.html.haml', resource.view_file(resource.name, partial: true)
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
private
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class <%= resource.namespaced_class_name %>Controller < <%= [resource.namespace.try(:classify).presence, ApplicationController].compact.join('::') %>
|
1
|
+
class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.namespace.try(:classify).presence, ApplicationController].compact.join('::') %>
|
2
2
|
before_action :authenticate_user! # Devise enforce user is present
|
3
3
|
|
4
4
|
<% if defined?(EffectiveResources) -%>
|
@@ -10,7 +10,7 @@ class <%= resource.namespaced_class_name %>Controller < <%= [resource.namespace.
|
|
10
10
|
@page_title = '<%= resource.plural_name.titleize %>'
|
11
11
|
authorize! :index, <%= resource.class_name %>
|
12
12
|
|
13
|
-
@datatable = <%= resource.namespaced_class_name %>Datatable.new(params[:scopes])
|
13
|
+
@datatable = <%= resource.namespaced_class_name.pluralize %>Datatable.new(params[:scopes])
|
14
14
|
end
|
15
15
|
|
16
16
|
<% end -%>
|
@@ -127,7 +127,7 @@ class <%= resource.namespaced_class_name %>Controller < <%= [resource.namespace.
|
|
127
127
|
)
|
128
128
|
end
|
129
129
|
|
130
|
-
<% if defined?(EffectiveResources) -%>
|
130
|
+
<% if !defined?(EffectiveResources) -%>
|
131
131
|
def redirect_path
|
132
132
|
case params[:commit].to_s
|
133
133
|
when 'Save'
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class <%= resource.namespaced_class_name %>Datatable < Effective::Datatable
|
1
|
+
class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Datatable
|
2
2
|
<% if resource.scopes.present? -%>
|
3
3
|
scopes do<% ([:all] + resource.scopes).uniq.each_with_index do |scope, index| %>
|
4
4
|
scope :<%= scope -%><%= ', default: true' if index == 0 -%>
|
@@ -17,9 +17,9 @@ class <%= resource.namespaced_class_name %>Datatable < Effective::Datatable
|
|
17
17
|
table_column :<%= attribute.name %>
|
18
18
|
<% end -%>
|
19
19
|
|
20
|
-
<% if
|
20
|
+
<% if non_crud_actions.present? -%>
|
21
21
|
actions_column do |<%= singular_name %>|
|
22
|
-
<%
|
22
|
+
<% non_crud_actions.each_with_index do |action, index| -%>
|
23
23
|
glyphicon_to('ok', <%= resource.action_path_helper(action, at: false) %>, title: '<%= action.titleize %>')<%= ' +' if (index+1) < (invoked_actions - crud_actions).length %>
|
24
24
|
<% end -%>
|
25
25
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
%h1= @page_title
|
2
2
|
|
3
|
-
<% if
|
3
|
+
<% if non_crud_actions.present? -%>
|
4
4
|
%p.text-right
|
5
|
-
<%
|
5
|
+
<% non_crud_actions.each do |action| -%>
|
6
6
|
- if can?(:<%= action.to_s %>, @<%= resource.name %>)
|
7
7
|
= link_to '<%= action.titleize %>', <%= resource.action_path_helper(action, at: true) %>, class: 'btn btn-primary',
|
8
8
|
data: { confirm: 'Really <%= action.to_s.titleize %>?' }
|
9
9
|
|
10
10
|
<% end -%>
|
11
11
|
<% end -%>
|
12
|
-
= render 'form', <%=
|
12
|
+
= render 'form', <%= resource.name %>: @<%= resource.name %>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
%h1= @page_title
|
2
2
|
|
3
|
-
<% if
|
3
|
+
<% if non_crud_actions.present? -%>
|
4
4
|
%p.text-right
|
5
|
-
<%
|
5
|
+
<% non_crud_actions.each do |action| -%>
|
6
6
|
- if can?(:<%= action.to_s %>, @<%= resource.name %>)
|
7
7
|
= link_to '<%= action.titleize %>', <%= resource.action_path_helper(action, at: true) %>, class: 'btn btn-default',
|
8
8
|
data: { confirm: 'Really <%= action.to_s.titleize %>?' }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_developer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|