ez 1.3.0 → 1.5.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.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +8 -14
  4. data/lib/ez.rb +11 -17
  5. data/lib/ez/domain_modeler.rb +6 -2
  6. data/lib/ez/model.rb +1 -11
  7. data/lib/ez/schema_modifier.rb +25 -15
  8. data/lib/ez/version.rb +1 -1
  9. data/lib/tasks/ez_tasks.rake +2 -2
  10. metadata +4 -39
  11. data/lib/ez/apis.rb +0 -26
  12. data/lib/ez/controller.rb +0 -19
  13. data/lib/ez/dispatcher.rb +0 -28
  14. data/lib/ez/mapper.rb +0 -22
  15. data/lib/ez/view_helpers.rb +0 -18
  16. data/lib/generators/ez/resource/USAGE +0 -35
  17. data/lib/generators/ez/resource/migration.rb +0 -15
  18. data/lib/generators/ez/resource/resource_generator.rb +0 -143
  19. data/lib/generators/ez/resource/templates/bootstrapped/edit.html.erb +0 -26
  20. data/lib/generators/ez/resource/templates/bootstrapped/index.html.erb +0 -42
  21. data/lib/generators/ez/resource/templates/bootstrapped/new.html.erb +0 -26
  22. data/lib/generators/ez/resource/templates/bootstrapped/show.html.erb +0 -11
  23. data/lib/generators/ez/resource/templates/controller.rb +0 -70
  24. data/lib/generators/ez/resource/templates/dried/_form.html.erb +0 -13
  25. data/lib/generators/ez/resource/templates/dried/bootstrapped/_form.html.erb +0 -21
  26. data/lib/generators/ez/resource/templates/dried/bootstrapped/edit.html.erb +0 -5
  27. data/lib/generators/ez/resource/templates/dried/bootstrapped/index.html.erb +0 -42
  28. data/lib/generators/ez/resource/templates/dried/bootstrapped/new.html.erb +0 -5
  29. data/lib/generators/ez/resource/templates/dried/bootstrapped/show.html.erb +0 -11
  30. data/lib/generators/ez/resource/templates/dried/controller.rb +0 -72
  31. data/lib/generators/ez/resource/templates/dried/edit.html.erb +0 -3
  32. data/lib/generators/ez/resource/templates/dried/index.html.erb +0 -40
  33. data/lib/generators/ez/resource/templates/dried/new.html.erb +0 -3
  34. data/lib/generators/ez/resource/templates/dried/show.html.erb +0 -9
  35. data/lib/generators/ez/resource/templates/edit.html.erb +0 -24
  36. data/lib/generators/ez/resource/templates/index.html.erb +0 -40
  37. data/lib/generators/ez/resource/templates/migration.rb +0 -15
  38. data/lib/generators/ez/resource/templates/model.rb +0 -2
  39. data/lib/generators/ez/resource/templates/new.html.erb +0 -22
  40. data/lib/generators/ez/resource/templates/show.html.erb +0 -9
  41. data/lib/generators/ez/style/USAGE +0 -31
  42. data/lib/generators/ez/style/style_generator.rb +0 -34
  43. data/lib/generators/ez/style/templates/layout.html.erb +0 -66
  44. data/lib/generators/ez/user/templates/user_controller.rb +0 -68
  45. data/lib/generators/ez/user/user_generator.rb +0 -91
  46. data/lib/generators/ez/views/USAGE +0 -33
@@ -1,68 +0,0 @@
1
- class <%= plural_name.camelize %>Controller < ApplicationController
2
-
3
- before_action :require_login, :only => [:show, :edit, :update, :destroy]
4
-
5
- def show
6
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
7
- end
8
-
9
- def new
10
- end
11
-
12
- def create
13
- @<%= singular_name.underscore %> = <%= class_name %>.new
14
- <% attributes.each do |attribute| -%>
15
- @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
16
- <% end -%>
17
-
18
- <% if named_routes? -%>
19
- if @<%= singular_name.underscore %>.save
20
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> created successfully."
21
- else
22
- render 'new'
23
- end
24
- <% else -%>
25
- if @<%= singular_name.underscore %>.save
26
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> created successfully."
27
- else
28
- render 'new'
29
- end
30
- <% end -%>
31
- end
32
-
33
- def edit
34
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
35
- end
36
-
37
- def update
38
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
39
- <% attributes.each do |attribute| -%>
40
- @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
41
- <% end -%>
42
-
43
- <% if named_routes? -%>
44
- if @<%= singular_name.underscore %>.save
45
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> updated successfully."
46
- else
47
- render 'edit'
48
- end
49
- <% else -%>
50
- if @<%= singular_name.underscore %>.save
51
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> updated successfully."
52
- else
53
- render 'edit'
54
- end
55
- <% end -%>
56
- end
57
-
58
- def destroy
59
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
60
- @<%= singular_name.underscore %>.destroy
61
-
62
- <% if named_routes? -%>
63
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> deleted."
64
- <% else -%>
65
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> deleted."
66
- <% end -%>
67
- end
68
- end
@@ -1,91 +0,0 @@
1
- require 'rails/generators/active_record'
2
- require_relative './migration'
3
- module Starter
4
- class UserGenerator < Rails::Generators::NamedBase
5
- source_root File.expand_path('../templates', __FILE__)
6
- include Rails::Generators::ResourceHelpers
7
- include Rails::Generators::Migration
8
- extend ActiveRecord::Generators::Migration
9
-
10
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
- remove_class_option :old_style_hash
12
- remove_class_option :force_plural
13
- remove_class_option :skip_namespace
14
- class_option :styled, :type => :boolean, :default => true, desc: 'Generates bootstrap-ready view templates'
15
-
16
- def generate_controller
17
- template 'user_controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
18
- template 'sessions_controller.rb', "app/controllers/sessions_controller.rb"
19
- end
20
-
21
- def generate_model
22
- template 'model.rb', "app/models/#{singular_name.underscore}.rb"
23
- end
24
-
25
- def generate_migration
26
- return if options[:skip_model]
27
- migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
28
- end
29
-
30
- # def create_root_view_folder
31
- # empty_directory File.join("app/views", controller_file_path)
32
- # end
33
-
34
- def copy_view_files
35
- available_views.each do |view|
36
- filename = view_filename_with_extensions(view)
37
- template filename, File.join("app/views", controller_file_path, File.basename(filename))
38
- end
39
- end
40
-
41
-
42
- def generate_routes
43
- route user_routes, "Routes"
44
- end
45
-
46
- protected
47
-
48
- def user_routes
49
- ["# Routes for sign up, user profile management, login, and logout:",
50
- " get '/#{plural_name}/new' => '#{plural_name}#new'",
51
- " get '/#{plural_name}/create' => '#{plural_name}#create'",
52
- " get '/#{plural_name}/:#{singular_name}/show' => '#{plural_name}#show'",
53
- " get '/#{plural_name}/:#{singular_name}/edit' => '#{plural_name}#edit'",
54
- " get '/#{plural_name}/:#{singular_name}/update' => '#{plural_name}#update'",
55
- " get '/#{plural_name}/:#{singular_name}/delete' => '#{plural_name}#destroy'",
56
- " ",
57
- " get '/login' => 'sessions#new'",
58
- " get '/handle_login' => 'sessions#create'",
59
- " get '/logout' => 'sessions#logout'"
60
-
61
- ].join("\n")
62
- end
63
-
64
- # Override of Rails::Generators::Actions
65
- def route(routing_code, title)
66
- log :route, title
67
- sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
68
-
69
- in_root do
70
- inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
71
- end
72
- end
73
-
74
- def attributes_with_index
75
- attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
76
- end
77
-
78
- def available_views
79
- dry? ? %w(index new edit show _form) : %w(index new edit show)
80
- end
81
-
82
- def view_filename_with_extensions(name)
83
- filename = [name, :html, :erb].compact.join(".")
84
- folders = []
85
- folders << 'dried' if dry?
86
- folders << 'bootstrapped' if styled?
87
- filename = File.join(folders, filename) if folders.any?
88
- return filename
89
- end
90
- end
91
- end
@@ -1,33 +0,0 @@
1
- Description:
2
- Generates "CRUD"-style views
3
-
4
- Pass the name of the model (in singular form), either CamelCased or
5
- under_scored, as the first argument, and an optional list of attribute
6
- pairs.
7
-
8
- Attributes are field arguments specifying the model's attributes. You can
9
- optionally pass the type and an index to each field. For instance:
10
- "title body:text tracking_id:integer:uniq" will generate a title field of
11
- string type, a body with text type and a tracking_id as an integer with an
12
- unique index. "index" could also be given instead of "uniq" if one desires
13
- a non unique index.
14
-
15
- Timestamps are added by default, so you don't have to specify them by hand
16
- as 'created_at:datetime updated_at:datetime'.
17
-
18
- You don't have to think up every attribute up front, but it helps to
19
- sketch out a few so you can start working with the resource immediately.
20
-
21
- For example, 'starter:resource post title body:text published:boolean' gives
22
- you a model with those three attributes, a controller that handles
23
- the create/show/update/destroy, forms to create and edit your posts, and
24
- an index that lists them all, as well as the Golden Seven "RESTful" routes
25
- in config/routes.rb.
26
-
27
- If you want to remove all the generated files, first rollback your migration
28
- with 'rake db:rollback' if you've already run 'rake db:migrate'. Then run
29
- 'rails destroy starter:resource ModelName'.
30
-
31
- Examples:
32
- `rails generate starter:resource post title body:text published:boolean`
33
- `rails generate starter:resource purchase amount:decimal tracking_id:integer:uniq`