Permalink
Browse files

Basic recipe scaffold is put together, imported all of the published …

…recipes from RailsWizard.
  • Loading branch information...
1 parent cef963e commit 9bd3ebf2f7ab057b144c5ef45856c145cab4c6de Michael Bleigh committed Mar 11, 2011
View
2 .rspec
@@ -0,0 +1,2 @@
+--format nested
+--colour
View
@@ -0,0 +1 @@
+Autotest.add_discovery { "rspec2" }
View
@@ -0,0 +1,94 @@
+require 'active_support/inflector'
+
+module RailsWizard
+ module Recipes
+ @@categories = {}
+ @@list = {}
+
+ def self.add(recipe)
+ @@list[recipe.key] = recipe
+ end
+
+ def self.list
+ @@list.keys.sort
+ end
+
+ def self.list_classes
+ @@list.values.sort_by{|c| c.key}
+ end
+
+ def self.for(category)
+ (@@categories[category.to_s] || []).sort
+ end
+
+ def self.add_to_category(category, recipe)
+ (@@categories[category.to_s] ||= []) << recipe.key
+ @@categories[category.to_s].uniq!
+ end
+
+ def self.remove_from_category(category, recipe)
+ (@@categories[category.to_s] ||= []).delete(recipe.key)
+ end
+ end
+
+ class Recipe
+ def self.inherited(subclass)
+ file, = caller[0].partition(':')
+
+ parts = File.open(file).read.split(/^__END__$/)
+ if parts.size > 1
+ subclass.template parts.last.strip
+ end
+
+ RailsWizard::Recipes.add(subclass)
+ end
+
+ # The unique key to reference this recipe, calculated simply
+ # as the underscoring of its class name.
+ def self.key(val = false)
+ ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(to_s))
+ end
+
+ ATTRIBUTES = %w(category name description template)
+
+ ATTRIBUTES.each do |setter|
+ class_eval <<-RUBY
+ def self.#{setter}(val = false)
+ @attributes ||= {}
+ @attributes[:#{setter}] = val unless val == false
+ @attributes[:#{setter}]
+ end
+
+ def #{setter}
+ self.class.#{setter}
+ end
+ RUBY
+ end
+
+ def self.category(val = false)
+ if @attributes[:category]
+ RailsWizard::Recipes.remove_from_category(@attributes[:category], self)
+ end
+
+ @attributes ||= {}
+ @attributes[:category] = val unless val == false
+ RailsWizard::Recipes.add_to_category(val, self)
+ @attributes[:category]
+ end
+
+
+ # The attributes hash containing any set values for
+ # the properties specified in ATTRIBUTES.
+ def self.attributes
+ @attributes
+ end
+
+ def attributes
+ self.class.attributes
+ end
+
+ def compile
+ "# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_recipe '#{name}'\n\n#{template}\n"
+ end
+ end
+end
@@ -0,0 +1,15 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class ActiveRecord < RailsWizard::Recipe
+ name "ActiveRecord"
+ category "orm"
+ description "Use the default ActiveRecord database store."
+ end
+ end
+end
+
+__END__
+
+# No additional code required.
@@ -0,0 +1,20 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Cucumber < RailsWizard::Recipe
+ name "Cucumber"
+ category "integration_testing"
+ description "Use Cucumber for integration testing with Capybara."
+ end
+ end
+end
+
+__END__
+
+gem 'cucumber-rails', :group => :test
+gem 'capybara', :group => :test
+
+after_bundler do
+ generate "cucumber:install --capybara#{' --rspec' if recipes.include?('rspec')}#{' -D' unless recipes.include?('activerecord')}"
+end
@@ -0,0 +1,31 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Devise < RailsWizard::Recipe
+ name "Devise"
+ category "authentication"
+ description "Utilize Devise for authentication, automatically configured for your selected ORM."
+ end
+ end
+end
+
+__END__
+
+gem 'devise'
+
+after_bundler do
+ generate 'devise:install'
+
+ case template['orm']
+ when 'mongo_mapper'
+ gem 'mm-devise'
+ gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongo_mapper_active_model'
+ when 'mongoid'
+ gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongoid'
+ when 'active_record'
+ # Nothing to do
+
+ generate 'devise user'
+ end
+end
@@ -0,0 +1,16 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Haml < RailsWizard::Recipe
+ name "HAML"
+ category "templating"
+ description "Utilize HAML for templating."
+ end
+ end
+end
+
+__END__
+
+gem 'haml', '>= 3.0.0'
+gem 'haml-rails'
@@ -0,0 +1,26 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Jquery < RailsWizard::Recipe
+ key "jquery"
+ name "jQuery"
+ category "javascript"
+ description "Adds the latest jQuery and Rails UJS helpers for jQuery."
+ end
+ end
+end
+
+__END__
+
+inside "public/javascripts" do
+ get "https://github.com/rails/jquery-ujs/raw/master/src/rails.js", "rails.js"
+ get "http://code.jquery.com/jquery-1.5.min.js", "jquery.js"
+end
+
+application do
+ "\nconfig.action_view.javascript_expansions[:defaults] = %w(jquery rails)\n"
+end
+
+gsub_file "config/application.rb", /# JavaScript.*\n/, ""
+gsub_file "config/application.rb", /# config\.action_view\.javascript.*\n/, ""
@@ -0,0 +1,16 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Less < RailsWizard::Recipe
+ name "Less CSS"
+ category "css"
+ description "Utilize Less CSS for CSS generation utilizing the \"more\" plugin for Rails."
+ end
+ end
+end
+
+__END__
+
+gem 'less'
+plugin 'more', :git => 'git://github.com/cloudhead/more.git'
@@ -0,0 +1,20 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class MongoMapper < RailsWizard::Recipe
+ name "MongoMapper"
+ category "orm"
+ description "Use MongoDB with MongoMapper as your primary datastore."
+ end
+ end
+end
+
+__END__
+
+gem 'bson_ext'
+gem 'mongo_mapper', :git => 'git://github.com/jnunemaker/mongomapper.git', :branch => 'rails3'
+
+after_bundler do
+ generate 'mongo_mapper:config'
+end
@@ -0,0 +1,19 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Mongoid < RailsWizard::Recipe
+ name "Mongoid"
+ category "orm"
+ description "Utilize MongoDB with Mongoid as the ORM."
+ end
+ end
+end
+
+__END__
+
+gem 'mongoid', '>= 2.0.0.beta.19'
+
+after_bundler do
+ generate 'mongoid:config'
+end
@@ -0,0 +1,25 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Mootools < RailsWizard::Recipe
+ name "MooTools"
+ category "javascript"
+ description "Adds MooTools and MooTools-compatible UJS helpers."
+ end
+ end
+end
+
+__END__
+
+inside "public/javascripts" do
+ get "https://github.com/kevinvaldek/mootools-ujs/raw/master/Source/rails.js", "rails.js"
+ get "http://ajax.googleapis.com/ajax/libs/mootools/1.2.5/mootools-yui-compressed.js", "mootools.min.js"
+end
+
+gsub_file "config/application.rb", /# JavaScript.*\n/, ""
+gsub_file "config/application.rb", /# config\.action_view\.javascript.*\n/, ""
+
+application do
+ "\n config.action_view.javascript_expansions[:defaults] = %w(mootools.min rails)\n"
+end
@@ -0,0 +1,20 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Omniauth < RailsWizard::Recipe
+ name "OmniAuth"
+ category "authentication"
+ description "A basic setup of OmniAuth with a SessionsController to handle the request and callback phases."
+ end
+ end
+end
+
+__END__
+
+gem 'omniauth'
+
+after_bundler do
+ file 'app/controllers/sessions_controller.rb', "class SessionsController < ApplicationController\n def callback\n auth # Do what you want with the auth hash!\n end\n\n def auth; request.env['omniauth.auth'] end\nend"
+ route "match '/auth/:provider/callback', :to => 'sessions#callback'"
+end
@@ -0,0 +1,15 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Prototype < RailsWizard::Recipe
+ name "Prototype"
+ category "javascript"
+ description "Use the default Javascript libraries and helpers."
+ end
+ end
+end
+
+__END__
+
+# No extra code required.
@@ -0,0 +1,24 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Rspec < RailsWizard::Recipe
+ key "rspec"
+ name "RSpec"
+ category "unit_testing"
+ description "Use RSpec for unit testing for this Rails app."
+ end
+ end
+end
+
+__END__
+
+gem 'rspec-rails', '>= 2.0.1', :group => [:development, :test]
+
+inject_into_file "config/initializers/generators.rb", :after => "Rails.application.config.generators do |g|\n" do
+ " g.test_framework = :rspec\n"
+end
+
+after_bundler do
+ generate 'rspec:install'
+end
@@ -0,0 +1,18 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Sass < RailsWizard::Recipe
+ key "sass"
+ name "SASS"
+ category "css"
+ description "Utilize SASS (through the HAML gem) for really awesome stylesheets!"
+ end
+ end
+end
+
+__END__
+
+unless recipes.include? 'haml'
+ gem 'haml', '>= 3.0.0'
+end
@@ -0,0 +1,16 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Slim < RailsWizard::Recipe
+ name "Slim"
+ category "templating"
+ description "Use Slim as the default templating engine."
+ end
+ end
+end
+
+__END__
+
+gem 'slim'
+gem 'slim-rails'
Oops, something went wrong.

0 comments on commit 9bd3ebf

Please sign in to comment.