Permalink
Browse files

Getting recipes into ideal schema configuration, next up comes the ac…

…tual code.
  • Loading branch information...
1 parent 2a1060e commit b3540f41d31c3ca58ae60c87c1fb588c4030efb2 Michael Bleigh committed Mar 13, 2011
@@ -1,5 +1,6 @@
require 'rails_wizard/recipes'
require 'rails_wizard/recipe'
+require 'rails_wizard/config'
Dir[File.dirname(__FILE__) + '/../recipes/*.rb'].each do |path|
key = File.basename(path, '.rb')
View
@@ -0,0 +1,44 @@
+module RailsWizard
+ class Config
+ attr_reader :questions
+
+ def initialize(schema)
+ @questions = {}
+ schema.each_pair do |key, details|
+ kind = details['type']
+ raise ArgumentError, "Unrecognized question type, must be one of #{QUESTION_TYPES.keys.join(', ')}" unless QUESTION_TYPES.keys.include?(kind)
+ @questions[key] = QUESTION_TYPES[kind].new(details)
+ end
+ end
+
+ def compile(values = {})
+
+ end
+
+ class Question
+ def initialize(schema)
+ end
+ end
+
+ class Prompt
+ def initialize(details)
+
+ end
+ end
+
+ class TrueFalse < Question
+ def compile
+ "wizard_yes?(#{prompt.inspect})"
+ end
+ end
+
+ class MultipleChoice < Question
+ end
+
+ QUESTION_TYPES = {
+ 'boolean' => TrueFalse,
+ 'string' => Prompt,
+ 'multiple_choice' => MultipleChoice
+ }
+ end
+end
View
@@ -1,8 +1,16 @@
require 'active_support/inflector'
require 'yaml'
+require 'rails_wizard/config'
+
module RailsWizard
class Recipe
+ ATTRIBUTES = %w(key args category name description template config)
+ DEFAULT_ATTRIBUTES = {
+ :category => 'other',
+ :args => []
+ }
+
def self.generate(key, template_or_file, attributes = {})
if template_or_file.respond_to?(:read)
file = template_or_file.read
@@ -25,16 +33,14 @@ def self.generate(key, template_or_file, attributes = {})
recipe_class
end
- ATTRIBUTES = %w(key category name description template)
-
ATTRIBUTES.each do |setter|
class_eval <<-RUBY
def self.#{setter}
- (@attributes ||= {})[:#{setter}]
+ attributes[:#{setter}]
end
def self.#{setter}=(val)
- (@attributes ||= {})[:#{setter}] = val
+ attributes[:#{setter}] = val
end
def #{setter}
@@ -44,21 +50,39 @@ def #{setter}
end
# The attributes hash containing any set values for
- # the properties specified in ATTRIBUTES.
def self.attributes
- @attributes || {}
+ @attributes ||= DEFAULT_ATTRIBUTES.dup
end
def self.attributes=(hash)
- @attributes = hash
+ attributes.merge! hash
+ end
+
+ def self.config
+ return nil unless attributes[:config]
+ RailsWizard::Config.new(attributes[:config])
end
def attributes
self.class.attributes
end
- def compile
+ def self.compile
"# >#{"[ #{name} ]".center(75,'-')}<\n\n# #{description}\nsay_recipe '#{name}'\n\n#{template}\n"
end
+ def compile; self.class.compile end
+
+ def self.to_mongo(value)
+ case value
+ when Class
+ value.key
+ when String
+ value
+ end
+ end
+
+ def self.from_mongo(key)
+ RailsWizard::Recipes[key]
+ end
end
end
@@ -11,6 +11,10 @@ def self.add(recipe)
recipe
end
+ def self.[](key)
+ @@list[key.to_s]
+ end
+
def self.list
@@list.keys.sort
end
@@ -19,6 +23,10 @@ def self.list_classes
@@list.values.sort_by{|c| c.key}
end
+ def self.categories
+ @@categories.keys.sort
+ end
+
def self.for(category)
(@@categories[category.to_s] || []).sort
end
@@ -18,9 +18,9 @@ Gem::Specification.new do |s|
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")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.files = Dir["lib/**/*.rb", "recipes/*.rb", "README.markdown", "version.rb"]
+ s.test_files = Dir["spec/**/*"]
+ s.executables = Dir["bin/*"]
s.require_paths = ["lib"]
end
View
@@ -2,6 +2,10 @@
__END__
-category: orm
name: ActiveRecord
description: "Use the default ActiveRecord database store."
+author: mbleigh
+
+exclusive: orm
+category: persistence
+tags: [sql, defaults, orm]
View
@@ -0,0 +1,17 @@
+gem 'steak', '>= 1.0.0.rc.1'
+gem 'capybara'
+
+after_bundler do
+ generate 'steak:install'
+end
+
+__END__
+
+name: Capybara
+description: "Use the Capybara acceptance testing libraries with RSpec."
+author: mbleigh
+
+requires: [rspec]
+exclusive: acceptance_testing
+category: testing
+tags: [acceptance]
View
@@ -7,6 +7,10 @@
__END__
-category: integration_testing
name: Cucumber
description: "Use Cucumber for integration testing with Capybara."
+author: mbleigh
+
+exclusive: acceptance_testing
+category: testing
+tags: [acceptance]
View
@@ -3,21 +3,21 @@
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
+ if recipes.include? 'mongo_mapper'
+ gem 'mm-devise'
+ gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongo_mapper_active_model'
+ elsif recipes.include? 'mongoid'
+ gsub_file 'config/intializers/devise.rb', 'devise/orm/active_record', 'devise/orm/mongoid'
+ end
+
+ generate 'devise user'
end
__END__
-category: authentication
name: Devise
-description: "Utilize Devise for authentication, automatically configured for your selected ORM."
+description: Utilize Devise for authentication, automatically configured for your selected ORM.
+author: mbleigh
+
+category: authentication
+exclusive: authentication
View
@@ -3,6 +3,9 @@
__END__
-category: templating
name: HAML
description: "Utilize HAML for templating."
+author: mbleigh
+
+category: templating
+exclusive: templating
View
@@ -0,0 +1,26 @@
+after_bundler do
+ heroku_name = nil
+ while heroku_name.blank? || !system("heroku create #{heroku_name}")
+ heroku_name = wizard_ask("What do you want to call your app? ")
+ end
+
+ git :push => "heroku master"
+end
+
+__END__
+
+name: Heroku
+description: Create a Heroku application and instantly deploy.
+author: mbleigh
+
+exclusive: deployment
+category: deployment
+tags: [provider]
+
+config:
+ - app_name:
+ prompt: "Application Name:"
+ type: string
+ - staging:
+ prompt: "Create staging app? (appname-staging.heroku.com)"
+ type: boolean
View
@@ -0,0 +1,28 @@
+if recipes.include? 'heroku'
+ before_config do
+ config['heroku'] = wizard_yes?("Use Heroku addon for Hoptoad?")
+ end
+end
+
+gem 'hoptoad_notifier'
+
+if config['heroku']
+ generate "hoptoad --heroku"
+else
+ generate "hoptoad --api-key #{config['api_key']}"
+end
+
+__END__
+
+name: Hoptoad
+description: Add Hoptoad exception reporting to your application.
+
+category: services
+exclusive: exception_notification
+tags: [exception_notification]
+
+config:
+ - api_key:
+ prompt: "Enter Hoptoad API Key:"
+ type: string
+ unless: heroku
View
@@ -1,6 +1,6 @@
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"
+ get "http://code.jquery.com/jquery-1.5.1.min.js", "jquery.js"
end
application do
@@ -12,6 +12,12 @@
__END__
-category: javascript
name: jQuery
description: "Adds the latest jQuery and Rails UJS helpers for jQuery."
+author: mbleigh
+
+exclusive: javascript_framework
+category: javascript
+tags: [framework]
+
+args: ["-J"]
View
@@ -3,6 +3,9 @@
__END__
-category: css
name: Less CSS
description: "Utilize Less CSS for CSS generation utilizing the \"more\" plugin for Rails."
+author: mbleigh
+
+exclusive: css_replacement
+category: css
View
@@ -7,6 +7,12 @@
__END__
-category: orm
name: MongoMapper
description: "Use MongoDB with MongoMapper as your primary datastore."
+author: mbleigh
+
+exclusive: orm
+category: persistence
+tags: [mongodb, orm]
+
+args: ["-O"]
View
@@ -6,6 +6,13 @@
__END__
-category: orm
name: Mongoid
description: "Utilize MongoDB with Mongoid as the ORM."
+author: mbleigh
+
+category: persistence
+exclusive: orm
+tags: [orm, mongodb]
+
+args: ["-O"]
+
View
@@ -12,6 +12,12 @@
__END__
-category: javascript
name: MooTools
description: "Adds MooTools and MooTools-compatible UJS helpers."
+author: mbleigh
+
+exclusive: javascript_framework
+category: javascript
+tags: [framework]
+
+args: ["-J"]
View
@@ -7,6 +7,9 @@
__END__
-category: authentication
name: OmniAuth
description: "A basic setup of OmniAuth with a SessionsController to handle the request and callback phases."
+author: mbleigh
+
+exclusive: authentication
+category: authentication
Oops, something went wrong.

0 comments on commit b3540f4

Please sign in to comment.