fume 0.6.3 → 0.6.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.3
1
+ 0.6.4
@@ -0,0 +1,10 @@
1
+ Description:
2
+ scaffold controller
3
+
4
+ Example:
5
+ rails generate fume:simple_scaffold Admin::User name:string email:string
6
+
7
+ This will create:
8
+ Controller: app/controllers/admin/users_controller.rb
9
+ Views: app/views/admin/users/index.html.erb [...]
10
+
@@ -0,0 +1,44 @@
1
+ module Fume
2
+
3
+ class SimpleScaffoldGenerator < Rails::Generators::NamedBase
4
+ include Rails::Generators::ResourceHelpers
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
8
+
9
+ def create_controller_files
10
+ template 'controller.rb', File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
11
+ end
12
+
13
+ def copy_view_files
14
+ %w(index new _form edit).each do |view|
15
+ filename = "#{view}.html.erb"
16
+ template filename, File.join("app/views", controller_file_path, filename)
17
+ end
18
+ end
19
+
20
+ protected
21
+ # model
22
+ def plural_model_name
23
+ singular_model_name.pluralize
24
+ end
25
+
26
+ def singular_model_name
27
+ model_class_name.underscore
28
+ end
29
+
30
+ def model_class_name
31
+ @model_class_name ||= file_name.camelize
32
+ end
33
+
34
+ # path
35
+ def resources_path_prefix
36
+ (class_path + [plural_model_name]).join('_')
37
+ end
38
+
39
+ def resource_path_prefix
40
+ (class_path + [singular_model_name]).join('_')
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,7 @@
1
+ <%%= f.inputs do %>
2
+ <%- for attribute in attributes -%>
3
+ <%%= f.input :<%= attribute.name %><%= ", :as => :#{attribute.type}" if %w[select radio].include?(attribute.type.to_s) %> %>
4
+ <%- end -%>
5
+ <%% end %>
6
+
7
+ <%%= f.buttons %>
@@ -0,0 +1,44 @@
1
+ class <%= controller_class_name %>Controller < ApplicationController
2
+
3
+ def index
4
+ @search = <%= "#{model_class_name}.search(params[:search])" %>
5
+ <%= "@#{plural_model_name}" %> = @search.page(params[:page])
6
+ end
7
+
8
+ def new
9
+ <%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.new" %>
10
+ end
11
+
12
+ def create
13
+ <%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.new(params[:#{singular_model_name}])" %>
14
+
15
+ if <%= "@#{singular_model_name}.save" %>
16
+ flash[:notice] = '<%= human_name %> was successfully created.'
17
+ redirect_to_ok_url_or_default :action => "index"
18
+ else
19
+ render :action => "new"
20
+ end
21
+ end
22
+
23
+ def edit
24
+ @<%= singular_model_name %> = <%= "#{model_class_name}.find(params[:id])" %>
25
+ end
26
+
27
+ def update
28
+ <%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.find(params[:id])" %>
29
+
30
+ if <%= "@#{singular_model_name}.update_attributes(params[:#{singular_model_name}])" %>
31
+ flash[:notice] = '<%= human_name %> was successfully updated.'
32
+ redirect_to_ok_url_or_default :action => "index"
33
+ else
34
+ render :action => "edit"
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ <%= "@#{singular_model_name}" %> = <%= "#{model_class_name}.find_by_id(params[:id])" %>
40
+ <%= "@#{singular_model_name}.destroy" %> if @<%= singular_model_name %>
41
+
42
+ redirect_to_ok_url_or_default :action => "index"
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ <h1>Editing <%%= <%= "#{model_class_name}.human_name" %> %></h1>
2
+
3
+ <%%= semantic_form_for(<%= "@#{singular_model_name}" %>, :url => <%= resource_path_prefix %>_path(<%= "@#{singular_model_name}" %>)) do |f| %>
4
+ <%%= render :partial => "form", :locals => { :f => f } %>
5
+ <%% end %>
@@ -0,0 +1,32 @@
1
+ <h1>Listing <%%= <%= "#{model_class_name}.human_name" %> %></h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th><%%= sort_link @search, :id %></th>
7
+ <%- for attribute in attributes -%>
8
+ <th><%%= sort_link @search, :<%= attribute.name %> %></th>
9
+ <%- end -%>
10
+ <th>Actions</th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <%% <%= "@#{plural_model_name}" %>.each do |<%= singular_model_name %>| %>
15
+ <tr>
16
+ <td><%%= <%= singular_model_name %>.id %></td>
17
+ <%- for attribute in attributes -%>
18
+ <td><%%=<%= "l" if %w[date datetime time].include?(attribute.type.to_s) %> <%= singular_model_name %>.<%= attribute.name %> %></td>
19
+ <%- end -%>
20
+ <td>
21
+ <%%= link_to 'Edit', edit_<%= resource_path_prefix %>_path(<%= singular_model_name %>) %>
22
+ <%%= link_to 'Destroy', <%= resource_path_prefix %>_path(<%= singular_model_name %>), :confirm => 'Are you sure?', :method => :delete %>
23
+ </td>
24
+ </tr>
25
+ <%% end %>
26
+ </table>
27
+
28
+ <%%= paginate <%= "@#{plural_model_name}" %> %>
29
+
30
+ <div class="actions">
31
+ <%%= link_to 'New <%= human_name %>', new_<%= resource_path_prefix %>_path %>
32
+ </div>
@@ -0,0 +1,5 @@
1
+ <h1>New <%%= <%= "#{model_class_name}.human_name" %> %></h1>
2
+
3
+ <%%= semantic_form_for(<%= "@#{singular_model_name}" %>, :url => <%= resources_path_prefix %>_path()) do |f| %>
4
+ <%%= render :partial => "form", :locals => { :f => f } %>
5
+ <%% end %>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fume
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.3
5
+ version: 0.6.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sunteya
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-29 00:00:00 +08:00
13
+ date: 2011-06-30 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -157,6 +157,13 @@ files:
157
157
  - lib/fume/rails_ext.rb
158
158
  - lib/fume/railtie.rb
159
159
  - lib/fume/simple_theme.rb
160
+ - lib/generators/fume/simple_scaffold/USAGE
161
+ - lib/generators/fume/simple_scaffold/simple_scaffold_generator.rb
162
+ - lib/generators/fume/simple_scaffold/templates/_form.html.erb
163
+ - lib/generators/fume/simple_scaffold/templates/controller.rb
164
+ - lib/generators/fume/simple_scaffold/templates/edit.html.erb
165
+ - lib/generators/fume/simple_scaffold/templates/index.html.erb
166
+ - lib/generators/fume/simple_scaffold/templates/new.html.erb
160
167
  - rails_generators/fume/fume_generator.rb
161
168
  - rails_generators/fume/rspec/rspec_gen.rb
162
169
  - rails_generators/fume/rspec/templates/spec/support/erb_macros.rb