dust-generators 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/lib/dust/version.rb +1 -1
  2. data/rails_generators/dust_scaffold/templates/actions/create.rb +1 -1
  3. data/rails_generators/dust_scaffold/templates/actions/destroy.rb +1 -1
  4. data/rails_generators/dust_scaffold/templates/actions/index.rb +1 -1
  5. data/rails_generators/dust_scaffold/templates/actions/update.rb +1 -1
  6. data/rails_generators/dust_scaffold/templates/controller.rb +7 -1
  7. data/rails_generators/dust_scaffold/templates/fixtures.yml +2 -2
  8. data/rails_generators/dust_scaffold/templates/migration.rb +4 -2
  9. data/rails_generators/dust_scaffold/templates/model.rb +35 -1
  10. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/create.rb +1 -1
  11. data/rails_generators/dust_scaffold/templates/tests/rspec/actions/update.rb +1 -1
  12. data/rails_generators/dust_scaffold/templates/tests/rspec/controller.rb +3 -3
  13. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/create.rb +1 -1
  14. data/rails_generators/dust_scaffold/templates/tests/shoulda/actions/update.rb +1 -1
  15. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/create.rb +1 -1
  16. data/rails_generators/dust_scaffold/templates/tests/testunit/actions/update.rb +1 -1
  17. data/rails_generators/dust_scaffold/templates/views/erb/_form.html.erb +12 -6
  18. data/rails_generators/dust_scaffold/templates/views/erb/_search.html.erb +6 -0
  19. data/rails_generators/dust_scaffold/templates/views/erb/edit.html.erb +2 -12
  20. data/rails_generators/dust_scaffold/templates/views/erb/index.html.erb +21 -26
  21. data/rails_generators/dust_scaffold/templates/views/erb/new.html.erb +1 -3
  22. data/rails_generators/dust_scaffold/templates/views/erb/show.html.erb +21 -18
  23. data/rails_generators/dust_scaffold/templates/views/haml/_form.html.haml +1 -1
  24. data/rails_generators/dust_scaffold/templates/views/haml/index.html.haml +4 -4
  25. data/rails_generators/dust_scaffold/templates/views/haml/show.html.haml +3 -3
  26. metadata +4 -3
data/lib/dust/version.rb CHANGED
@@ -2,7 +2,7 @@ class Dust
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 4
5
+ PATCH = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
@@ -1,7 +1,7 @@
1
1
  def create
2
2
  @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
3
3
  if @<%= singular_name %>.save
4
- flash[:notice] = "Successfully created <%= name.underscore.humanize.downcase %>."
4
+ flash[:notice] = "Successfully created <%= model_name.underscore.humanize.downcase %>."
5
5
  redirect_to <%= item_path('url') %>
6
6
  else
7
7
  render :action => 'new'
@@ -1,6 +1,6 @@
1
1
  def destroy
2
2
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
3
  @<%= singular_name %>.destroy
4
- flash[:notice] = "Successfully destroyed <%= name.underscore.humanize.downcase %>."
4
+ flash[:notice] = "Successfully destroyed <%= model_name.underscore.humanize.downcase %>."
5
5
  redirect_to <%= items_path('url') %>
6
6
  end
@@ -1,3 +1,3 @@
1
1
  def index
2
- @<%= plural_name %> = <%= class_name %>.all
2
+ @<%= plural_name %> = <%= class_name %>.page(params[:search], params[:page])
3
3
  end
@@ -1,7 +1,7 @@
1
1
  def update
2
2
  @<%= singular_name %> = <%= class_name %>.find(params[:id])
3
3
  if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
4
- flash[:notice] = "Successfully updated <%= name.underscore.humanize.downcase %>."
4
+ flash[:notice] = "Successfully updated <%= model_name.underscore.humanize.downcase %>."
5
5
  redirect_to <%= item_path('url') %>
6
6
  else
7
7
  render :action => 'edit'
@@ -1,3 +1,9 @@
1
1
  class <%= plural_class_name %>Controller < ApplicationController
2
- <%= controller_methods :actions %>
2
+
3
+ filter_resource_access
4
+
5
+ layout 'cms'
6
+
7
+ <%= controller_methods :actions %>
8
+
3
9
  end
@@ -1,9 +1,9 @@
1
1
  one:
2
- <%- for attribute in attributes -%>
2
+ <%- for attribute in model_attributes -%>
3
3
  <%= attribute.name %>: <%= attribute.default %>
4
4
  <%- end -%>
5
5
 
6
6
  two:
7
- <%- for attribute in attributes -%>
7
+ <%- for attribute in model_attributes -%>
8
8
  <%= attribute.name %>: <%= attribute.default %>
9
9
  <%- end -%>
@@ -1,7 +1,7 @@
1
1
  class Create<%= plural_class_name %> < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :<%= plural_name %> do |t|
4
- <%- for attribute in attributes -%>
4
+ <%- for attribute in model_attributes -%>
5
5
  t.<%= attribute.type %> :<%= attribute.name %>
6
6
  <%- end -%>
7
7
  <%- unless options[:skip_timestamps] -%>
@@ -9,7 +9,9 @@ class Create<%= plural_class_name %> < ActiveRecord::Migration
9
9
  <%- end -%>
10
10
  end
11
11
  end
12
-
12
+
13
+ CmsMenuItem.create({:title =>"<%= plural_class_name %>", :controller_name => "<%= plural_name %>", :url => "/<%= plural_name %>"})
14
+
13
15
  def self.down
14
16
  drop_table :<%= plural_name %>
15
17
  end
@@ -1,3 +1,37 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
- attr_accessible <%= attributes.map { |a| ":#{a.name}" }.join(", ") %>
2
+ attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
+
4
+ <%- first_attribute = model_attributes.first -%>
5
+ def self.page(search, page)
6
+ paginate :per_page => 10, :page => page,
7
+ :order => 'name',
8
+ :conditions => ["<%= first_attribute.name %> LIKE ? OR content LIKE ?", "%#{search}%", "%#{search}%"]
9
+ end
10
+
11
+ has_one :menu_item, :as => :linkable, :dependent => :destroy
12
+
13
+ after_create :create_menu_item
14
+ after_update :update_menu_item
15
+
16
+ def update_menu_item
17
+ @menu_item = self.menu_item
18
+ if @menu_item == nil
19
+ self.create_menu_item
20
+ else
21
+ @menu_item.update_attributes(
22
+ :title => self.<%= first_attribute.name %>,
23
+ :url => "/#{self.<%= first_attribute.name %>}",
24
+ :active => self.<%= first_attribute.name %>
25
+ )
26
+ end
27
+ end
28
+
29
+ def create_menu_item
30
+ @menu_item = self.build_menu_item(
31
+ :title => self.<%= first_attribute.name %>,
32
+ :url => "/#{<%= first_attribute.name %>}",
33
+ :active => self.<%= first_attribute.name %>
34
+ )
35
+ @menu_item.save
36
+ end
3
37
  end
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  response.should render_template(:new)
5
5
  end
6
-
6
+
7
7
  it "create action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  response.should render_template(:edit)
5
5
  end
6
-
6
+
7
7
  it "update action should redirect when model is valid" do
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -1,8 +1,8 @@
1
1
  require File.dirname(__FILE__) + '/../spec_helper'
2
-
2
+
3
3
  describe <%= plural_class_name %>Controller do
4
4
  fixtures :all
5
- integrate_views
6
-
5
+ render_views
6
+
7
7
  <%= controller_methods 'tests/rspec/actions' %>
8
8
  end
@@ -4,7 +4,7 @@
4
4
  post :create
5
5
  assert_template 'new'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  post :create
@@ -4,7 +4,7 @@
4
4
  put :update, :id => <%= class_name %>.first
5
5
  assert_template 'edit'
6
6
  end
7
-
7
+
8
8
  should "redirect when model is valid" do
9
9
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
10
  put :update, :id => <%= class_name %>.first
@@ -3,7 +3,7 @@
3
3
  post :create
4
4
  assert_template 'new'
5
5
  end
6
-
6
+
7
7
  def test_create_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  post :create
@@ -3,7 +3,7 @@
3
3
  put :update, :id => <%= class_name %>.first
4
4
  assert_template 'edit'
5
5
  end
6
-
6
+
7
7
  def test_update_valid
8
8
  <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
9
  put :update, :id => <%= class_name %>.first
@@ -1,10 +1,16 @@
1
- <%% form_for @<%= singular_name %> do |f| %>
1
+ <%%= content_for :head do -%>
2
+ <%%= javascript_include_tag :ckeditor %>
3
+ <%% end -%>
4
+
5
+ <%%= form_for @<%= singular_name %>, :validations => true do |f| %>
2
6
  <%%= f.error_messages %>
3
- <%- for attribute in attributes -%>
4
- <p>
7
+ <%- for attribute in model_attributes -%>
8
+ <div class="item">
5
9
  <%%= f.label :<%= attribute.name %> %><br />
6
- <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
7
- </p>
10
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => 'field' %>
11
+ </div>
8
12
  <%- end -%>
9
- <p><%%= f.submit %></p>
13
+ <div class="item">
14
+ <p><%%= f.submit %></p>
15
+ </div>
10
16
  <%% end %>
@@ -0,0 +1,6 @@
1
+ <div id="searchbox">
2
+ <%%= form_tag <%= plural_name %>_path, :method => 'get' do %>
3
+ <%%= text_field_tag :search, params[:search], :class => "input-text", :placeholder => 'Search <%= plural_name.capitalize %>' %>
4
+ <%%= image_submit_tag "admin/blank.png", :class => "image-submit"%>
5
+ <%% end %>
6
+ </div>
@@ -1,14 +1,4 @@
1
1
  <%% title "Edit <%= singular_name.titleize %>" %>
2
+ <%% heading "Edit <%= singular_name.titleize %>" %>
2
3
 
3
- <%= render_form %>
4
-
5
- <%- if actions? :show, :index -%>
6
- <p>
7
- <%- if action? :show -%>
8
- <%%= link_to "Show", @<%= singular_name %> %> |
9
- <%- end -%>
10
- <%- if action? :index -%>
11
- <%%= link_to "View All", <%= plural_name %>_path %>
12
- <%- end -%>
13
- </p>
14
- <%- end -%>
4
+ <%= render_form %>
@@ -1,29 +1,24 @@
1
1
  <%% title "<%= plural_name.titleize %>" %>
2
+ <%- first_attribute = model_attributes.first -%>
3
+ <div class="button_bar">
4
+ <%%= render :partial => 'search' %>
5
+ <%%= link_to 'new page', new_<%= singular_name %>_path, :class => 'newfile tip', :title => "New <%= singular_name.titleize %>" %>
6
+ </div>
2
7
 
3
- <table>
4
- <tr>
5
- <%- for attribute in attributes -%>
6
- <th><%= attribute.column.human_name.titleize %></th>
7
- <%- end -%>
8
- </tr>
9
- <%% for <%= singular_name %> in @<%= plural_name %> %>
10
- <tr>
11
- <%- for attribute in attributes -%>
12
- <td><%%=h <%= singular_name %>.<%= attribute.name %> %></td>
13
- <%- end -%>
14
- <%- if action? :show -%>
15
- <td><%%= link_to "Show", <%= singular_name %> %></td>
16
- <%- end -%>
17
- <%- if action? :edit -%>
18
- <td><%%= link_to "Edit", edit_<%= singular_name %>_path(<%= singular_name %>) %></td>
19
- <%- end -%>
20
- <%- if action? :destroy -%>
21
- <td><%%= link_to "Destroy", <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
22
- <%- end -%>
23
- </tr>
24
- <%% end %>
25
- </table>
8
+ <%%= will_paginate @<%= plural_name %> %>
26
9
 
27
- <%- if action? :new -%>
28
- <p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
29
- <%- end -%>
10
+ <%% @<%= plural_name %>.each do |<%= singular_name %>| %>
11
+ <div class="item">
12
+ <div style='float:right'>
13
+ <%%= link_to '', edit_<%= singular_name %>_path(<%= singular_name %>), :class => 'edit tip', :title => "Edit This Item" %>
14
+ <%%= link_to '', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'destroy tip', :title => "Destroy This Item" %>
15
+ </div>
16
+
17
+ <h3><%%= link_to <%= singular_name %>.<%= first_attribute.name %>, <%= singular_name %> %></h3>
18
+ <p>
19
+ <%%= link_to "Preview <%= singular_name.titleize %>", <%= singular_name %>, :class => 'remote_iframe' %>
20
+ </p>
21
+ </div>
22
+ <%% end -%>
23
+
24
+ <%%= will_paginate @<%= plural_name %> %>
@@ -1,7 +1,5 @@
1
1
  <%% title "New <%= singular_name.titleize %>" %>
2
+ <%% heading "New <%= singular_name.titleize %>" %>
2
3
 
3
4
  <%= render_form %>
4
5
 
5
- <%- if action? :index -%>
6
- <p><%%= link_to "Back to List", <%= plural_name %>_path %></p>
7
- <%- end -%>
@@ -1,20 +1,23 @@
1
1
  <%% title "<%= singular_name.titleize %>" %>
2
+ <%- first_attribute = model_attributes.first -%>
2
3
 
3
- <%- for attribute in attributes -%>
4
- <p>
5
- <strong><%= attribute.column.human_name.titleize %>:</strong>
6
- <%%=h @<%= singular_name %>.<%= attribute.name %> %>
7
- </p>
8
- <%- end -%>
9
-
10
- <p>
11
- <%- if action? :edit -%>
12
- <%%= link_to "Edit", edit_<%= singular_name %>_path(@<%= singular_name %>) %> |
13
- <%- end -%>
14
- <%- if action? :destroy -%>
15
- <%%= link_to "Destroy", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete %> |
16
- <%- end -%>
17
- <%- if action? :index -%>
18
- <%%= link_to "View All", <%= plural_name %>_path %>
19
- <%- end -%>
20
- </p>
4
+ <div class="item">
5
+ <div style='float:right'>
6
+ <%- if action? :edit -%>
7
+ <%%=link_to '', edit_<%= singular_name %>_path(@<%= singular_name %>), :class => 'edit tip', :title => "Edit This Item" %>
8
+ <%- end -%>
9
+ <%- if action? :destroy -%>
10
+ <%%=link_to "", @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'destroy tip', :title => "Destroy This Item" %>
11
+ <%- end -%>
12
+ </div>
13
+ <h3><%%= link_to @<%= singular_name %>.<%= first_attribute.name %>, @<%= singular_name %> %></h3>
14
+ <p>
15
+ <%%= link_to "Preview <%= singular_name.titleize %>", @<%= singular_name %>, :class => 'remote_iframe' %>
16
+ </p>
17
+ <%- for attribute in model_attributes -%>
18
+ <p>
19
+ <strong><%= attribute.human_name.titleize %>:</strong>
20
+ <%%= @<%= singular_name %>.<%= attribute.name %> %>
21
+ </p>
22
+ <%- end -%>
23
+ </div>
@@ -1,6 +1,6 @@
1
1
  - form_for @<%= singular_name %> do |f|
2
2
  = f.error_messages
3
- <%- for attribute in attributes -%>
3
+ <%- for attribute in model_attributes -%>
4
4
  %p
5
5
  = f.label :<%= attribute.name %>
6
6
  %br
@@ -2,13 +2,13 @@
2
2
 
3
3
  %table
4
4
  %tr
5
- <%- for attribute in attributes -%>
6
- %th <%= attribute.column.human_name %>
5
+ <%- for attribute in model_attributes -%>
6
+ %th <%= attribute.human_name %>
7
7
  <%- end -%>
8
8
  - for <%= singular_name %> in @<%= plural_name %>
9
9
  %tr
10
- <%- for attribute in attributes -%>
11
- %td= h <%= singular_name %>.<%= attribute.name %>
10
+ <%- for attribute in model_attributes -%>
11
+ %td= <%= singular_name %>.<%= attribute.name %>
12
12
  <%- end -%>
13
13
  <%- if action? :show -%>
14
14
  %td= link_to 'Show', <%= singular_name %>
@@ -1,9 +1,9 @@
1
1
  - title "<%= singular_name.titleize %>"
2
2
 
3
- <%- for attribute in attributes -%>
3
+ <%- for attribute in model_attributes -%>
4
4
  %p
5
- %strong <%= attribute.column.human_name.titleize %>:
6
- =h @<%= singular_name %>.<%= attribute.name %>
5
+ %strong <%= attribute.human_name.titleize %>:
6
+ = @<%= singular_name %>.<%= attribute.name %>
7
7
  <%- end -%>
8
8
 
9
9
  %p
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dust-generators
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - rossnelson
@@ -283,6 +283,7 @@ files:
283
283
  - rails_generators/dust_scaffold/templates/tests/testunit/controller.rb
284
284
  - rails_generators/dust_scaffold/templates/tests/testunit/model.rb
285
285
  - rails_generators/dust_scaffold/templates/views/erb/_form.html.erb
286
+ - rails_generators/dust_scaffold/templates/views/erb/_search.html.erb
286
287
  - rails_generators/dust_scaffold/templates/views/erb/edit.html.erb
287
288
  - rails_generators/dust_scaffold/templates/views/erb/index.html.erb
288
289
  - rails_generators/dust_scaffold/templates/views/erb/new.html.erb