Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfixes, misc. improvements and added a few new bricks

  • Loading branch information...
commit 2309a8d913131186d364c9b14c274be00b155afd 1 parent c66a311
@lhoeg authored
View
8 aasm.rb
@@ -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
11 acts-as-taggeable-on.rb
@@ -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
28 app_lego.rb
@@ -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
278 authlogic-scaffold.rb
@@ -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
2  cucumber.rb
@@ -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
4 haml.rb
@@ -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
2  locale.rb
@@ -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
2  machinist.rb
@@ -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.'"
View
46 misc.rb
@@ -27,13 +27,9 @@ def body_class
}
-Dir['config/locales/*.*'].map {|f| File.basename(f).split(".").first}.uniq.each do |locale|
- file "config/locales/#{locale}.app.yml", <<-YAML
-#{locale}:
- app_name: "APP_NAME"
- YAML
-end
+# layout
+# Detect whether stylesheets are placed in compiled directory
stylesheet_path_prefix = File.exists?('public/stylesheets/compiled') ? 'compiled/' : ''
if File.exists?('vendor/plugins/haml')
@@ -49,27 +45,26 @@ def body_class
%html{html_attrs}
%head
%meta{'http-equiv' => 'Content-Type', :content => 'text/html; charset=utf-8'}
- -# %meta{:name => "description" content="A collection of Rails templates I use for projects"}
- -# %link{:rel => "alternate", :href => "http://github.com/feeds/rayngwf/commits/app_lego/master",
- :title => "Recent Commits to app_lego:master", :type => "application/atom+xml"}
+ %meta{:name => "description" content="A Ruby on Rails application generated by app_lego templates"}
%link{ :rel => "shortcut icon", :href => "/favicon.ico", :type => "image/x-icon"}
%title= "\#{page_title + ' - ' unless page_title.blank?}\#{t(:app_name)}"
= stylesheet_link_tag '#{stylesheet_path_prefix}screen.css', :media => 'screen, projection'
= stylesheet_link_tag '#{stylesheet_path_prefix}print.css', :media => 'print'
/[if IE]
= stylesheet_link_tag '#{stylesheet_path_prefix}ie.css', :media => 'screen, projection'
- = yield :local_styles
= javascript_include_tag :defaults
- = yield :unobtrusive_javascript
%body{:class => body_class}
#container
#header
- %h1 app_name
+ %h1{:title => t(:app_name)}=h t(:app_name)
+ / insert header content
#sidebar
+ / insert sidebar content
#content
= render :partial => 'layouts/flashes'
= yield
#footer
+ / insert footer content
HAML
else
@@ -92,17 +87,25 @@ def body_class
<!--[if IE]>
<%= stylesheet_link_tag '#{stylesheet_path_prefix}ie.css', :media => 'screen, projection' %>
<![endif]-->
- <%= yield :local_styles %>
<%= javascript_include_tag :defaults %>
- <%= yield :unobtrusive_javascript %>
</head>
<body class="<%= body_class %>">
- <div id="header">
- <%= render :partial => 'layouts/flashes' -%>
- </div>
- <div class="container">
- <%= yield %>
- </div>
+ <div id="container">
+ <div id="header">
+ <h1 title="#{t(:app_name)}"><%=h t(:app_name) %></h1>
+ <!-- insert header content -->
+ </div>
+ <div id="sidebar">
+ <!-- insert sidebar content -->
+ </div>
+ <div class="main">
+ <%= render :partial => 'layouts/flashes' -%>
+ <%= yield %>
+ </div>
+ <div id="footer">
+ <!-- insert footer content -->
+ </div>
+ </div
</body>
</html>
ERB
@@ -116,9 +119,12 @@ def body_class
erb_files = Dir['app/views/*/*.html.erb']
erb_files.each do |erb|
run "html2haml #{erb} #{File.basename(erb) << '.haml'}"
+ end
end
+
# initializers
+
initializer 'requires.rb',
%q{Dir[Rails.root.join('lib', '*.rb')].each do |f|
require f
View
4 object_daddy.rb
@@ -0,0 +1,4 @@
+plugin "object_daddy", :git => "git://github.com/flogic/object_daddy"
+
+git :add => "."
+git :commit => "-a -m 'Added object_daddy fixture generation'"
View
7 sqlite3.rb
@@ -0,0 +1,7 @@
+# Install sqlite3-ruby gem with correct lib (breaks otherwise on some systems)
+gem "sqlite3-ruby", :lib => "sqlite3"
+
+rake "gems:install", :sudo=>true
+
+git :add => "."
+git :commit => "-a -m 'Added sqlite3-ruby'"
View
5 webrat.rb
@@ -0,0 +1,5 @@
+gem 'webrat', :env => :test
+rake "gems:install", :sudo => true, :env => :test
+
+git :add => '.'
+git :commit => "-a -m 'Added Webrat web browser simulator for integration testing.'"
View
14 welcome-scaffold.rb
@@ -0,0 +1,14 @@
+# Generate a simple welcome page scaffold
+if File.exists?('spec')
+ generate :rspec_controller, "welcome index"
+ File.delete("spec/helpers/welcome_helper_spec.rb")
+else
+ generate :controller, "welcome index"
+ File.delete("test/unit/helpers/welcome_helper_test.rb")
+end
+route "map.root :controller => 'welcome'"
+
+File.delete("app/helpers/welcome_helper.rb")
+
+git :add => "."
+git :commit => "-m 'Added Welcome scaffold as homepage'"
Please sign in to comment.
Something went wrong with that request. Please try again.