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,22 +0,0 @@
1
- # module ActionDispatch
2
- # module Routing
3
- # class Mapper
4
- # class Mapping
5
-
6
- # def route_uses_slash_and_no_hash?
7
- # @options[:to].is_a?(String) &&
8
- # @options[:to].index('#').nil? &&
9
- # @options[:to].index('/')
10
- # end
11
-
12
- # def to
13
- # if route_uses_slash_and_no_hash?
14
- # @options[:to].sub('/','#')
15
- # else
16
- # @options[:to]
17
- # end
18
- # end
19
- # end
20
- # end
21
- # end
22
- # end
@@ -1,18 +0,0 @@
1
- module EZ
2
- module ViewHelpers
3
-
4
- def weather(location = 'Evanston, IL')
5
- EZ.weather(location)
6
- end
7
-
8
- def map(location, options = {})
9
- defaults = { :zoom => 12, :scale => 1, :size => '400x400', :type => 'hybrid', :sensor => false}
10
- parameters = defaults.merge(options)
11
- parameters[:center] = location
12
- qstring = parameters.keys.map { |key| "#{key}=#{parameters[key]}" }.join('&')
13
- url = "http://maps.googleapis.com/maps/api/staticmap?#{qstring}"
14
- image_tag URI.escape(url)
15
- end
16
-
17
- end
18
- end
@@ -1,35 +0,0 @@
1
- Description:
2
- Generates an example of one entire database-backed resource, from model
3
- and migration to controller and views. The resource is ready to use as a
4
- starting point for your RESTful, resource-oriented application.
5
-
6
- Pass the name of the model (in singular form), either CamelCased or
7
- under_scored, as the first argument, and an optional list of attribute
8
- pairs.
9
-
10
- Attributes are field arguments specifying the model's attributes. You can
11
- optionally pass the type and an index to each field. For instance:
12
- "title body:text tracking_id:integer:uniq" will generate a title field of
13
- string type, a body with text type and a tracking_id as an integer with an
14
- unique index. "index" could also be given instead of "uniq" if one desires
15
- a non unique index.
16
-
17
- Timestamps are added by default, so you don't have to specify them by hand
18
- as 'created_at:datetime updated_at:datetime'.
19
-
20
- You don't have to think up every attribute up front, but it helps to
21
- sketch out a few so you can start working with the resource immediately.
22
-
23
- For example, 'starter:resource post title body:text published:boolean' gives
24
- you a model with those three attributes, a controller that handles
25
- the create/show/update/destroy, forms to create and edit your posts, and
26
- an index that lists them all, as well as the Golden Seven "RESTful" routes
27
- in config/routes.rb.
28
-
29
- If you want to remove all the generated files, first rollback your migration
30
- with 'rake db:rollback' if you've already run 'rake db:migrate'. Then run
31
- 'rails destroy starter:resource ModelName'.
32
-
33
- Examples:
34
- `rails generate starter:resource post title body:text published:boolean`
35
- `rails generate starter:resource purchase amount:decimal tracking_id:integer:uniq`
@@ -1,15 +0,0 @@
1
- module ActiveRecord
2
- module Generators
3
- module Migration
4
- # Implement the required interface for Rails::Generators::Migration.
5
- def next_migration_number(dirname) #:nodoc:
6
- next_migration_number = current_migration_number(dirname) + 1
7
- if ActiveRecord::Base.timestamped_migrations
8
- [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
9
- else
10
- "%.3d" % next_migration_number
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,143 +0,0 @@
1
- require 'rails/generators/active_record'
2
- require_relative './migration'
3
- module Starter
4
- class ResourceGenerator < 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 :named_routes, :type => :boolean, :default => true
15
- class_option :skip_model, :type => :boolean, :default => false
16
- class_option :skip_controller, :type => :boolean, :default => false
17
- class_option :styled, :type => :boolean, :default => false, desc: 'Generates bootstrap-ready view templates'
18
- class_option :dry, :type => :boolean, :default => false, desc: 'DRYs up the controller, views, and routes'
19
-
20
- def generate_controller
21
- return if options[:skip_controller]
22
- if dry?
23
- template 'dried/controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
24
- else
25
- template 'controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
26
- end
27
- end
28
-
29
- def generate_model
30
- return if options[:skip_model]
31
- template 'model.rb', "app/models/#{singular_name.underscore}.rb"
32
- end
33
-
34
- def generate_migration
35
- return if options[:skip_model]
36
- migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
37
- end
38
-
39
- # def create_root_view_folder
40
- # empty_directory File.join("app/views", controller_file_path)
41
- # end
42
-
43
- def copy_view_files
44
- available_views.each do |view|
45
- filename = view_filename_with_extensions(view)
46
- template filename, File.join("app/views", controller_file_path, File.basename(filename))
47
- end
48
- end
49
-
50
-
51
- def generate_routes
52
- return if options[:skip_controller]
53
- if dry?
54
- route "resources :#{plural_name}", "Named RESTful routes"
55
- elsif named_routes?
56
- route golden_7_named, "Named RESTful routes"
57
- else
58
- route golden_7, "RESTful routes"
59
- end
60
- end
61
-
62
- protected
63
-
64
- def golden_7
65
- ["# Routes for the #{singular_name.capitalize} resource:",
66
- " # CREATE",
67
- " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new'",
68
- " post '/#{plural_name}', controller: '#{plural_name}', action: 'create'",
69
- "",
70
- " # READ",
71
- " get '/#{plural_name}', controller: '#{plural_name}', action: 'index'",
72
- " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show'",
73
- "",
74
- " # UPDATE",
75
- " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit'",
76
- " patch '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
77
- "",
78
- " # DELETE",
79
- " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
80
- " ##{'-' * 30}"
81
- ].join("\n")
82
- end
83
-
84
- def golden_7_named
85
- ["# Routes for the #{singular_name.capitalize} resource:",
86
- " # CREATE",
87
- " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new', as: 'new_#{singular_name}'",
88
- " post '/#{plural_name}', controller: '#{plural_name}', action: 'create', as: '#{plural_name}'",
89
- "",
90
- " # READ",
91
- " get '/#{plural_name}', controller: '#{plural_name}', action: 'index'",
92
- " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show', as: '#{singular_name}'",
93
- "",
94
- " # UPDATE",
95
- " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit', as: 'edit_#{singular_name}'",
96
- " patch '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
97
- "",
98
- " # DELETE",
99
- " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
100
- " ##{'-' * 30}"
101
- ].join("\n")
102
- end
103
-
104
- def dry?
105
- options[:dry]
106
- end
107
-
108
- def named_routes?
109
- options[:named_routes]
110
- end
111
-
112
- def styled?
113
- options[:styled]
114
- end
115
-
116
- # Override of Rails::Generators::Actions
117
- def route(routing_code, title)
118
- log :route, title
119
- sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
120
-
121
- in_root do
122
- inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
123
- end
124
- end
125
-
126
- def attributes_with_index
127
- attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
128
- end
129
-
130
- def available_views
131
- dry? ? %w(index new edit show _form) : %w(index new edit show)
132
- end
133
-
134
- def view_filename_with_extensions(name)
135
- filename = [name, :html, :erb].compact.join(".")
136
- folders = []
137
- folders << 'dried' if dry?
138
- folders << 'bootstrapped' if styled?
139
- filename = File.join(folders, filename) if folders.any?
140
- return filename
141
- end
142
- end
143
- end
@@ -1,26 +0,0 @@
1
- <div class="page-header">
2
- <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
- </div>
4
-
5
- <%%= form_tag(<%= singular_table_name %>_url(@<%= singular_table_name %>), method: 'patch', class: 'form-horizontal') do %>
6
- <% attributes.each do |attribute| -%>
7
- <div class="form-group">
8
- <%%= label_tag :<%= attribute.name %>, nil, class: 'col-md-2 control-label' %>
9
- <div class="col-md-6">
10
- <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
11
- <%%= text_field_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %>, class: 'form-control' %>
12
- <% elsif attribute.field_type == :check_box -%>
13
- <%%= check_box_tag :<%= attribute.name %>, 1, @<%= singular_table_name %>.<%= attribute.name %>? %>
14
- <% else -%>
15
- <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %>, class: 'form-control' %>
16
- <% end -%>
17
- </div>
18
- </div>
19
-
20
- <% end -%>
21
- <div class="form-group">
22
- <div class="col-md-offset-2 col-md-6">
23
- <%%= submit_tag "Update <%= human_name.titleize %>", class: 'btn btn-primary' %>
24
- </div>
25
- </div>
26
- <%% end %>
@@ -1,42 +0,0 @@
1
- <div class="page-header">
2
- <h1><%= plural_table_name.humanize %></h1>
3
- </div>
4
-
5
- <% if named_routes? -%>
6
- <p><%%= link_to 'Add a New <%= human_name.titleize %>', new_<%= singular_table_name %>_url, class: 'btn btn-primary' %></p>
7
- <% else -%>
8
- <p><%%= link_to 'Add a New <%= human_name.titleize %>', "/<%= plural_name %>/new", class: 'btn btn-primary' %></p>
9
- <% end -%>
10
-
11
- <table class="table table-hover">
12
- <thead>
13
- <tr>
14
- <% attributes.each do |attribute| -%>
15
- <th><%= attribute.human_name %></th>
16
- <% end -%>
17
- <th></th>
18
- <th></th>
19
- <th></th>
20
- </tr>
21
- </thead>
22
-
23
- <tbody>
24
- <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
25
- <tr>
26
- <% attributes.each do |attribute| -%>
27
- <td><%%= <%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %></td>
28
- <% end -%>
29
- <% if named_routes? -%>
30
- <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, <%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-primary' %></td>
31
- <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-warning' %></td>
32
- <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, <%= singular_table_name %>_url(<%= singular_table_name %>), method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: 'btn btn-danger' %></td>
33
- <% else -%>
34
- <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}", class: 'btn btn-primary' %></td>
35
- <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}/edit", class: 'btn btn-warning' %></td>
36
- <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}", method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: 'btn btn-danger' %></td>
37
- <% end -%>
38
- </tr>
39
- <%% end %>
40
- </tbody>
41
- </table>
42
-
@@ -1,26 +0,0 @@
1
- <div class="page-header">
2
- <h1>New <%= human_name.titleize %></h1>
3
- </div>
4
-
5
- <%%= form_tag(<%= plural_name %>_url, method: 'post', class: 'form-horizontal') do %>
6
- <% attributes.each do |attribute| -%>
7
- <div class="form-group">
8
- <%%= label_tag :<%= attribute.name %>, nil, class: 'col-md-2 control-label' %>
9
- <div class="col-md-6">
10
- <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
11
- <%%= text_field_tag :<%= attribute.name %>, nil, class: 'form-control' %>
12
- <% elsif attribute.field_type == :check_box -%>
13
- <%%= check_box_tag :<%= attribute.name %> %>
14
- <% else -%>
15
- <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, nil, class: 'form-control' %>
16
- <% end -%>
17
- </div>
18
- </div>
19
-
20
- <% end -%>
21
- <div class="form-group">
22
- <div class="col-md-offset-2 col-md-6">
23
- <%%= submit_tag "Create <%= human_name.titleize %>", class: 'btn btn-primary' %>
24
- </div>
25
- </div>
26
- <%% end %>
@@ -1,11 +0,0 @@
1
- <div class="page-header">
2
- <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
- </div>
4
-
5
- <dl class="dl-horizontal">
6
- <% attributes.each do |attribute| -%>
7
- <dt><%= attribute.human_name %></dt>
8
- <dd><%%= @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %></dd>
9
-
10
- <% end -%>
11
- </dl>
@@ -1,70 +0,0 @@
1
- class <%= plural_name.camelize %>Controller < ApplicationController
2
-
3
- def index
4
- @<%= plural_name.underscore %> = <%= class_name %>.all
5
- end
6
-
7
- def show
8
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
9
- end
10
-
11
- def new
12
- end
13
-
14
- def create
15
- @<%= singular_name.underscore %> = <%= class_name %>.new
16
- <% attributes.each do |attribute| -%>
17
- @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
18
- <% end -%>
19
-
20
- <% if named_routes? -%>
21
- if @<%= singular_name.underscore %>.save
22
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> created successfully."
23
- else
24
- render 'new'
25
- end
26
- <% else -%>
27
- if @<%= singular_name.underscore %>.save
28
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> created successfully."
29
- else
30
- render 'new'
31
- end
32
- <% end -%>
33
- end
34
-
35
- def edit
36
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
37
- end
38
-
39
- def update
40
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
41
- <% attributes.each do |attribute| -%>
42
- @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
43
- <% end -%>
44
-
45
- <% if named_routes? -%>
46
- if @<%= singular_name.underscore %>.save
47
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> updated successfully."
48
- else
49
- render 'edit'
50
- end
51
- <% else -%>
52
- if @<%= singular_name.underscore %>.save
53
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> updated successfully."
54
- else
55
- render 'edit'
56
- end
57
- <% end -%>
58
- end
59
-
60
- def destroy
61
- @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
62
- @<%= singular_name.underscore %>.destroy
63
-
64
- <% if named_routes? -%>
65
- redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> deleted."
66
- <% else -%>
67
- redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> deleted."
68
- <% end -%>
69
- end
70
- end
@@ -1,13 +0,0 @@
1
- <%%= form_for @<%= singular_table_name %> do |f| %>
2
-
3
- <% attributes.each do |attribute| -%>
4
- <div>
5
- <%%= f.label :<%= attribute.name %> %><br>
6
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
7
- </div>
8
-
9
- <% end -%>
10
- <div>
11
- <%%= f.submit %>
12
- </div>
13
- <%% end %>
@@ -1,21 +0,0 @@
1
- <%%= form_for(@<%= singular_table_name %>, html: { class: 'form-horizontal'}) do |f| %>
2
-
3
- <% attributes.each do |attribute| -%>
4
- <div class="form-group">
5
- <%%= f.label :<%= attribute.name %>, class: 'col-md-2' %>
6
- <%
7
- colsize = 6
8
- colsize = 2 if attribute.type == :integer
9
- %>
10
- <div class="col-md-<%= colsize %>">
11
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %><%= "?" if attribute.type == :boolean %>, class: 'form-control' %>
12
- </div>
13
- </div>
14
-
15
- <% end -%>
16
- <div class="form-group">
17
- <div class="col-md-offset-2 col-md-6">
18
- <%%= f.submit nil, class: 'btn btn-primary' %>
19
- </div>
20
- </div>
21
- <%% end %>