rails_templater 0.0.2 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +3 -0
  3. data/CHANGELOG +17 -0
  4. data/README.textile +58 -0
  5. data/Rakefile +5 -0
  6. data/TODO.textile +5 -5
  7. data/bin/templater +0 -0
  8. data/lib/rails_templater.rb +14 -5
  9. data/lib/rails_templater/cli.rb +1 -1
  10. data/lib/rails_templater/fixture_replacement.rb +23 -0
  11. data/lib/rails_templater/javascript_framework.rb +23 -0
  12. data/lib/rails_templater/orm.rb +23 -0
  13. data/lib/rails_templater/templater.rb +49 -0
  14. data/lib/rails_templater/testing_framework.rb +23 -0
  15. data/lib/rails_templater/version.rb +1 -1
  16. data/lib/template_framework/core_ext.rb +15 -0
  17. data/lib/{template → template_framework}/generators/factory_girl.rb +0 -0
  18. data/lib/{template → template_framework}/generators/factory_girl/model/model_generator.rb +0 -0
  19. data/lib/{template → template_framework}/generators/factory_girl/model/templates/fixtures.rb +0 -0
  20. data/lib/template_framework/recipes/active_record.rb +5 -0
  21. data/lib/template_framework/recipes/cucumber.rb +37 -0
  22. data/lib/{template → template_framework}/recipes/default.rb +2 -5
  23. data/lib/template_framework/recipes/factory_girl.rb +11 -0
  24. data/lib/template_framework/recipes/git.rb +3 -0
  25. data/lib/template_framework/recipes/haml.rb +7 -0
  26. data/lib/template_framework/recipes/javascript_framework.rb +18 -0
  27. data/lib/template_framework/recipes/jquery.rb +10 -0
  28. data/lib/template_framework/recipes/mongoid.rb +11 -0
  29. data/lib/template_framework/recipes/orm.rb +19 -0
  30. data/lib/template_framework/recipes/remarkable.rb +12 -0
  31. data/lib/template_framework/recipes/rspec.rb +22 -0
  32. data/lib/template_framework/recipes/sass.rb +48 -0
  33. data/lib/template_framework/recipes/test_unit.rb +1 -0
  34. data/lib/template_framework/recipes/testing_framework.rb +19 -0
  35. data/lib/{template → template_framework}/snippets/cucumber/factory_girl +0 -0
  36. data/lib/{template/snippets/rails/generators → template_framework/snippets/factory_girl/generator} +0 -0
  37. data/lib/{template → template_framework}/snippets/rspec/mongoid +0 -0
  38. data/lib/template_framework/template_runner.rb +19 -0
  39. data/lib/template_framework/templates/active_record/config/database.yml +22 -0
  40. data/lib/{template → template_framework}/templates/git/gitignore +0 -0
  41. data/lib/{template → template_framework}/templates/haml/app/views/layouts/application.html.haml +0 -0
  42. data/lib/{template → template_framework}/templates/mongoid/features/step_definitions/mongoid_steps.rb +0 -0
  43. data/lib/{template → template_framework}/templates/mongoid/features/support/hooks.rb +0 -0
  44. data/rails_templater.gemspec +2 -0
  45. data/spec/fixtures/sample_snippet +1 -0
  46. data/spec/fixtures/sample_template.rb +0 -0
  47. data/spec/rails_templater/fixture_replacement_spec.rb +29 -0
  48. data/spec/rails_templater/javascript_framework_spec.rb +36 -0
  49. data/spec/rails_templater/orm_spec.rb +36 -0
  50. data/spec/rails_templater/templater_spec.rb +65 -0
  51. data/spec/rails_templater/testing_framework_spec.rb +35 -0
  52. data/spec/rails_templater_spec.rb +9 -0
  53. data/spec/spec_helper.rb +20 -0
  54. data/spec/support/fixtures.rb +5 -0
  55. data/spec/support/paths.rb +1 -0
  56. metadata +65 -26
  57. data/README.md +0 -42
  58. data/lib/template/core_extensions.rb +0 -53
  59. data/lib/template/recipes/cucumber.rb +0 -22
  60. data/lib/template/recipes/design.rb +0 -16
  61. data/lib/template/recipes/factory_girl.rb +0 -5
  62. data/lib/template/recipes/haml.rb +0 -5
  63. data/lib/template/recipes/jquery.rb +0 -7
  64. data/lib/template/recipes/mongoid.rb +0 -7
  65. data/lib/template/recipes/remarkable.rb +0 -6
  66. data/lib/template/recipes/rspec.rb +0 -12
  67. data/lib/template/templater.rb +0 -23
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
+ Gemfile.lock
1
2
  pkg/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format documentation
3
+ --fail-fast
data/CHANGELOG ADDED
@@ -0,0 +1,17 @@
1
+ 0.1.1 (January 30, 2011)
2
+ rails-templater choices are now agnostic
3
+ Add ActiveRecord as an ORM option
4
+ Add TestUnit as a Testing Framework option
5
+ Add Prototype as a JavaScript Framework option
6
+ Remarkable RSpec matchers are optional and are dependent on the RSpec recipe
7
+ Haml is an optional choice for your View Templates
8
+ Sass is an optional choice for composing Stylesheets
9
+ Compass is now dependent on the Sass recipe
10
+ Compass has three options: core, blueprint semantic, and blueprint basic
11
+ Cucumber is an optional choice for Integration Testing
12
+
13
+ 0.0.2 (January 23, 2011)
14
+ Add a custom generator for FactoryGirl which uses the new 2.0.0 syntax
15
+
16
+ 0.0.1 (January 13, 2011)
17
+ First version
data/README.textile ADDED
@@ -0,0 +1,58 @@
1
+ h1. Rails Templater
2
+
3
+ Rails Templater is a gem which generates new Ruby on Rails 3 applications the way you want them. Based on your choices, Rails Templater will create an application configured correctly. For example, if you select Mongoid for an ODM and RSpec for your testing framework, Rails Templater will generate all necessary hooks to handle dropping your collections from MongoDB. The project was inspired by ffmike's "BigOldRailsTemplate":http://github.com/ffmike/BigOldRailsTemplate Rails 2 template project.
4
+
5
+ h2. Install
6
+
7
+ @gem install rails_templater@
8
+
9
+ h2. Usage
10
+
11
+ At the command prompt, create a new Rails application using the @templater@ command:
12
+
13
+ @templater myapp_name@
14
+
15
+ h2. Generated Application
16
+
17
+ Rails Templater provides you with the following choices during application generation:
18
+
19
+ h3. Database
20
+
21
+ * "Mongoid":http://mongoid.org/ as your Object Document Mapper for MongoDB
22
+ * ActiveRecord as your Object Relational Mapper for Relational Databases
23
+
24
+ h3. Testing
25
+
26
+ * "RSpec":http://github.com/rspec/rspec
27
+ ** "Remarkable":http://github.com/remarkable/remarkable for ActiveModel RSpec matchers (optional)
28
+ * TestUnit
29
+
30
+ h4. Fixture Replacement
31
+
32
+ * "FactoryGirl":http://github.com/thoughtbot/factory_girl (Dependent on RSpec recipe)
33
+
34
+ h4. Integration Testing
35
+
36
+ * "Cucumber":http://github.com/aslakhellesoy/cucumber-rails (optional)
37
+
38
+ h3. JavaScript
39
+
40
+ * "jQuery":http://jquery.com/
41
+ * "Prototype":http://www.prototypejs.org/
42
+
43
+ h3. Template Engine
44
+
45
+ * ERB
46
+ * "Haml":http://haml-lang.com (optional)
47
+
48
+ h3. Stylesheets
49
+
50
+ * "Sass":http://sass-lang.com for generating CSS (optional)
51
+ ** "Compass":http://compass-style.org as your stylesheet authoring framework (optional)
52
+
53
+
54
+ h2. Note on Patches/Pull Requests
55
+
56
+ * Fork the project.
57
+ * Make your feature addition or bug fix in a branch.
58
+ * Send me a pull request.
data/Rakefile CHANGED
@@ -1,2 +1,7 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
+
4
+ require "rspec/core/rake_task"
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = 'spec/**/*_spec.rb'
7
+ end
data/TODO.textile CHANGED
@@ -1,7 +1,7 @@
1
1
  h1. TODO
2
2
 
3
- * Write a generator for FactoryGirl which uses the 2.0.0 syntax
4
- * Clean up questions to users during template run
5
- * Make choices agnostic
6
- * Add a choice to load a local configuration YAML with defaults for template input
7
- * Update Mongoid to RC once stabalized
3
+ * Add more options for Fixture Replacement
4
+ * Add some RVM support?
5
+ * Devise recipe
6
+ * SimpleForm recipe
7
+ * Shoulda RSpec matchers for ActiveRecord
data/bin/templater CHANGED
File without changes
@@ -1,10 +1,19 @@
1
+ require 'active_support/core_ext/string'
2
+
1
3
  module RailsTemplater
2
4
  extend self
3
-
5
+
6
+ class NotSupportedError < Exception; end
7
+
4
8
  autoload :Cli, 'rails_templater/cli'
5
-
6
- def template_path
7
- File.join(File.dirname(__FILE__), 'template', 'templater.rb')
9
+ autoload :FixtureReplacement, 'rails_templater/fixture_replacement'
10
+ autoload :JavaScriptFramework, 'rails_templater/javascript_framework'
11
+ autoload :Orm, 'rails_templater/orm'
12
+ autoload :Templater, 'rails_templater/templater'
13
+ autoload :TestingFramework, 'rails_templater/testing_framework'
14
+
15
+ def template_runner
16
+ File.join(File.dirname(__FILE__), 'template_framework', 'template_runner.rb')
8
17
  end
9
-
18
+
10
19
  end
@@ -6,7 +6,7 @@ module RailsTemplater
6
6
  desc "Generates a new Rails application with templater'"
7
7
 
8
8
  def run_templater
9
- system("rails new #{application_name} -JOT -m #{RailsTemplater::template_path}")
9
+ system("rails new #{application_name} -O -m #{RailsTemplater::template_runner}")
10
10
  end
11
11
 
12
12
  end
@@ -0,0 +1,23 @@
1
+ module RailsTemplater
2
+ class FixtureReplacement
3
+
4
+ DEFAULT = :factory_girl
5
+ SUPPORTED_TYPES = [:factory_girl]
6
+
7
+ def type
8
+ @type || DEFAULT
9
+ end
10
+
11
+ def type=(value)
12
+ raise NotSupportedError unless SUPPORTED_TYPES.include?(value)
13
+ @type = value
14
+ end
15
+
16
+ SUPPORTED_TYPES.each do |type|
17
+ define_method "#{type}?" do
18
+ self.type == type
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module RailsTemplater
2
+ class JavaScriptFramework
3
+
4
+ DEFAULT = :jquery
5
+ SUPPORTED_TYPES = [:jquery, :prototype]
6
+
7
+ def type
8
+ @type || DEFAULT
9
+ end
10
+
11
+ def type=(value)
12
+ raise NotSupportedError unless SUPPORTED_TYPES.include?(value)
13
+ @type = value
14
+ end
15
+
16
+ SUPPORTED_TYPES.each do |type|
17
+ define_method "#{type}?" do
18
+ self.type == type
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module RailsTemplater
2
+ class Orm
3
+
4
+ DEFAULT = :mongoid
5
+ SUPPORTED_TYPES = [:active_record, :mongoid]
6
+
7
+ def type
8
+ @type || DEFAULT
9
+ end
10
+
11
+ def type=(value)
12
+ raise NotSupportedError unless SUPPORTED_TYPES.include?(value)
13
+ @type = value
14
+ end
15
+
16
+ SUPPORTED_TYPES.each do |type|
17
+ define_method "#{type}?" do
18
+ self.type == type
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,49 @@
1
+ module RailsTemplater
2
+ class Templater
3
+
4
+ attr_reader :post_bundler_strategies
5
+
6
+ def initialize
7
+ @post_bundler_strategies = []
8
+ @template_framework_path = File.join(File.dirname(__FILE__), '..', 'template_framework')
9
+ end
10
+
11
+ def fixture_replacement
12
+ @fixture_replacement ||= FixtureReplacement.new
13
+ end
14
+
15
+ def orm
16
+ @orm ||= Orm.new
17
+ end
18
+
19
+ def javascript_framework
20
+ @javascript_framework ||= JavaScriptFramework.new
21
+ end
22
+
23
+ def post_bundler(&block)
24
+ @post_bundler_strategies << block
25
+ end
26
+
27
+ def recipe(name)
28
+ File.expand_path("recipes/#{name}.rb", @template_framework_path)
29
+ end
30
+
31
+ ['snippet', 'template'].each do |type|
32
+
33
+ define_method "#{type}_path" do |group|
34
+ File.expand_path("#{type.pluralize}/#{group}", @template_framework_path)
35
+ end
36
+
37
+ define_method "load_#{type}" do |name, group|
38
+ group_path = send("#{type}_path".to_sym, group)
39
+ File.read File.expand_path(name, group_path)
40
+ end
41
+
42
+ end
43
+
44
+ def testing_framework
45
+ @testing_framework ||= TestingFramework.new
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,23 @@
1
+ module RailsTemplater
2
+ class TestingFramework
3
+
4
+ DEFAULT = :rspec
5
+ SUPPORTED_TYPES = [:rspec, :test_unit]
6
+
7
+ def type
8
+ @type || DEFAULT
9
+ end
10
+
11
+ def type=(value)
12
+ raise NotSupportedError unless SUPPORTED_TYPES.include?(value)
13
+ @type ||= value
14
+ end
15
+
16
+ SUPPORTED_TYPES.each do |type|
17
+ define_method "#{type}?" do
18
+ self.type == type
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsTemplater
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,15 @@
1
+ module Rails
2
+ module Generators
3
+ module Actions
4
+
5
+ def templater
6
+ @templater ||= RailsTemplater::Templater.new
7
+ end
8
+
9
+ def execute_post_bundler_strategies
10
+ templater.post_bundler_strategies.each {|strategy| strategy.call }
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ gem 'sqlite3-ruby', :require => 'sqlite3'
2
+
3
+ gsub_file 'config/application.rb', '# require "active_record/railtie"', 'require "active_record/railtie"'
4
+ create_file 'config/database.yml', templater.load_template('config/database.yml', 'active_record')
5
+ run 'cp config/database.yml config/database.yml.example'
@@ -0,0 +1,37 @@
1
+ if yes?("\n[Integration Testing] Would you like to add integration testing with Cucumber? [y|n]: ", Thor::Shell::Color::BLUE)
2
+
3
+ gem 'capybara', '0.4.0', :group => :test
4
+ gem 'cucumber-rails', :group => :test
5
+ gem 'launchy', :group => :test
6
+
7
+ cucumber_generate_command = "cucumber:install --capybara"
8
+ cucumber_generate_command << ' --skip-database' if templater.orm.mongoid?
9
+ cucumber_generate_command << ' --rspec' if templater.testing_framework.rspec?
10
+ cucumber_generate_command << ' --testunit' if templater.testing_framework.test_unit?
11
+
12
+ templater.post_bundler do
13
+ generate cucumber_generate_command
14
+
15
+ gsub_file 'features/support/env.rb',
16
+ "require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript", ''
17
+
18
+ inject_into_file "features/support/env.rb",
19
+ "\nCapybara.save_and_open_page_path = 'tmp/capybara/'",
20
+ :after => 'Capybara.default_selector = :css'
21
+
22
+ if templater.testing_framework.rspec? && templater.fixture_replacement.factory_girl?
23
+ inject_into_file "features/support/env.rb", templater.load_snippet("factory_girl", 'cucumber'), :after => 'ActionController::Base.allow_rescue = false'
24
+ end
25
+
26
+ # Mongoid truncation strategy
27
+ if templater.orm.mongoid?
28
+ create_file 'features/support/hooks.rb', templater.load_template('features/support/hooks.rb', 'mongoid')
29
+
30
+ # Compliment to factory_girl step definitions
31
+ if templater.fixture_replacement.factory_girl?
32
+ create_file 'features/step_definitions/mongoid_steps.rb', templater.load_template('features/step_definitions/mongoid_steps.rb', 'mongoid')
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -4,14 +4,11 @@ remove_file "public/index.html"
4
4
  remove_file "public/robots.txt"
5
5
  remove_file "public/images/rails.png"
6
6
 
7
+ # Create project files
7
8
  create_file 'README'
8
9
  create_file 'log/.gitkeep'
9
10
  create_file 'tmp/.gitkeep'
10
11
 
11
- gsub_file 'config/application.rb', 'require "rails/test_unit/railtie"', '# require "rails/test_unit/railtie"'
12
-
13
12
  get "http://html5shiv.googlecode.com/svn/trunk/html5.js", "public/javascripts/html5.js"
14
13
 
15
- git :init
16
-
17
- append_file '.gitignore', load_template('gitignore','git')
14
+ apply templater.recipe('git')
@@ -0,0 +1,11 @@
1
+ if templater.testing_framework.rspec?
2
+ say("\nReplacing Fixtures with FactoryGirl\n", Thor::Shell::Color::YELLOW)
3
+ gem 'factory_girl_rails', '1.1.beta1', :group => :test
4
+
5
+ templater.post_bundler do
6
+ inject_into_file 'spec/spec_helper.rb', "\nrequire 'factory_girl'", :after => "require 'rspec/rails'"
7
+
8
+ environment templater.load_snippet('generator', 'factory_girl')
9
+ directory File.expand_path('./../../generators', __FILE__), 'lib/generators'
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ git :init
2
+
3
+ append_file '.gitignore', templater.load_template('gitignore','git')
@@ -0,0 +1,7 @@
1
+ if yes?("\n[Template Engine] Would you like use Haml for your view templates? [y|n]: ", Thor::Shell::Color::BLUE)
2
+ gem 'haml'
3
+ gem "haml-rails"
4
+
5
+ remove_file 'app/views/layouts/application.html.erb'
6
+ create_file 'app/views/layouts/application.html.haml', templater.load_template('app/views/layouts/application.html.haml','haml')
7
+ end
@@ -0,0 +1,18 @@
1
+ say "\nWhich JavaScript Framework would you like to use?\n", Thor::Shell::Color::BLUE
2
+
3
+ javascript_framework_options = {
4
+ 'Option' => 'JavaScript Framework',
5
+ '1' => 'jquery',
6
+ '2' => 'Prototype'
7
+ }
8
+
9
+ print_table javascript_framework_options.to_a, :ident => 4
10
+
11
+ javascript_framework_selection = ask("\nOption: ", Thor::Shell::Color::BLUE)
12
+ if javascript_framework_selection.present?
13
+ templater.javascript_framework.type = javascript_framework_options[javascript_framework_selection].underscore.to_sym
14
+ end
15
+
16
+ $stdout << "\n\n"
17
+
18
+ apply templater.recipe('jquery') if templater.javascript_framework.jquery?
@@ -0,0 +1,10 @@
1
+ say("\nReplacing Prototype with JQuery as your JavaScript Framework\n", Thor::Shell::Color::YELLOW )
2
+
3
+ gem 'jquery-rails'
4
+
5
+ remove_file 'public/javascripts/rails.js'
6
+ gsub_file 'config/application.rb', /(config.action_view.javascript_expansions\[:defaults\] = %w\(\))/, '# \1'
7
+
8
+ templater.post_bundler do
9
+ generate 'jquery:install'
10
+ end