Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…recipes from RailsWizard.
  • Loading branch information...
commit 9bd3ebf2f7ab057b144c5ef45856c145cab4c6de 1 parent cef963e
Michael Bleigh authored
View
2  .rspec
@@ -0,0 +1,2 @@
+--format nested
+--colour
View
1  autotest/discover.rb
@@ -0,0 +1 @@
+Autotest.add_discovery { "rspec2" }
View
94 lib/rails_wizard/recipe.rb
@@ -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
View
15 lib/rails_wizard/recipes/active_record.rb
@@ -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.
View
20 lib/rails_wizard/recipes/cucumber.rb
@@ -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
View
31 lib/rails_wizard/recipes/devise.rb
@@ -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
View
16 lib/rails_wizard/recipes/haml.rb
@@ -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'
View
26 lib/rails_wizard/recipes/jquery.rb
@@ -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/, ""
View
16 lib/rails_wizard/recipes/less.rb
@@ -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'
View
20 lib/rails_wizard/recipes/mongo_mapper.rb
@@ -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
View
19 lib/rails_wizard/recipes/mongoid.rb
@@ -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
View
25 lib/rails_wizard/recipes/mootools.rb
@@ -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
View
20 lib/rails_wizard/recipes/omniauth.rb
@@ -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
View
15 lib/rails_wizard/recipes/prototype.rb
@@ -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.
View
24 lib/rails_wizard/recipes/rspec.rb
@@ -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
View
18 lib/rails_wizard/recipes/sass.rb
@@ -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
View
16 lib/rails_wizard/recipes/slim.rb
@@ -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'
View
20 lib/rails_wizard/recipes/steak.rb
@@ -0,0 +1,20 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class Steak < RailsWizard::Recipe
+ name "Steak"
+ category "integration_testing"
+ description "Use Steak and Capybara for integration testing."
+ end
+ end
+end
+
+__END__
+
+gem 'steak', '>= 1.0.0.rc.1'
+gem 'capybara'
+
+after_bundler do
+ generate 'steak:install'
+end
View
15 lib/rails_wizard/recipes/test_unit.rb
@@ -0,0 +1,15 @@
+require 'rails_wizard/recipe'
+
+module RailsWizard
+ module Recipes
+ class TestUnit < RailsWizard::Recipe
+ name "Test::Unit"
+ category "unit_testing"
+ description "Utilize the default Rails test facilities."
+ end
+ end
+end
+
+__END__
+
+# No additional code required.
View
8 lib/railswizard-recipes.rb
@@ -1,5 +1,3 @@
-module Railswizard
- module Recipes
- # Your code goes here...
- end
-end
+require 'rails_wizard/recipe'
+
+Dir[File.dirname(__FILE__) + '/rails_wizard/recipes/**/*.rb'].each{|f| require f}
View
18 railswizard-recipes.gemspec
@@ -1,18 +1,22 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
-require "railswizard-recipes/version"
+require File.dirname(__FILE__) + "/version"
Gem::Specification.new do |s|
s.name = "railswizard-recipes"
- s.version = Railswizard::Recipes::VERSION
+ s.version = RailsWizard::Recipes::VERSION
s.platform = Gem::Platform::RUBY
- s.authors = ["TODO: Write your name"]
- s.email = ["TODO: Write your email address"]
- s.homepage = ""
- s.summary = %q{TODO: Write a gem summary}
- s.description = %q{TODO: Write a gem description}
+ s.authors = ["Michael Bleigh"]
+ s.email = ["michael@intridea.com"]
+ s.homepage = "http://railswizard.org/"
+ s.summary = %q{The collection of recipes available on RailsWizard.org}
+ s.description = %q{The collection of recipes available on RailsWizard.org}
s.rubyforge_project = "railswizard-recipes"
+
+ s.add_dependency "i18n"
+ s.add_dependency "activesupport", "~> 3.0.0"
+ s.add_development_dependency "rspec", "~> 2.5.0"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
View
85 spec/rails_wizard/recipe_spec.rb
@@ -0,0 +1,85 @@
+require 'spec_helper'
+
+module RailsWizard
+ module Recipes
+ class RecipeExample < ::RailsWizard::Recipe
+ category "example"
+ end
+ end
+end
+
+describe RailsWizard::Recipe do
+ subject{ RailsWizard::Recipes::RecipeExample }
+
+ context 'string setter methods' do
+ (RailsWizard::Recipe::ATTRIBUTES + ['category']).each do |setter|
+ it "should be able to set #{setter} with an argument" do
+ subject.send(setter, "test")
+ subject.send(setter).should == 'test'
+ end
+
+ it 'should be able to get the value from the instance' do
+ subject.send(setter, 'test')
+ subject.new.send(setter).should == subject.send(setter)
+ end
+ end
+ end
+
+ describe ".key" do
+ it 'should be the underscored class name (without modules)' do
+ subject.key.should == "recipe_example"
+ end
+ end
+
+ describe '.attributes' do
+ it 'should be a hash of the set attributes' do
+ hash = subject::ATTRIBUTES.inject({}){|hash,att| subject.send(att, att); hash[att.to_sym] = att; hash}
+ subject.attributes.should == hash
+ end
+
+ it 'should be accessible from the instance' do
+ subject.new.attributes.should == subject.attributes
+ end
+ end
+
+ describe '.template' do
+ it 'should be the trimmed data that comes after __END__' do
+ class RailsWizard::Recipes::TemplateExample < RailsWizard::Recipe; end
+ RailsWizard::Recipes::TemplateExample.template.should == 'this is a test'
+ end
+ end
+
+ describe '#compile' do
+ it 'should say the name' do
+ subject.name "Awesome Sauce"
+ subject.new.compile.should be_include("say_recipe 'Awesome Sauce'")
+ end
+
+ it 'should include the template' do
+ subject.template "This is only a test."
+ subject.new.compile.should be_include(subject.template)
+ end
+ end
+end
+
+describe RailsWizard::Recipes do
+ subject{ RailsWizard::Recipes }
+ it '.list_classes should include recipe classes' do
+ subject.list_classes.should be_include(RailsWizard::Recipes::RecipeExample)
+ end
+
+ it '.list should include recipe keys' do
+ subject.list.should be_include('recipe_example')
+ end
+
+ describe '.for' do
+ it 'should find for a given category' do
+ RailsWizard::Recipes::RecipeExample.category 'example'
+ RailsWizard::Recipes.for('example').should be_include('recipe_example')
+ end
+ end
+end
+
+__END__
+
+this is a test
View
24 spec/rails_wizard/recipes/sanity_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+# This is a simple set of tests to make sure that
+# all of the recipes conform to the base requirements.
+
+RailsWizard::Recipes.list_classes.each do |recipe|
+ describe recipe do
+ it("should have a name"){ recipe.name.should be_kind_of(String) }
+ it("should have a description"){ recipe.description.should be_kind_of(String) }
+ it("should have a template"){ recipe.template.should be_kind_of(String) }
+ it("should be able to compile"){ recipe.new.compile.should be_kind_of(String) }
+
+ it "should have a string or nil category" do
+ if recipe.category
+ recipe.category.should be_kind_of(String)
+ end
+ end
+
+ it "should be in the list" do
+ RailsWizard::Recipes.list_classes.should be_include(recipe)
+ RailsWizard::Recipes.list.should be_include(recipe.key)
+ end
+ end
+end
View
9 spec/spec_helper.rb
@@ -0,0 +1,9 @@
+require 'bundler'
+Bundler.setup
+require 'rspec'
+
+require 'railswizard-recipes'
+
+RSpec.configure do |config|
+
+end
View
5 version.rb
@@ -0,0 +1,5 @@
+module RailsWizard
+ module Recipes
+ VERSION = "0.0.1"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.