Permalink
Browse files

Bugfixes, misc. improvements and added a few new bricks

  • Loading branch information...
1 parent c66a311 commit 2309a8d913131186d364c9b14c274be00b155afd @lhoeg committed May 20, 2009
Showing with 383 additions and 28 deletions.
  1. +8 −0 aasm.rb
  2. +11 −0 acts-as-taggeable-on.rb
  3. +22 −6 app_lego.rb
  4. +278 −0 authlogic-scaffold.rb
  5. +2 −0 cucumber.rb
  6. +4 −0 haml.rb
  7. +1 −1 locale.rb
  8. +1 −1 machinist.rb
  9. +26 −20 misc.rb
  10. +4 −0 object_daddy.rb
  11. +7 −0 sqlite3.rb
  12. +5 −0 webrat.rb
  13. +14 −0 welcome-scaffold.rb
View
@@ -0,0 +1,8 @@
+# Install aasm state machine
+# see http://github.com/rubyist/aasm
+gem "rubyist-aasm", :lib => "aasm"
+
+rake "gems:install", :sudo=>true
+
+git :add => "."
+git :commit => "-a -m 'Added aasm state machine'"
View
@@ -0,0 +1,11 @@
+# Install acts-as-taggeable-on
+# see http://github.com/mbleigh/acts-as-taggable-on
+gem "mbleigh-acts-as-taggable-on", :lib => "acts-as-taggable-on"
+
+rake "gems:install", :sudo=>true
+
+generate "acts_as_taggable_on_migration"
+rake "db:migrate"
+
+git :add => "."
+git :commit => "-a -m 'Added acts-as-taggable-on'"
View
@@ -36,21 +36,37 @@ def plugin(name, options)
modules = [
["basic", "Do basic setup? (only exclude this if you already have a Rails app skeleton with Rails 2.3+ frozen, or as a gem)"],
["frozen_edge", "Freeze edge Rails?"],
- ["haml", "Use haml for views and sass for css?"],
+ ["sqlite3", "Use sqlite3?"],
+
+ ["haml", "Use haml for views and sass for css?"], # must be before generating any templates
["compass", "Use compass for CSS?"],
- ["rspec", "Use RSpec instead of test/unit?"],
- ["cucumber","Install Cucumber/Webrat testing framework?"],
+
+ ["rspec", "Use RSpec instead of Test::Unit?"], # must be before any generators etc. who may test for RSpec
+ ["shoulda", "Add Shoulda testing capabilities?"],
+
+ ["cucumber","Install Cucumber/Webrat integration testing framework?"],
+ ["webrat","Install Webrat web browser simulator for integration testing?"],
+
+ ["factory_girl","Add factory_girl fixture generation?"],
+ ["machinist","Add machinist fixture generation?"],
+ ["object_daddy","Add object_daddy fixture generation?"],
+
["hoptoad", "Use Hoptoad error notifier?"],
["jquery", "Use jQuery instead of Prototype + Script.aculo.us?"],
["jrails", "install jquery for rails plugin?"],
+
["auth", "Add authentication module?"],
+ ["authlogic-scaffold", "Add scaffold for authlogic?"],
+
+ ["aasm", "install aasm state machine?"],
+ ["acts-as-taggeable-on", "install acts-as-taggeable-on?"],
+
["locale", "Add specific localizations?"],
- ["welcome-scaffold", "Add welcome page?"],
["layout", "Add basic layout?"],
["misc", "Add miscellaneous stuff (helpers, basic layout, flashes, initializers)?"],
+ ["welcome-scaffold", "Add a welcome page scaffold?"],
+
["clearance", "Add clearance engine?"],
- ["factory_girl", "Add factory_girl fixture generation?"],
- ["shoulda", "Add shoulda testing capibilities?"],
["typus", "Add typus admin panel handling?"],
]
View
@@ -0,0 +1,278 @@
+# Create Authlogic user controller/views
+
+user_model ||= ENV['USER_MODEL'] || ask("What should be the name of the user model?")
+user_model = user_model.underscore
+user_ident ||= ENV['USER_IDENT'] || ask("What is the identifier of a user? (e.g. login, email)")
+
+
+# Add some helper methods at the end of ApplicationController
+sentinel = "\nend"
+gsub_file 'app/controllers/application_controller.rb', /(#{Regexp.escape(sentinel)})/mi do |match|
+ data = <<-AUTHLOGIC
+
+ # Authlogic-specific helper methods
+ helper_method :current_user
+
+ private
+ def current_user_session
+ return @current_user_session if defined?(@current_user_session)
+ @current_user_session = UserSession.find
+ end
+
+ def current_user
+ return @current_user if defined?(@current_user)
+ @current_user = current_user_session && current_user_session.record
+ end
+
+ def require_user
+ unless current_user
+ store_location
+ flash[:notice] = "You must be logged in to access this page"
+ redirect_to new_user_session_url
+ return false
+ end
+ end
+
+ def require_no_user
+ if current_user
+ store_location
+ flash[:notice] = "You must be logged out to access this page"
+ redirect_to account_url
+ return false
+ end
+ end
+
+ def store_location
+ session[:return_to] = request.request_uri
+ end
+
+ def redirect_back_or_default(default)
+ redirect_to(session[:return_to] || default)
+ session[:return_to] = nil
+ end
+
+AUTHLOGIC
+ data << match
+end
+
+
+# Create UserSession controller and minimal log-in/-out views
+file File.join("app", "controllers", "#{user_model}_sessions_controller.rb"), <<-USERSESSIONS
+class #{user_model.classify}SessionsController < ApplicationController
+ before_filter :require_no_user, :only => [:new, :create]
+ before_filter :require_user, :only => :destroy
+
+ def new
+ @#{user_model}_session = #{user_model.classify}Session.new
+ end
+
+ def create
+ @#{user_model}_session = #{user_model.classify}Session.new(params[:#{user_model}_session])
+ if @#{user_model}_session.save
+ flash[:notice] = "Successfully logged in."
+ redirect_back_or_default root_url
+ else
+ render :action => 'new'
+ end
+ end
+
+ def destroy
+ @#{user_model}_session = #{user_model.classify}Session.find
+ @#{user_model}_session.destroy
+ flash[:notice] = "Successfully logged out."
+ redirect_back_or_default root_url
+ end
+end
+USERSESSIONS
+
+route "map.resources :#{user_model}_sessions"
+route "map.login 'login', :controller => '#{user_model}_sessions', :action => 'new'"
+route "map.logout 'logout', :controller => '#{user_model}_sessions', :action => 'destroy'"
+
+if haml?
+ file File.join("app", "views", "#{user_model}_sessions", "new.html.haml"), <<-NEW
+%h1 Log in
+- form_for @#{user_model}_session do |f|
+ = f.error_messages
+ %p
+ = f.label :#{user_ident}
+ %br/
+ = f.text_field :#{user_ident}
+ %p
+ = f.label :password
+ %br/
+ = f.password_field :password
+ %p
+ = f.submit "Submit"
+NEW
+
+else
+
+ file File.join("app", "views", "#{user_model}_sessions", "new.html.erb"), <<-NEW
+<h2>Log in</h2>
+
+<% form_for @#{user_model}_session do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :#{user_ident} %><br />
+ <%= f.text_field :#{user_ident} %>
+ </p>
+ <p>
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
+NEW
+end
+
+
+# Generate minimal user controller
+file File.join("app", "controllers", "#{user_model.pluralize}_controller.rb"), <<-USERS
+class #{user_model.classify.pluralize}Controller < ApplicationController
+ #before_filter :require_no_user, :only => [:new, :create]
+ #before_filter :require_user, :only => [:show, :edit, :update]
+
+ def new
+ @#{user_model} = #{user_model.classify}.new
+ end
+
+ def create
+ @#{user_model} = #{user_model.classify}.new(params[:#{user_model}])
+ if @#{user_model}.save
+ flash[:notice] = "Registration successful."
+ redirect_back_or_default root_url
+ else
+ render :action => 'new'
+ end
+ end
+
+ def edit
+ @#{user_model} = current_user
+ end
+
+ def update
+ @#{user_model} = current_user
+ if @#{user_model}.update_attributes(params[:#{user_model}])
+ flash[:notice] = "Successlfuly updated #{user_model}."
+ redirect_to #{user_model.pluralize}_url
+ else
+ render :action => 'edit'
+ end
+ end
+end
+USERS
+
+route "map.resources :#{user_model.pluralize}"
+
+def haml?
+ File.exists?('vendor/plugins/haml')
+end
+
+# Create create/edit views
+if haml?
+ file File.join("app", "views", user_model.pluralize, "new.html.haml"), <<-NEW
+%h2 New #{user_model.classify}
+= render :partial => 'form'
+%p
+ = link_to "Back to List", #{user_model.pluralize}_path
+NEW
+
+ file File.join("app", "views", user_model.pluralize, "edit.html.haml"), <<-EDIT
+%h2 Edit #{user_model.classify}
+= render :partial => 'form'
+%p
+ = link_to "Show", @#{user_model}
+ |
+ = link_to "View All", #{user_model.pluralize}_path
+EDIT
+
+ file File.join("app", "views", user_model.pluralize, "_form.html.haml"), <<-FORM
+-form_for @#{user_model} do |f|
+ = f.error_messages
+ %p
+ = f.label :#{user_ident}
+ %br/
+ = f.text_field :#{user_ident}
+ %p
+ = f.label :password
+ %br/
+ = f.password_field :password
+ %p
+ = f.label :password_confirmation
+ %br/
+ = f.password_field :password_confirmation
+ %p
+ = f.submit "Submit"
+FORM
+
+ file File.join("app", "views", user_model.pluralize, "_user_nav.html.haml"), <<-USERNAV
+#user-nav
+ - if current_user
+ = link_to "Edit Profile", edit_#{user_model}_path(:current)
+ |
+ = link_to "Logout", logout_path
+ - else
+ = link_to "Register", new_#{user_model}_path
+ |
+ = link_to "Login", login_path
+USERNAV
+
+else
+
+ file File.join("app", "views", user_model.pluralize, "new.html.erb"), <<-FORM
+ <h2>New #{user_model.classify}</h2>
+
+ <%= render :partial => 'form' %>
+
+ <p><%= link_to "Back to List", #{user_model.pluralize}_path %></p>
+FORM
+
+ file File.join("app", "views", user_model.pluralize, "edit.html.erb"), <<-FORM
+ <h2>Edit #{user_model.classify}</h2>
+
+ <%= render :partial => 'form' %>
+
+ <p>
+ <%= link_to "Show", @#{user_model} %> |
+ <%= link_to "View All", #{user_model.pluralize}_path %>
+ </p>
+FORM
+
+ file File.join("app", "views", user_model.pluralize, "_form.html.erb"), <<-FORM
+<% form_for @#{user_model} do |f| %>
+ <%= f.error_messages %>
+ <p>
+ <%= f.label :#{user_ident} %><br />
+ <%= f.text_field :#{user_ident} %>
+ </p>
+ <p>
+ <%= f.label :password %><br />
+ <%= f.password_field :password %>
+ </p>
+ <p>
+ <%= f.label :password_confirmation %><br />
+ <%= f.password_field :password_confirmation %>
+ </p>
+ <p><%= f.submit "Submit" %></p>
+<% end %>
+FORM
+
+ file File.join("app", "views", user_model.pluralize, "_user_nav.html.erb"), <<-USERNAV
+<% if current_user %>
+ <%= link_to "Edit Profile", edit_#{user_model}_path(:current) %>
+ |
+ <%= link_to "Logout", logout_path %>
+<% else %>
+ <%= link_to "Register", #{user_model}_page %>
+ |
+ <%= link_to "Login", login_path %>
+<% end %>
+USERNAV
+end
+
+
+# OPTIONAL: Add styles to user_nav
+# #user-nav
+# +float(right)
+# font-size: 12px
View
@@ -1,3 +1,5 @@
+# see http://github.com/aslakhellesoy/cucumber
+# see also http://github.com/bmabey/cucumber-tmbundle
gem 'cucumber', :env => :test
gem 'webrat', :env => :test
View
@@ -1,3 +1,7 @@
+# see http://github.com/nex3/haml
+# see also http://github.com/douglasjarquin/ruby-haml-tmbundle/
+# see also http://github.com/seaofclouds/sass-textmate-bundle
+
#gem 'echoe'
gem 'haml', :version => '>=2.1'
View
@@ -34,7 +34,7 @@ def uri_exists?(uri)
Dir['config/locales/*.*'].map {|f| File.basename(f).split(".").first}.uniq.each do |locale|
file "config/locales/#{locale}.app.yml", <<-YAML
#{locale}:
- app_name: "#{NAME}"
+ app_name: "#{File.basename(root).titleize}"
YAML
end
View
@@ -34,5 +34,5 @@
SH
git :add => "."
-git :commit => "-m 'Added machinist. fixtures aren't fun.'"
+git :commit => "-m 'Added machinist. fixtures aren`t fun.'"
Oops, something went wrong.

0 comments on commit 2309a8d

Please sign in to comment.