Created
January 9, 2015 02:23
-
-
Save bcroesch/263e345ecc26bee8db5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component_name = Rails.root.to_s.split("/")[-3] | |
component_root = Rails.root.to_s.gsub("spec/dummy", "") | |
gemspec = <<-EOS | |
s.add_development_dependency \"rspec-rails\" | |
s.test_files = Dir["spec/**/*"] | |
EOS | |
inject_into_file "#{component_root}/#{component_name}.gemspec", | |
gemspec, | |
after: "s.add_development_dependency \"sqlite3\"\n" | |
engine_config = <<-EOS | |
config.autoload_paths += Dir["#{config.root}/lib/**/"] | |
config.generators do |g| | |
g.test_framework :rspec, fixture: false | |
g.fixture_replacement :factory_girl, dir: 'spec/factories' | |
end | |
initializer :append_migrations do |app| | |
unless app.root.to_s.match root.to_s | |
config.paths["db/migrate"].expanded.each do |expanded_path| | |
app.config.paths["db/migrate"] << expanded_path | |
end | |
end | |
end | |
EOS | |
inject_into_file "#{component_root}/lib/#{component_name}/engine.rb", | |
engine_config, | |
after: "isolate_namespace #{component_name.camelize}" | |
run "bundle install" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rails plugin new ./components/$@ --mountable -T --dummy-path=spec/dummy | |
cd ./components/$@ | |
bundle exec rake app:rails:template LOCATION=../component_template.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing Ben, I could be misreading your template but wouldn't you need to escape the interpolation on line 17?
config.autoload_paths += Dir["#{config.root}/lib/**/"]
to (or similar)
config.autoload_paths += Dir["\#{config.root}/lib/**/"]