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
@@ -0,0 +1,11 @@
1
+ say("\nReplacing ActiveRecord with Mongoid\n", Thor::Shell::Color::YELLOW )
2
+
3
+ gem 'mongoid', '2.0.0.rc.6'
4
+ gem 'bson_ext', '~> 1.2'
5
+
6
+ gsub_file 'config/application.rb', 'require "active_record/railtie"', '# require "active_record/railtie"'
7
+
8
+ templater.post_bundler do
9
+ generate 'mongoid:config'
10
+ run 'cp config/mongoid.yml config/mongoid.yml.example'
11
+ end
@@ -0,0 +1,19 @@
1
+ say "\nWhich ORM/ODM would you like to use?\n", Thor::Shell::Color::BLUE
2
+
3
+ orm_options = {
4
+ 'Option' => 'ORM/ODM',
5
+ '1' => 'Mongoid',
6
+ '2' => 'ActiveRecord'
7
+ }
8
+
9
+ print_table orm_options.to_a, :ident => 4
10
+
11
+ orm_selection = ask("\nOption: ", Thor::Shell::Color::BLUE)
12
+ if orm_selection.present?
13
+ templater.orm.type = orm_options[orm_selection].underscore.to_sym
14
+ end
15
+
16
+ $stdout << "\n\n"
17
+
18
+ apply templater.recipe('mongoid') if templater.orm.mongoid?
19
+ apply templater.recipe('active_record') if templater.orm.active_record?
@@ -0,0 +1,12 @@
1
+ if templater.orm.mongoid?
2
+ gem 'remarkable_activemodel', '>=4.0.0.alpha4', :group => :test
3
+ gem 'remarkable_mongoid', :group => :test
4
+ require_remarkable = "\nrequire 'remarkable/active_model'\nrequire 'remarkable/mongoid'"
5
+ elsif templater.orm.active_record?
6
+ gem 'remarkable_activerecord', '>=4.0.0.alpha4', :group => :test
7
+ require_remarkable = "\nrequire 'remarkable/active_record'"
8
+ end
9
+
10
+ templater.post_bundler do
11
+ inject_into_file 'spec/spec_helper.rb', require_remarkable, :after => "require 'rspec/rails'"
12
+ end
@@ -0,0 +1,22 @@
1
+ say("\nReplacing TestUnit with RSpec as your Testing Framework\n", Thor::Shell::Color::YELLOW )
2
+
3
+ gem 'rspec-rails', '>= 2.4.1', :group => [:development]
4
+
5
+ remove_dir 'test'
6
+ gsub_file 'config/application.rb', 'require "rails/test_unit/railtie"', '# require "rails/test_unit/railtie"'
7
+
8
+ templater.post_bundler do
9
+ generate 'rspec:install'
10
+
11
+ spec_helper_path = 'spec/spec_helper.rb'
12
+
13
+ gsub_file spec_helper_path, 'config.fixture_path = "#{::Rails.root}/spec/fixtures"', ''
14
+
15
+ if templater.orm.mongoid?
16
+ gsub_file spec_helper_path, /(config.use_transactional_fixtures = true)/, '# \1'
17
+ inject_into_file spec_helper_path, templater.load_snippet('mongoid', 'rspec'), :after => "# config.use_transactional_fixtures = true\n"
18
+ end
19
+ end
20
+
21
+ apply(templater.recipe('remarkable')) if yes?("\n\nWould you like to add Remarkable RSpec matchers? [y|n]: ", Thor::Shell::Color::BLUE)
22
+ apply templater.recipe('factory_girl')
@@ -0,0 +1,48 @@
1
+ if yes?("\n[Stylesheets] Would you like to use Sass for Syntactically Awesome Stylesheets? [y|n]: ", Thor::Shell::Color::BLUE)
2
+
3
+ # gem 'sass' # TODO: Wait until Sass 3.1 is released
4
+ gem 'haml'
5
+
6
+ if yes?("\nWould you like to use Compass? [y|n]: ", Thor::Shell::Color::BLUE)
7
+ design_options = {
8
+ 'Option' => 'Design Framework',
9
+ '1' => 'Compass',
10
+ '2' => 'Compass with blueprint semantic',
11
+ '3' => 'Compass with blueprint basic'
12
+ }
13
+
14
+ print_table design_options.to_a, :ident => 4
15
+ design_selection = ask("\nOption: ", Thor::Shell::Color::BLUE)
16
+
17
+ design_framework = case design_selection
18
+ when "1"
19
+ :compass
20
+ when "2"
21
+ :compass_blueprint_semantic
22
+ when "3"
23
+ :compass_blueprint
24
+ else
25
+ :none
26
+ end
27
+
28
+ unless design_framework == :none
29
+ gem 'compass'
30
+
31
+ compass_sass_dir = "app/stylesheets"
32
+ compass_css_dir = "public/stylesheets/compiled"
33
+ blueprint_option = case design_framework
34
+ when :compass_blueprint
35
+ "--using blueprint/basic"
36
+ when :compass_blueprint_semantic
37
+ "--using blueprint/semantic"
38
+ end
39
+
40
+ compass_command = "compass init rails . #{blueprint_option} --css-dir=#{compass_css_dir} --sass-dir=#{compass_sass_dir} "
41
+
42
+ templater.post_bundler do
43
+ run compass_command
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ gsub_file 'config/application.rb', '# require "rails/test_unit/railtie"', 'require "rails/test_unit/railtie"'
@@ -0,0 +1,19 @@
1
+ say "\nWhich Testing Framework would you like to use?\n", Thor::Shell::Color::BLUE
2
+
3
+ testing_framework_options = {
4
+ 'Option' => 'Testing Framework',
5
+ '1' => 'rspec',
6
+ '2' => 'TestUnit'
7
+ }
8
+
9
+ print_table testing_framework_options.to_a, :ident => 4
10
+
11
+ testing_framework_selection = ask("\nOption: ", Thor::Shell::Color::BLUE)
12
+ if testing_framework_selection.present?
13
+ templater.testing_framework.type = testing_framework_options[testing_framework_selection].underscore.to_sym
14
+ end
15
+
16
+ $stdout << "\n\n"
17
+
18
+ apply templater.recipe('rspec') if templater.testing_framework.rspec?
19
+ apply templater.recipe('test_unit') if templater.testing_framework.test_unit?
@@ -0,0 +1,19 @@
1
+ $LOAD_PATH.unshift(File.expand_path('./../../', __FILE__))
2
+
3
+ require 'rails_templater'
4
+ require File.join(File.dirname(__FILE__), 'core_ext.rb')
5
+
6
+ %w(default orm testing_framework javascript_framework haml sass cucumber).each do |recipe|
7
+ apply templater.recipe(recipe)
8
+ end
9
+
10
+ say("\nInitial generation complete\n", Thor::Shell::Color::YELLOW)
11
+
12
+ say("\nBeginning bundle install\n", Thor::Shell::Color::YELLOW)
13
+ run 'bundle install'
14
+ say("\nbundle install complete\n", Thor::Shell::Color::YELLOW)
15
+
16
+ execute_post_bundler_strategies
17
+
18
+ git :add => "."
19
+ git :commit => "-m 'Initial commit'"
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -22,4 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.require_path = 'lib'
23
23
 
24
24
  s.add_dependency("thor", ["~> 0.14.6"])
25
+
26
+ s.add_development_dependency("rspec", ["~> 2.4"])
25
27
  end
@@ -0,0 +1 @@
1
+ Foo Bar
File without changes
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater::FixtureReplacement do
4
+
5
+ context "Fixture Replacement type has not been set" do
6
+ its(:type) { should == :factory_girl }
7
+ end
8
+
9
+ context "Fxiture Replacement type has been set to FactoryGirl" do
10
+
11
+ before(:each) do
12
+ subject.type = :factory_girl
13
+ end
14
+
15
+ it { should be_factory_girl }
16
+
17
+ end
18
+
19
+ describe "#type" do
20
+
21
+ it "allows setting of only supported Fixture Replacements" do
22
+ expect {
23
+ subject.type = :fixture
24
+ }.to raise_error(RailsTemplater::NotSupportedError)
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater::JavaScriptFramework do
4
+
5
+ context "JavaScript Framework type has not been set" do
6
+ its(:type) { should == :jquery }
7
+ end
8
+
9
+ context "JavaScript Framework type has been set to jQuery" do
10
+
11
+ before(:each) do
12
+ subject.type = :jquery
13
+ end
14
+
15
+ it { should be_jquery }
16
+
17
+ end
18
+
19
+ context "JavaScript Framework type has been set to Prototype" do
20
+
21
+ before(:each) do
22
+ subject.type = :prototype
23
+ end
24
+
25
+ it { should be_prototype }
26
+
27
+ end
28
+
29
+ it "only sets type to supported JavaScript Frameworks" do
30
+ expect{
31
+ subject.type = :random
32
+ }.to raise_error(RailsTemplater::NotSupportedError)
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater::Orm do
4
+
5
+ it "defaults to Mongoid" do
6
+ subject.type.should == :mongoid
7
+ end
8
+
9
+ context "ORM type is ActiveRecord" do
10
+
11
+ before(:each) do
12
+ subject.type = :active_record
13
+ end
14
+
15
+ it { should be_active_record }
16
+
17
+ end
18
+
19
+ context "ORM type is Mongoid" do
20
+
21
+ before(:each) do
22
+ subject.type = :mongoid
23
+ end
24
+
25
+ it { should be_mongoid }
26
+
27
+ end
28
+
29
+ it "only sets type to supported ORMs" do
30
+ expect{
31
+ subject.type = :mongo_mapper
32
+ }.to raise_error(RailsTemplater::NotSupportedError)
33
+ end
34
+
35
+
36
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater::Templater do
4
+
5
+ let(:group) { 'sample' }
6
+
7
+ its(:fixture_replacement) { should be_kind_of(RailsTemplater::FixtureReplacement) }
8
+ its(:javascript_framework) { should be_kind_of(RailsTemplater::JavaScriptFramework) }
9
+ its(:orm) { should be_kind_of(RailsTemplater::Orm) }
10
+ its(:testing_framework) { should be_kind_of(RailsTemplater::TestingFramework) }
11
+
12
+ it "generates a recipe path based on a name" do
13
+ subject.recipe("mongoid").should == File.expand_path('recipes/mongoid.rb', TEMPLATE_FRAMEWORK_PATH)
14
+ end
15
+
16
+ it "generates a snippet path" do
17
+ subject.snippet_path("cucumber").should == File.expand_path('snippets/cucumber', TEMPLATE_FRAMEWORK_PATH)
18
+ end
19
+
20
+ it "generates a template path" do
21
+ subject.template_path("haml").should == File.expand_path('templates/haml', TEMPLATE_FRAMEWORK_PATH)
22
+ end
23
+
24
+ describe "#load_snippet" do
25
+
26
+ let(:snippet_name) { 'sample_snippet' }
27
+
28
+ before(:each) do
29
+ subject.stub(:snippet_path) { FIXTURE_PATH }
30
+ end
31
+
32
+ it "loads a snippet" do
33
+ subject.load_snippet(snippet_name, group).should == load_fixture(snippet_name)
34
+ end
35
+
36
+ end
37
+
38
+ describe "#load_template" do
39
+
40
+ let(:template_name) { 'sample_template.rb' }
41
+
42
+ before(:each) do
43
+ subject.stub(:template_path) { FIXTURE_PATH }
44
+ end
45
+
46
+ it "loads a template" do
47
+ subject.load_template(template_name, group).should == load_fixture(template_name)
48
+ end
49
+
50
+ end
51
+
52
+ describe "#post_bundler" do
53
+
54
+ it "adds blocks to post_bundler_strategies" do
55
+ subject.post_bundler do
56
+ "Hi"
57
+ end
58
+ subject.post_bundler_strategies.should have(1).item
59
+ result = subject.post_bundler_strategies.first.call
60
+ result.should == 'Hi'
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater::TestingFramework do
4
+
5
+ it "defaults to RSpec" do
6
+ subject.type.should == :rspec
7
+ end
8
+
9
+ context "Testing Framework type is set to RSpec" do
10
+
11
+ before(:each) do
12
+ subject.type = :rspec
13
+ end
14
+
15
+ it { should be_rspec }
16
+
17
+ end
18
+
19
+ context "Testing Framework type is set to TestUnit" do
20
+
21
+ before(:each) do
22
+ subject.type = :test_unit
23
+ end
24
+
25
+ it { should be_test_unit }
26
+
27
+ end
28
+
29
+ it "only sets type to supported Test Frameworks" do
30
+ expect{
31
+ subject.type = :random
32
+ }.to raise_error(RailsTemplater::NotSupportedError)
33
+ end
34
+
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsTemplater do
4
+
5
+ subject { RailsTemplater }
6
+
7
+ its(:template_runner) { should == File.expand_path('template_runner.rb', TEMPLATE_FRAMEWORK_PATH)}
8
+
9
+ end
@@ -0,0 +1,20 @@
1
+ begin
2
+ require 'bundler'
3
+ Bundler.setup(:default, :development)
4
+ rescue LoadError => e
5
+ # Fall back on doing an unlocked resolve at runtime.
6
+ STDERR.puts e.message
7
+ STDERR.puts "Try running `bundle install`."
8
+ exit!
9
+ end
10
+
11
+ require 'rails_templater'
12
+ require 'rspec'
13
+
14
+ # # Requires supporting files with custom matchers and macros, etc,
15
+ # in ./support/ and its subdirectories.
16
+ Dir[File.join(File.dirname(__FILE__),'/support/**/*.rb')].each {|f| require f}
17
+
18
+ RSpec.configure do |config|
19
+ config.mock_with :rspec
20
+ end