enginex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright 2010 José Valim http://blog.plataformatec.com.br
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ == Enginex
2
+
3
+ This is a tool which creates a Rails 3 Engine with Rakefile, Gemfile and a ready to run test suite on top of a vendored Rails application.
4
+
5
+ Enginex is going to be used in José Valim's upcoming book for Rails 3.
6
+
7
+ == Usage
8
+
9
+ $ enginex ENGINE_NAME
10
+
11
+ == Bugs and Feedback
12
+
13
+ If you discover any bugs, feel free to send me a message or create an issue on GitHub tracker:
14
+
15
+ http://github.com/josevalim
16
+ http://github.com/josevalim/enginex/issues
17
+
18
+ MIT License. Copyright 2010 José Valim. http://blog.plataformatec.com.br
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require File.join(File.dirname(__FILE__), 'lib', 'enginex')
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/*_test.rb'
11
+ t.verbose = true
12
+ end
13
+
14
+ Rake::RDocTask.new(:rdoc) do |rdoc|
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = 'Enginex'
17
+ rdoc.options << '--line-numbers' << '--inline-source'
18
+ rdoc.rdoc_files.include('README.rdoc')
19
+ rdoc.rdoc_files.include('lib/**/*.rb')
20
+ end
21
+
22
+ begin
23
+ require 'jeweler'
24
+ Jeweler::Tasks.new do |s|
25
+ s.name = "enginex"
26
+ s.version = Enginex::VERSION
27
+ s.summary = "Creates a Rails 3 engine with Rakefile, Gemfile and running tests"
28
+ s.email = "jose.valim@plataformatec.com.br"
29
+ s.homepage = "http://github.com/josevalim/enginex"
30
+ s.description = "Creates a Rails 3 engine with Rakefile, Gemfile and running tests"
31
+ s.authors = ['José Valim']
32
+ s.files = FileList["[A-Z]*", "lib/**/*"]
33
+ s.bindir = "bin"
34
+ s.executables = %w(enginex)
35
+ s.add_dependency("thor", "~> 0.13.0")
36
+ s.add_dependency("bundler", "~> 0.9.0")
37
+ s.add_dependency("rails", "~> 3.0.0")
38
+ s.add_dependency("rake", "~> 0.8")
39
+ end
40
+
41
+ Jeweler::GemcutterTasks.new
42
+ rescue LoadError
43
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
44
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'enginex'
5
+ Enginex.start
@@ -0,0 +1,119 @@
1
+ require "thor/group"
2
+ require "active_support"
3
+ require "active_support/version"
4
+ require "active_support/core_ext/string"
5
+
6
+ require "rails/generators"
7
+ require "generators/rails/app/app_generator"
8
+
9
+ # TODO Remove webrat hack file
10
+ # TODO Remove Rails 3 application hack
11
+ class Enginex < Thor::Group
12
+ VERSION = "0.1.0".freeze
13
+
14
+ include Thor::Actions
15
+ check_unknown_options!
16
+
17
+ def self.source_root
18
+ @_source_root ||= File.expand_path('../templates', __FILE__)
19
+ end
20
+
21
+ def self.say_step(message)
22
+ @step = (@step || 0) + 1
23
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
24
+ def step_#{@step}
25
+ #{"puts" if @step > 1}
26
+ say_status "STEP #{@step}", #{message.inspect}
27
+ end
28
+ METHOD
29
+ end
30
+
31
+ argument :path, :type => :string,
32
+ :desc => "Path to the engine to be created"
33
+
34
+ desc "Creates a Rails 3 engine with Rakefile, Gemfile and running tests."
35
+
36
+ say_step "Creating gem skeleton"
37
+
38
+ def create_root
39
+ self.destination_root = File.expand_path(path, destination_root)
40
+ set_accessors!
41
+
42
+ directory "root", "."
43
+ FileUtils.cd(destination_root)
44
+ end
45
+
46
+ def copy_gitignore
47
+ copy_file "gitignore", ".gitignore"
48
+ end
49
+
50
+ say_step "Vendoring Rails application at test/dummy"
51
+
52
+ def invoke_rails_app_generator
53
+ invoke Rails::Generators::AppGenerator,
54
+ [ File.expand_path("test/dummy", destination_root) ]
55
+ end
56
+
57
+ say_step "Configuring Rails application"
58
+
59
+ def change_config_files
60
+ store_application_definition!
61
+ template "rails/boot.rb", "test/dummy/config/boot.rb", :force => true
62
+ template "rails/application.rb", "test/dummy/config/application.rb", :force => true
63
+ end
64
+
65
+ def rails_3_beta_fix
66
+ inject_into_class "test/dummy/config/application.rb", "Application",
67
+ " config.root = File.expand_path('../..', __FILE__)\n\n"
68
+ end
69
+
70
+ say_step "Removing unneeded files"
71
+
72
+ def remove_uneeded_rails_files
73
+ inside "test/dummy" do
74
+ remove_file "db/seeds.rb"
75
+ remove_file "doc"
76
+ remove_file "Gemfile"
77
+ remove_file "lib/tasks"
78
+ remove_file "public/images/rails.png"
79
+ remove_file "public/index.html"
80
+ remove_file "public/robots.txt"
81
+ remove_file "Rakefile"
82
+ remove_file "README"
83
+ remove_file "test"
84
+ remove_file "vendor"
85
+ end
86
+ end
87
+
88
+ protected
89
+
90
+ def self.banner
91
+ self_task.formatted_usage(self, false)
92
+ end
93
+
94
+ def application_definition
95
+ @application_definition ||= begin
96
+ contents = File.read(File.expand_path("test/dummy/config/application.rb", destination_root))
97
+ contents[(contents.index("module Dummy"))..-1]
98
+ end
99
+ end
100
+ alias :store_application_definition! :application_definition
101
+
102
+ # Cache accessors since we are changing the directory
103
+ def set_accessors!
104
+ self.name
105
+ self.class.source_root
106
+ end
107
+
108
+ def name
109
+ @name ||= File.basename(destination_root)
110
+ end
111
+
112
+ def camelized
113
+ @camelized ||= name.camelize
114
+ end
115
+
116
+ def underscored
117
+ @underscored ||= name.underscore
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ .bundle/
2
+ db/*.sqlite3
3
+ log/*.log
4
+ tmp/**/*
5
+ pkg/
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "active_model/railtie"
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_view/railtie"
7
+ require "action_mailer/railtie"
8
+
9
+ Bundler.require
10
+ require "<%= underscored %>"
11
+
12
+ <%= application_definition %>
@@ -0,0 +1,9 @@
1
+ begin
2
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler.setup
7
+ end
8
+
9
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,9 @@
1
+ source "http://gemcutter.org"
2
+
3
+ gem "rails", "<%= ActiveSupport::VERSION::STRING %>"
4
+ gem "webrat", "0.7"
5
+ gem "sqlite3-ruby", :require => "sqlite3"
6
+
7
+ if RUBY_VERSION < '1.9'
8
+ gem "ruby-debug", ">= 0.10.3"
9
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: UTF-8
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/gempackagetask'
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'lib'
9
+ t.libs << 'test'
10
+ t.pattern = 'test/**/*_test.rb'
11
+ t.verbose = true
12
+ end
13
+
14
+ Rake::RDocTask.new(:rdoc) do |rdoc|
15
+ rdoc.rdoc_dir = 'rdoc'
16
+ rdoc.title = '<%= camelized %>'
17
+ rdoc.options << '--line-numbers' << '--inline-source'
18
+ rdoc.rdoc_files.include('README.rdoc')
19
+ rdoc.rdoc_files.include('lib/**/*.rb')
20
+ end
21
+
22
+ spec = Gem::Specification.new do |s|
23
+ s.name = "<%= underscored %>"
24
+ s.summary = "Insert <%= camelized %> summary."
25
+ s.description = "Insert <%= camelized %> description."
26
+ s.files = FileList["[A-Z]*", "lib/**/*"]
27
+ s.version = "0.0.1"
28
+ end
29
+
30
+ Rake::GemPackageTask.new(spec) do |pkg|
31
+ end
32
+
33
+ desc "Install the gem #{spec.name}-#{spec.version}.gem"
34
+ task :install do
35
+ system("gem install pkg/#{spec.name}-#{spec.version}.gem --no-ri --no-rdoc")
36
+ end
@@ -0,0 +1,2 @@
1
+ module <%= camelized %>
2
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= camelized %>Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, <%= camelized %>
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class NagivationTest < ActionController::IntegrationTest
4
+ test "truth" do
5
+ assert_kind_of Dummy::Application, Rails.application
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # Configure Rails Envinronment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+
7
+ ActionMailer::Base.delivery_method = :test
8
+ ActionMailer::Base.perform_deliveries = true
9
+ ActionMailer::Base.default_url_options[:host] = "test.com"
10
+
11
+ $:.unshift File.dirname(__FILE__)
12
+
13
+ Webrat.configure do |config|
14
+ config.mode = :rails
15
+ config.open_error_files = false
16
+ end
17
+
18
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
@@ -0,0 +1,31 @@
1
+ require 'webrat/core/elements/field'
2
+
3
+ module Webrat
4
+ Field.class_eval do
5
+ def parse_rails_request_params(params)
6
+ Rack::Utils.parse_nested_query(params)
7
+ end
8
+ end
9
+ end
10
+
11
+ module ActionController #:nodoc:
12
+ IntegrationTest.class_eval do
13
+ include Webrat::Methods
14
+ include Webrat::Matchers
15
+
16
+ # The Rails version of within supports passing in a model and Webrat
17
+ # will apply a scope based on Rails' dom_id for that model.
18
+ #
19
+ # Example:
20
+ # within User.last do
21
+ # click_link "Delete"
22
+ # end
23
+ def within(selector_or_object, &block)
24
+ if selector_or_object.is_a?(String)
25
+ super
26
+ else
27
+ super('#' + RecordIdentifier.dom_id(selector_or_object), &block)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ require 'test_helper'
2
+
3
+ class EnginexTest < ActiveSupport::TestCase
4
+ test "enginex skeleton" do
5
+ run_enginex do
6
+ # Root
7
+ assert_file "Rakefile"
8
+ assert_file "Gemfile", /gem "rails"/, /gem "webrat"/
9
+ assert_file ".gitignore", /\.bundle/, /db\/\*\.sqlite3/
10
+
11
+ # Lib
12
+ assert_file "lib/demo_engine.rb", /module DemoEngine\nend/
13
+
14
+ # Test
15
+ assert_file "test/test_helper.rb"
16
+ assert_directory "test/support/"
17
+ assert_directory "test/integration/"
18
+
19
+ assert_file "test/demo_engine_test.rb", /assert_kind_of Module, DemoEngine/
20
+ assert_file "test/integration/navigation_test.rb", /assert_kind_of Dummy::Application, Rails.application/
21
+
22
+ # Vendored Rails
23
+ assert_file "test/dummy/config/application.rb"
24
+ end
25
+ end
26
+
27
+ test "enginex rakefile can create a gem" do
28
+ run_enginex do
29
+ execute("rake gem")
30
+ assert_file "pkg/demo_engine-0.0.1.gem"
31
+ end
32
+ end
33
+
34
+ test "enginex can run tests" do
35
+ run_enginex do
36
+ assert_match /2 tests, 2 assertions, 0 failures, 0 errors/, execute("rake test")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,77 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ gem "test-unit"
5
+ rescue LoadError
6
+ end
7
+
8
+ ENV["RAILS_ENV"] ||= "test"
9
+ require 'test/unit'
10
+ require 'active_support'
11
+ require 'active_support/test_case'
12
+
13
+ $counter = 0
14
+ LIB_PATH = File.expand_path('../../lib', __FILE__)
15
+ BIN_PATH = File.expand_path('../../bin/enginex', __FILE__)
16
+
17
+ DESTINATION_ROOT = File.expand_path('../enginex', __FILE__)
18
+ FileUtils.rm_rf(DESTINATION_ROOT)
19
+
20
+ $:.unshift LIB_PATH
21
+ require 'enginex'
22
+
23
+
24
+ class ActiveSupport::TestCase
25
+ def run_enginex
26
+ $counter += 1
27
+ `ruby -I#{LIB_PATH} -rrubygems #{BIN_PATH} #{destination_root}`
28
+ yield
29
+ FileUtils.rm_rf(File.dirname(destination_root))
30
+ rescue Exception => e
31
+ puts "Error happened. #{destination_root.inspect} left for inspecting."
32
+ raise e
33
+ end
34
+
35
+ def destination_root
36
+ File.join(DESTINATION_ROOT, $counter.to_s, "demo_engine")
37
+ end
38
+
39
+ def capture(stream)
40
+ begin
41
+ stream = stream.to_s
42
+ eval "$#{stream} = StringIO.new"
43
+ yield
44
+ eval("$#{stream}").string
45
+ ensure
46
+ eval("$#{stream} = #{stream.upcase}")
47
+ end
48
+ end
49
+ alias :silence :capture
50
+
51
+ def assert_file(relative, *contents)
52
+ absolute = File.expand_path(relative, destination_root)
53
+ assert File.exists?(absolute), "Expected file #{relative.inspect} to exist, but does not"
54
+
55
+ read = File.read(absolute) if block_given? || !contents.empty?
56
+ yield read if block_given?
57
+
58
+ contents.each do |content|
59
+ assert_match content, read
60
+ end
61
+ end
62
+ alias :assert_directory :assert_file
63
+
64
+ def assert_no_file(relative)
65
+ absolute = File.expand_path(relative, destination_root)
66
+ assert !File.exists?(absolute), "Expected file #{relative.inspect} to not exist, but does"
67
+ end
68
+ alias :assert_no_directory :assert_no_file
69
+
70
+ def execute(command)
71
+ current_path = Dir.pwd
72
+ FileUtils.cd destination_root
73
+ `#{command}`
74
+ ensure
75
+ FileUtils.cd current_path
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enginex
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - "Jos\xC3\xA9 Valim"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-25 00:00:00 +01:00
13
+ default_executable: enginex
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 0.13.0
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rails
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 3.0.0
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: rake
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: "0.8"
54
+ version:
55
+ description: Creates a Rails 3 engine with Rakefile, Gemfile and running tests
56
+ email: jose.valim@plataformatec.com.br
57
+ executables:
58
+ - enginex
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - README.rdoc
63
+ files:
64
+ - MIT-LICENSE
65
+ - README.rdoc
66
+ - Rakefile
67
+ - lib/enginex.rb
68
+ - lib/templates/gitignore
69
+ - lib/templates/rails/application.rb
70
+ - lib/templates/rails/boot.rb
71
+ - lib/templates/root/Gemfile.tt
72
+ - lib/templates/root/Rakefile.tt
73
+ - lib/templates/root/lib/%underscored%.rb.tt
74
+ - lib/templates/root/test/%underscored%_test.rb.tt
75
+ - lib/templates/root/test/integration/navigation_test.rb.tt
76
+ - lib/templates/root/test/test_helper.rb
77
+ - lib/templates/root/test/webrat/integrations/rails.rb
78
+ has_rdoc: true
79
+ homepage: http://github.com/josevalim/enginex
80
+ licenses: []
81
+
82
+ post_install_message:
83
+ rdoc_options:
84
+ - --charset=UTF-8
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: "0"
92
+ version:
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: "0"
98
+ version:
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.5
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Creates a Rails 3 engine with Rakefile, Gemfile and running tests
106
+ test_files:
107
+ - test/enginex_test.rb
108
+ - test/test_helper.rb