dust-generators 0.0.1 → 0.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 (49) hide show
  1. data/Rakefile +10 -11
  2. data/lib/dust/version.rb +9 -0
  3. data/lib/generators/dust/config/config_generator.rb +1 -1
  4. data/lib/generators/dust/scaffold/scaffold_generator.rb +3 -1
  5. data/lib/generators/dust/scaffold/templates/actions/index.rb +1 -1
  6. data/lib/generators/dust/scaffold/templates/model.rb +12 -0
  7. data/lib/generators/dust/scaffold/templates/views/erb/_form.html.erb +10 -4
  8. data/lib/generators/dust/scaffold/templates/views/erb/_search.html.erb +6 -0
  9. data/lib/generators/dust/scaffold/templates/views/erb/edit.html.erb +2 -12
  10. data/lib/generators/dust/scaffold/templates/views/erb/index.html.erb +21 -26
  11. data/lib/generators/dust/scaffold/templates/views/erb/new.html.erb +1 -3
  12. data/lib/generators/dust/scaffold/templates/views/erb/show.html.erb +20 -18
  13. metadata +6 -40
  14. data/lib/generators/dust/authentication/USAGE +0 -50
  15. data/lib/generators/dust/authentication/authentication_generator.rb +0 -154
  16. data/lib/generators/dust/authentication/templates/authlogic_session.rb +0 -2
  17. data/lib/generators/dust/authentication/templates/controller_authentication.rb +0 -61
  18. data/lib/generators/dust/authentication/templates/fixtures.yml +0 -24
  19. data/lib/generators/dust/authentication/templates/migration.rb +0 -20
  20. data/lib/generators/dust/authentication/templates/sessions_controller.rb +0 -45
  21. data/lib/generators/dust/authentication/templates/sessions_helper.rb +0 -2
  22. data/lib/generators/dust/authentication/templates/tests/rspec/sessions_controller.rb +0 -39
  23. data/lib/generators/dust/authentication/templates/tests/rspec/user.rb +0 -83
  24. data/lib/generators/dust/authentication/templates/tests/rspec/users_controller.rb +0 -56
  25. data/lib/generators/dust/authentication/templates/tests/shoulda/sessions_controller.rb +0 -40
  26. data/lib/generators/dust/authentication/templates/tests/shoulda/user.rb +0 -85
  27. data/lib/generators/dust/authentication/templates/tests/shoulda/users_controller.rb +0 -61
  28. data/lib/generators/dust/authentication/templates/tests/testunit/sessions_controller.rb +0 -36
  29. data/lib/generators/dust/authentication/templates/tests/testunit/user.rb +0 -88
  30. data/lib/generators/dust/authentication/templates/tests/testunit/users_controller.rb +0 -53
  31. data/lib/generators/dust/authentication/templates/user.rb +0 -42
  32. data/lib/generators/dust/authentication/templates/users_controller.rb +0 -34
  33. data/lib/generators/dust/authentication/templates/users_helper.rb +0 -2
  34. data/lib/generators/dust/authentication/templates/views/erb/_form.html.erb +0 -20
  35. data/lib/generators/dust/authentication/templates/views/erb/edit.html.erb +0 -3
  36. data/lib/generators/dust/authentication/templates/views/erb/login.html.erb +0 -30
  37. data/lib/generators/dust/authentication/templates/views/erb/signup.html.erb +0 -5
  38. data/lib/generators/dust/authentication/templates/views/haml/_form.html.haml +0 -20
  39. data/lib/generators/dust/authentication/templates/views/haml/edit.html.haml +0 -3
  40. data/lib/generators/dust/authentication/templates/views/haml/login.html.haml +0 -30
  41. data/lib/generators/dust/authentication/templates/views/haml/signup.html.haml +0 -5
  42. data/lib/generators/dust/layout/USAGE +0 -25
  43. data/lib/generators/dust/layout/layout_generator.rb +0 -29
  44. data/lib/generators/dust/layout/templates/error_messages_helper.rb +0 -23
  45. data/lib/generators/dust/layout/templates/layout.html.erb +0 -19
  46. data/lib/generators/dust/layout/templates/layout.html.haml +0 -21
  47. data/lib/generators/dust/layout/templates/layout_helper.rb +0 -22
  48. data/lib/generators/dust/layout/templates/stylesheet.css +0 -75
  49. data/lib/generators/dust/layout/templates/stylesheet.sass +0 -66
data/Rakefile CHANGED
@@ -1,19 +1,21 @@
1
1
  require 'rubygems'
2
2
  require 'bundler'
3
+ require './lib/dust/version.rb'
4
+
3
5
  begin
4
6
  Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
9
11
  end
10
- require 'rake'
11
12
 
13
+ require 'rake'
12
14
  require 'jeweler'
15
+
13
16
  Jeweler::Tasks.new do |gem|
14
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
17
  gem.name = "dust-generators"
16
- gem.version = "0.0.1"
18
+ gem.version = Dust::Version::STRING
17
19
  gem.homepage = "http://github.com/rossnelson/dust-generators"
18
20
  gem.license = "MIT"
19
21
  gem.summary = %Q{Generators for DustCMS}
@@ -21,11 +23,8 @@ Jeweler::Tasks.new do |gem|
21
23
  gem.email = "axcess1@me.com"
22
24
  gem.authors = ["rossnelson"]
23
25
  gem.files = FileList["[A-Z]*", "{lib}/**/*"]
24
- # Include your dependencies below. Runtime dependencies are required when using your gem,
25
- # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
26
- # gem.add_runtime_dependency 'jabber4r', '> 0.1'
27
- # gem.add_development_dependency 'rspec', '> 1.2.3'
28
26
  end
27
+
29
28
  Jeweler::RubygemsDotOrgTasks.new
30
29
 
31
30
  require 'rake/testtask'
@@ -0,0 +1,9 @@
1
+ class Dust
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 2
6
+
7
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
@@ -1,6 +1,6 @@
1
1
  require 'generators/dust'
2
2
 
3
- module dust
3
+ module Dust
4
4
  module Generators
5
5
  class ConfigGenerator < Base
6
6
  argument :config_name, :type => :string, :default => 'app', :banner => 'config_name'
@@ -95,7 +95,9 @@ module Dust
95
95
  template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
96
96
  end
97
97
  end
98
-
98
+
99
+ template "views/#{view_language}/_search.html.erb", "app/views/#{plural_name}/_search.html.erb"
100
+
99
101
  if form_partial?
100
102
  template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
101
103
  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,3 +1,15 @@
1
1
  class <%= class_name %> < ActiveRecord::Base
2
2
  attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
3
+
4
+ def self.page(search, page)
5
+ with_permissions_to(:manage).search(search).order("<%= model_attributes.first %>").paginate(:per_page => 12, :page => page)
6
+ end
7
+
8
+ def self.search(search)
9
+ if search
10
+ where("<%= model_attributes.first %> LIKE ?", "%#{search}%")
11
+ else
12
+ scoped
13
+ end
14
+ end
3
15
  end
@@ -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
7
  <%- for attribute in model_attributes -%>
4
- <p>
8
+ <div class="item">
5
9
  <%%= f.label :<%= attribute.name %> %><br />
6
10
  <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
7
- </p>
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 <%= singular_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
2
 
3
- <table>
4
- <tr>
5
- <%- for attribute in model_attributes -%>
6
- <th><%= attribute.human_name.titleize %></th>
7
- <%- end -%>
8
- </tr>
9
- <%% for <%= singular_name %> in @<%= plural_name %> %>
10
- <tr>
11
- <%- for attribute in model_attributes -%>
12
- <td><%%= <%= 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>
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.capitalize %>")%>
6
+ </div>
26
7
 
27
- <%- if action? :new -%>
28
- <p><%%= link_to "New <%= singular_name.titleize %>", new_<%= singular_name %>_path %></p>
29
- <%- end -%>
8
+ <%%= will_paginate @<%= plural_name %> %>
9
+
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 %>.<%= model_attributes.first %>, <%= singular_name %> %></h3>
18
+ <p>
19
+ <%%= link_to "Preview <%= singular_name.capitalize %>", <%= 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,22 @@
1
1
  <%% title "<%= singular_name.titleize %>" %>
2
2
 
3
- <%- for attribute in model_attributes -%>
4
- <p>
5
- <strong><%= attribute.human_name.titleize %>:</strong>
6
- <%%= @<%= 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>
3
+ <div class="item">
4
+ <div style='float:right'>
5
+ <%- if action? :edit -%>
6
+ <%%=link_to '', edit_<%= singular_name %>_path(<%= singular_name %>), :class => 'edit tip', :title => "Edit This Item" %>
7
+ <%- end -%>
8
+ <%- if action? :destroy -%>
9
+ <%%=link_to "", <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete, :class => 'destroy tip', :title => "Destroy This Item" %>
10
+ <%- end -%>
11
+ </div>
12
+ <h3><%%= link_to <%= singular_name %>.<%= model_attributes.first %>, <%= singular_name %>.menu_item.url %></h3>
13
+ <p>
14
+ <%%= link_to "Preview <%= singular_name.titleize %>", <%= singular_name %>.filename, :class => 'remote_iframe' %>
15
+ </p>
16
+ <%- for attribute in model_attributes -%>
17
+ <p>
18
+ <strong><%= attribute.human_name.titleize %>:</strong>
19
+ <%%= @<%= singular_name %>.<%= attribute.name %> %>
20
+ </p>
21
+ <%- end -%>
22
+ </div>
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - rossnelson
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-22 00:00:00 -06:00
17
+ date: 2011-02-25 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -101,47 +101,12 @@ files:
101
101
  - LICENSE.txt
102
102
  - README.rdoc
103
103
  - Rakefile
104
+ - lib/dust/version.rb
104
105
  - lib/generators/dust.rb
105
- - lib/generators/dust/authentication/USAGE
106
- - lib/generators/dust/authentication/authentication_generator.rb
107
- - lib/generators/dust/authentication/templates/authlogic_session.rb
108
- - lib/generators/dust/authentication/templates/controller_authentication.rb
109
- - lib/generators/dust/authentication/templates/fixtures.yml
110
- - lib/generators/dust/authentication/templates/migration.rb
111
- - lib/generators/dust/authentication/templates/sessions_controller.rb
112
- - lib/generators/dust/authentication/templates/sessions_helper.rb
113
- - lib/generators/dust/authentication/templates/tests/rspec/sessions_controller.rb
114
- - lib/generators/dust/authentication/templates/tests/rspec/user.rb
115
- - lib/generators/dust/authentication/templates/tests/rspec/users_controller.rb
116
- - lib/generators/dust/authentication/templates/tests/shoulda/sessions_controller.rb
117
- - lib/generators/dust/authentication/templates/tests/shoulda/user.rb
118
- - lib/generators/dust/authentication/templates/tests/shoulda/users_controller.rb
119
- - lib/generators/dust/authentication/templates/tests/testunit/sessions_controller.rb
120
- - lib/generators/dust/authentication/templates/tests/testunit/user.rb
121
- - lib/generators/dust/authentication/templates/tests/testunit/users_controller.rb
122
- - lib/generators/dust/authentication/templates/user.rb
123
- - lib/generators/dust/authentication/templates/users_controller.rb
124
- - lib/generators/dust/authentication/templates/users_helper.rb
125
- - lib/generators/dust/authentication/templates/views/erb/_form.html.erb
126
- - lib/generators/dust/authentication/templates/views/erb/edit.html.erb
127
- - lib/generators/dust/authentication/templates/views/erb/login.html.erb
128
- - lib/generators/dust/authentication/templates/views/erb/signup.html.erb
129
- - lib/generators/dust/authentication/templates/views/haml/_form.html.haml
130
- - lib/generators/dust/authentication/templates/views/haml/edit.html.haml
131
- - lib/generators/dust/authentication/templates/views/haml/login.html.haml
132
- - lib/generators/dust/authentication/templates/views/haml/signup.html.haml
133
106
  - lib/generators/dust/config/USAGE
134
107
  - lib/generators/dust/config/config_generator.rb
135
108
  - lib/generators/dust/config/templates/config.yml
136
109
  - lib/generators/dust/config/templates/load_config.rb
137
- - lib/generators/dust/layout/USAGE
138
- - lib/generators/dust/layout/layout_generator.rb
139
- - lib/generators/dust/layout/templates/error_messages_helper.rb
140
- - lib/generators/dust/layout/templates/layout.html.erb
141
- - lib/generators/dust/layout/templates/layout.html.haml
142
- - lib/generators/dust/layout/templates/layout_helper.rb
143
- - lib/generators/dust/layout/templates/stylesheet.css
144
- - lib/generators/dust/layout/templates/stylesheet.sass
145
110
  - lib/generators/dust/scaffold/USAGE
146
111
  - lib/generators/dust/scaffold/scaffold_generator.rb
147
112
  - lib/generators/dust/scaffold/templates/actions/create.rb
@@ -184,6 +149,7 @@ files:
184
149
  - lib/generators/dust/scaffold/templates/tests/testunit/controller.rb
185
150
  - lib/generators/dust/scaffold/templates/tests/testunit/model.rb
186
151
  - lib/generators/dust/scaffold/templates/views/erb/_form.html.erb
152
+ - lib/generators/dust/scaffold/templates/views/erb/_search.html.erb
187
153
  - lib/generators/dust/scaffold/templates/views/erb/edit.html.erb
188
154
  - lib/generators/dust/scaffold/templates/views/erb/index.html.erb
189
155
  - lib/generators/dust/scaffold/templates/views/erb/new.html.erb
@@ -209,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
175
  requirements:
210
176
  - - ">="
211
177
  - !ruby/object:Gem::Version
212
- hash: 3323453795700847522
178
+ hash: 4195696695767586530
213
179
  segments:
214
180
  - 0
215
181
  version: "0"
@@ -1,50 +0,0 @@
1
- Description:
2
- Generates a user model, users controller, and sessions controller. The
3
- users controller handles the registration and the sessions controller
4
- handles authentication. This is similar to restful_authentication, but
5
- simpler.
6
-
7
- IMPORTANT: This generator uses the "title" helper method which is generated
8
- by the dust_layout generator. You may want to run that generator first.
9
-
10
- Usage:
11
- If you do not pass any arguments, the model name will default to "user", and
12
- the authentication controller will default to "session". You can override
13
- each of these respectively by passing one or two arguments. Either name can
14
- be CamelCased or under_scored.
15
-
16
- Make sure to setup the authlogic gem if you are using that option.
17
-
18
- gem "authlogic" # in Gemfile
19
-
20
- Examples:
21
- rails generate dust:authentication
22
-
23
- Creates user model, users_controller, and sessions_controller.
24
-
25
- rails generate dust:authentication account
26
-
27
- Creates account model, accounts_controller, and sessions_controller.
28
-
29
- rails generate dust:authentication Account UserSession
30
-
31
- Creates account model, accounts_controller, and user_sessions_controller.
32
-
33
- Methods:
34
- There are several methods generated which you can use in your application.
35
- Here's a common example of what you might add to your layout.
36
-
37
- <% if logged_in? %>
38
- Welcome <%= current_user.username %>! Not you?
39
- <%= link_to "Log out", logout_path %>
40
- <% else %>
41
- <%= link_to "Sign up", signup_path %> or
42
- <%= link_to "log in", login_path %>.
43
- <% end %>
44
-
45
- You can also restrict unregistered users from accessing a controller using
46
- a before filter. For example.
47
-
48
- before_filter :login_required, :except => [:index, :show]
49
-
50
- See the generated file lib/authentication.rb for details.
@@ -1,154 +0,0 @@
1
- require 'generators/dust'
2
- require 'rails/generators/migration'
3
-
4
- module dust
5
- module Generators
6
- class AuthenticationGenerator < Base
7
- include Rails::Generators::Migration
8
-
9
- argument :user_name, :type => :string, :default => 'user', :banner => 'user_name'
10
- argument :session_name, :type => :string, :default => '[[DEFAULT]]', :banner => 'sessions_controller_name'
11
-
12
- class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
13
- class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
14
- class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
15
-
16
- class_option :haml, :desc => 'Generate HAML views instead of ERB.', :type => :boolean
17
- class_option :authlogic, :desc => 'Use Authlogic for authentication.', :type => :boolean
18
-
19
- def add_gems
20
- gem "bcrypt-ruby", :require => "bcrypt" unless File.read(destination_path("Gemfile")).include? "bcrypt"
21
- gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
22
- end
23
-
24
- def create_model_files
25
- template 'user.rb', "app/models/#{user_singular_name}.rb"
26
- template 'authlogic_session.rb', "app/models/#{user_singular_name}_session.rb" if options.authlogic?
27
- end
28
-
29
- def create_controller_files
30
- template 'users_controller.rb', "app/controllers/#{user_plural_name}_controller.rb"
31
- template 'sessions_controller.rb', "app/controllers/#{session_plural_name}_controller.rb"
32
- end
33
-
34
- def create_helper_files
35
- template 'users_helper.rb', "app/helpers/#{user_plural_name}_helper.rb"
36
- template 'sessions_helper.rb', "app/helpers/#{session_plural_name}_helper.rb"
37
- end
38
-
39
- def create_view_files
40
- template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
41
- template "views/#{view_language}/edit.html.#{view_language}", "app/views/#{user_plural_name}/edit.html.#{view_language}"
42
- template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{user_plural_name}/_form.html.#{view_language}"
43
- template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
44
- end
45
-
46
- def create_lib_files
47
- template 'controller_authentication.rb', 'lib/controller_authentication.rb'
48
- end
49
-
50
- def create_routes
51
- route "resources #{user_plural_name.to_sym.inspect}"
52
- route "resources #{session_plural_name.to_sym.inspect}"
53
- route "match 'login' => '#{session_plural_name}#new', :as => :login"
54
- route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
55
- route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
56
- route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_#{user_singular_name}"
57
- end
58
-
59
- def create_migration
60
- migration_template 'migration.rb', "db/migrate/create_#{user_plural_name}.rb"
61
- end
62
-
63
- def load_and_include_authentication
64
- inject_into_class "config/application.rb", "Application", " config.autoload_paths << \"\#{config.root}/lib\""
65
- inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " include ControllerAuthentication\n"
66
- end
67
-
68
- def create_test_files
69
- if test_framework == :rspec
70
- template 'fixtures.yml', "spec/fixtures/#{user_plural_name}.yml"
71
- template 'tests/rspec/user.rb', "spec/models/#{user_singular_name}_spec.rb"
72
- template 'tests/rspec/users_controller.rb', "spec/controllers/#{user_plural_name}_controller_spec.rb"
73
- template 'tests/rspec/sessions_controller.rb', "spec/controllers/#{session_plural_name}_controller_spec.rb"
74
- else
75
- template 'fixtures.yml', "test/fixtures/#{user_plural_name}.yml"
76
- template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
77
- template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
78
- template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
79
- end
80
- end
81
-
82
- private
83
-
84
- def session_name
85
- @_session_name ||= @session_name == '[[DEFAULT]]' ?
86
- (options.authlogic? ? user_name + '_session' : 'session') :
87
- @session_name
88
- end
89
-
90
- def user_singular_name
91
- user_name.underscore
92
- end
93
-
94
- def user_plural_name
95
- user_singular_name.pluralize
96
- end
97
-
98
- def user_class_name
99
- user_name.camelize
100
- end
101
-
102
- def user_plural_class_name
103
- user_plural_name.camelize
104
- end
105
-
106
- def session_singular_name
107
- session_name.underscore
108
- end
109
-
110
- def session_plural_name
111
- session_singular_name.pluralize
112
- end
113
-
114
- def session_class_name
115
- session_name.camelize
116
- end
117
-
118
- def session_plural_class_name
119
- session_plural_name.camelize
120
- end
121
-
122
- def view_language
123
- options.haml? ? 'haml' : 'erb'
124
- end
125
-
126
- def test_framework
127
- return @test_framework if defined?(@test_framework)
128
- if options.testunit?
129
- return @test_framework = :testunit
130
- elsif options.rspec?
131
- return @test_framework = :rspec
132
- elsif options.shoulda?
133
- return @test_framework = :shoulda
134
- else
135
- return @test_framework = File.exist?(destination_path('spec')) ? :rspec : :testunit
136
- end
137
- end
138
-
139
- def destination_path(path)
140
- File.join(destination_root, path)
141
- end
142
-
143
- # FIXME: Should be proxied to ActiveRecord::Generators::Base
144
- # Implement the required interface for Rails::Generators::Migration.
145
- def self.next_migration_number(dirname) #:nodoc:
146
- if ActiveRecord::Base.timestamped_migrations
147
- Time.now.utc.strftime("%Y%m%d%H%M%S")
148
- else
149
- "%.3d" % (current_migration_number(dirname) + 1)
150
- end
151
- end
152
- end
153
- end
154
- end
@@ -1,2 +0,0 @@
1
- class <%= session_class_name %> < Authlogic::Session::Base
2
- end
@@ -1,61 +0,0 @@
1
- # This module is included in your application controller which makes
2
- # several methods available to all controllers and views. Here's a
3
- # common example you might add to your application layout file.
4
- #
5
- # <%% if logged_in? %>
6
- # Welcome <%%= current_<%= user_singular_name %>.username %>.
7
- # <%%= link_to "Edit profile", edit_<%= user_singular_name %>_path %> or
8
- # <%%= link_to "Log out", logout_path %>
9
- # <%% else %>
10
- # <%%= link_to "Sign up", signup_path %> or
11
- # <%%= link_to "log in", login_path %>.
12
- # <%% end %>
13
- #
14
- # You can also restrict unregistered users from accessing a controller using
15
- # a before filter. For example.
16
- #
17
- # before_filter :login_required, :except => [:index, :show]
18
- module ControllerAuthentication
19
- def self.included(controller)
20
- controller.send :helper_method, :current_<%= user_singular_name %>, :logged_in?, :redirect_to_target_or_default
21
- end
22
-
23
- <%- if options[:authlogic] -%>
24
- def current_<%= session_singular_name %>
25
- return @current_<%= session_singular_name %> if defined?(@current_<%= session_singular_name %>)
26
- @current_<%= session_singular_name %> = <%= session_class_name %>.find
27
- end
28
-
29
- def current_<%= user_singular_name %>
30
- return @current_<%= user_singular_name %> if defined?(@current_<%= user_singular_name %>)
31
- @current_<%= user_singular_name %> = current_<%= session_singular_name %> && current_<%= session_singular_name %>.record
32
- end
33
- <%- else -%>
34
- def current_<%= user_singular_name %>
35
- @current_<%= user_singular_name %> ||= <%= user_class_name %>.find(session[:<%= user_singular_name %>_id]) if session[:<%= user_singular_name %>_id]
36
- end
37
- <%- end -%>
38
-
39
- def logged_in?
40
- current_<%= user_singular_name %>
41
- end
42
-
43
- def login_required
44
- unless logged_in?
45
- flash[:error] = "You must first log in or sign up before accessing this page."
46
- store_target_location
47
- redirect_to login_url
48
- end
49
- end
50
-
51
- def redirect_to_target_or_default(default)
52
- redirect_to(session[:return_to] || default)
53
- session[:return_to] = nil
54
- end
55
-
56
- private
57
-
58
- def store_target_location
59
- session[:return_to] = request.url
60
- end
61
- end
@@ -1,24 +0,0 @@
1
- # password: "secret"
2
- foo:
3
- username: foo
4
- email: foo@example.com
5
- <%- if options[:authlogic] -%>
6
- persistence_token: d5ddba13ed4408ea2b0a12ab18ed2d2eda086279736bdc121ca726a11f1e4b99217d9c534c2cc4ebb22729349c8c5fdbe1529e1f2c3c5859c62ef4dd9feea25c
7
- crypted_password: 3d16c326648cccafe3d4b4cb024475c381dda92f430dfedf6f933e1f61203bacb6bae2437849bdb43b06be335e23790e4aa03902b3c28c3bbbbe27d501e521f3
8
- password_salt: n6z_wtpWoIsHgQb5IcFd
9
- <%- else -%>
10
- password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
11
- password_salt: bef65e058905c379436d80d1a32e7374b139e7b0
12
- <%- end -%>
13
-
14
- bar:
15
- username: bar
16
- email: bar@example.com
17
- <%- if options[:authlogic] -%>
18
- persistence_token: 19e074bd7cb506ab3e7e53e41f24f0ab3221c8cb68111f4c1aa43965114ad734233979a50a9463537487cdca18c279ac91c4bc83693d589625d446493322394c
19
- crypted_password: 3bc9f4113ca645a186765df3d31a9352d0067bf2304ba0cdd6b08a7f3d58c6668ab1762fa3e76aef466ea2ff188399d8e6c40244fa59312bb4112292dac9f7f0
20
- password_salt: UiAh9ejabnKRxqsiK0xO
21
- <%- else -%>
22
- password_hash: 3488f5f7efecab14b91eb96169e5e1ee518a569f
23
- password_salt: bef65e058905c379436d80d1a32e7374b139e7b0
24
- <%- end -%>
@@ -1,20 +0,0 @@
1
- class Create<%= user_plural_class_name %> < ActiveRecord::Migration
2
- def self.up
3
- create_table :<%= user_plural_name %> do |t|
4
- t.string :username
5
- t.string :email
6
- <%- if options[:authlogic] -%>
7
- t.string :persistence_token
8
- t.string :crypted_password
9
- <%- else -%>
10
- t.string :password_hash
11
- <%- end -%>
12
- t.string :password_salt
13
- t.timestamps
14
- end
15
- end
16
-
17
- def self.down
18
- drop_table :<%= user_plural_name %>
19
- end
20
- end