Permalink
Browse files

Modernize

* Use bundler
* Update support for Rails 3.2
* Remove support for Rails 2.x
* Use aruba and thin
* Remove generated rails_root
  • Loading branch information...
jferris committed Apr 29, 2013
1 parent 071d8f1 commit 26cb4324721ee57d9c8855b079fcee920c4d0b95
Showing with 369 additions and 506 deletions.
  1. +1 −0 .gitignore
  2. +2 −0 Gemfile
  3. +15 −73 Rakefile
  4. +18 −9 effigy.gemspec
  5. +13 −17 features/{rails2_generators.feature → rails_generators.feature}
  6. +35 −33 features/{rails2_integration.feature → rails_template_integration.feature}
  7. +0 −48 features/step_definitions/common_rails_steps.rb
  8. +0 −14 features/step_definitions/rails2_steps.rb
  9. +37 −0 features/step_definitions/rails_steps.rb
  10. +7 −0 features/support/env.rb
  11. +90 −0 features/support/rails_server.rb
  12. +0 −36 features/support/terminal.rb
  13. +0 −125 features/templates/boot.rb.template
  14. +0 −21 features/templates/preinitializer.rb.template
  15. +0 −7 features/templates/rails2_request.template
  16. +0 −81 generators/effigy_view/effigy_view_generator.rb
  17. +0 −7 generators/effigy_view/templates/layout_template.erb
  18. +0 −3 generators/effigy_view/templates/template.erb
  19. +4 −0 lib/effigy.rb
  20. +4 −2 lib/effigy/rails.rb
  21. +36 −20 lib/effigy/rails/template_handler.rb
  22. +0 −1 lib/effigy/rails/view.rb
  23. BIN lib/generators/effigy/.base.rb.swo
  24. +18 −0 lib/generators/effigy/base.rb
  25. BIN lib/generators/effigy/view/.view_generator.rb.swo
  26. +7 −0 lib/generators/effigy/view/templates/layout_template.erb
  27. +2 −2 {generators/effigy_view → lib/generators/effigy/view}/templates/layout_view.erb
  28. +3 −0 lib/generators/effigy/view/templates/template.erb
  29. +2 −2 {generators/effigy_view → lib/generators/effigy/view}/templates/view.erb
  30. +73 −0 lib/generators/effigy/view/view_generator.rb
  31. +0 −1 rails/init.rb
  32. +2 −4 spec/spec_helper.rb
View
@@ -4,3 +4,4 @@ pkg
tmp
doc
.yardoc
Gemfile.lock
View
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gemspec
View
@@ -1,97 +1,39 @@
require 'rubygems'
require 'rake'
require 'rake/gempackagetask'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'cucumber/rake/task'
require 'reek/rake/task'
require 'yard'
desc 'Default: run the specs, features, and metrics.'
task :default => [:spec, :cucumber, :metrics]
task :rails_root do
rails_root = File.join('tmp', 'rails_root')
unless File.exist?(rails_root)
FileUtils.mkdir_p(File.dirname(rails_root))
command = "rails #{rails_root}"
output = `#{command} 2>&1`
if $? == 0
FileUtils.ln_s(FileUtils.pwd, File.join(rails_root, 'vendor', 'plugins'))
else
$stderr.puts "Command failed with status #{$?}:"
$stderr.puts command
$stderr.puts output
end
end
end
begin
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--color', '--format', 'progress']
t.libs = %w(spec)
t.ruby_opts = ['-rrubygems']
end
task :spec => :rails_root
desc "Run all specs individually to ensure that requires are correct"
task :check_requires do
Dir["spec/**/*_spec.rb"].each do |spec_file|
system("spec -cfp #{spec_file}") or raise "Failed while running #{spec_file}"
end
end
rescue LoadError => exception
puts "Missing dependencies for specs"
task :spec do
raise exception
end
RSpec::Core::RakeTask.new do |t|
end
desc "Remove build files"
task :clean do
%w(tmp pkg doc).each do |path|
FileUtils.rm_rf(path)
desc "Run all specs individually to ensure that requires are correct"
task :check_requires do
Dir["spec/**/*_spec.rb"].each do |spec_file|
system("spec -cfp #{spec_file}") or raise "Failed while running #{spec_file}"
end
end
namespace :metrics do
desc "Run reek"
begin
require 'reek/adapters/rake_task'
task :reek do
files = FileList['lib/**/*.rb', 'rails/**/*.rb'].to_a.join(' ')
system("reek -q #{files}")
end
rescue LoadError => exception
puts "Missing dependencies for metrics."
task :reek do
puts exception.inspect
end
task :reek do
files = FileList['lib/**/*.rb', 'rails/**/*.rb'].to_a.join(' ')
system("reek -q #{files}")
end
end
desc "Run all metrics"
task :metrics => ['metrics:reek']
begin
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'rails/**/*.rb']
end
rescue LoadError => exception
puts "Missing dependencies for yard."
task :yard do
raise exception
end
end
eval("$specification = begin; #{IO.read('effigy.gemspec')}; end")
Rake::GemPackageTask.new($specification) do |package|
package.need_zip = true
package.need_tar = true
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'rails/**/*.rb']
end
Cucumber::Rake::Task.new(:cucumber) do |t|
t.fork = true
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress')]
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'progress'), '--tags', '~@wip']
end
View
@@ -1,26 +1,35 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = "effigy"
s.version = "0.4.0"
s.name = 'effigy'
s.version = '0.4.0'
s.authors = ["Joe Ferris"]
s.authors = ['Joe Ferris']
s.date = %q{2010-08-20}
s.description = %q{Define views in Ruby and templates in HTML. Avoid code interpolation or ugly templating languages. Use ids, class names, and semantic structures already present in your documents to produce content.}
s.email = %q{jferris@thoughtbot.com}
s.extra_rdoc_files = [
"LICENSE",
"README.textile"
'LICENSE',
'README.textile'
]
s.files = Dir['[A-Z]*',
'lib/**/*.rb',
'spec/**/*.rb',
'rails/**/*.rb',
'generators/**/*.*']
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.require_paths = ['lib']
s.summary = %q{Effigy provides a view and template framework without a templating language.}
s.test_files = Dir[*['spec/**/*_spec.rb']]
s.add_runtime_dependency(%q<nokogiri>, [">= 1.3"])
s.add_runtime_dependency 'nokogiri', '>= 1.3'
s.add_development_dependency 'aruba'
s.add_development_dependency 'cucumber'
s.add_development_dependency 'rails', '>= 3.2'
s.add_development_dependency 'rake'
s.add_development_dependency 'reek'
s.add_development_dependency 'rspec'
s.add_development_dependency 'thin'
s.add_development_dependency 'yard'
end
@@ -1,20 +1,15 @@
Feature: Generate views in a Rails 2.3 application
Feature: Generate views in a Rails application
Background:
When I generate a new rails 2 application
And I configure the rails 2 preinitializer to use bundler
And I save the following as "Gemfile"
"""
source "http://rubygems.org"
gem 'rails', '2.3.8'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'effigy', :path => '../../', :require => 'effigy/rails'
"""
When I run "bundle lock"
When I run `rails new testapp`
And I cd to "testapp"
And I add "effigy" from this project as a dependency
When I run `bundle install`
@disable-bundler
Scenario: generate a controller view and template
When I run "./script/generate effigy_view users create"
Then the following should be saved as "app/views/users/create.html.effigy"
When I run `bundle exec rails generate effigy:view users create`
Then the file "app/views/users/create.html.effigy" should contain:
"""
class UsersCreateView < Effigy::Rails::View
private
@@ -29,16 +24,17 @@ Feature: Generate views in a Rails 2.3 application
end
end
"""
Then the following should be saved as "app/templates/users/create.html"
Then the file "app/templates/users/create.html" should contain:
"""
<h1>UsersCreateView</h1>
<p>Edit me at app/templates/users/create.html</p>
<p>Edit my view at app/views/users/create.html.effigy</p>
"""
@disable-bundler
Scenario: generate a layout view and template
When I run "./script/generate effigy_view layouts narrow"
Then the following should be saved as "app/views/layouts/narrow.html.effigy"
When I run `bundle exec rails generate effigy:view layouts narrow`
Then the file "app/views/layouts/narrow.html.effigy" should contain:
"""
class NarrowLayout < Effigy::Rails::View
private
@@ -54,7 +50,7 @@ Feature: Generate views in a Rails 2.3 application
end
end
"""
Then the following should be saved as "app/templates/layouts/narrow.html"
Then the file "app/templates/layouts/narrow.html" should contain:
"""
<html>
<body>
@@ -1,19 +1,16 @@
Feature: Integrate with Rails 2.3
Feature: Integrate with Rails templates
Background:
When I generate a new rails 2 application
And I configure the rails 2 preinitializer to use bundler
And I save the following as "Gemfile"
"""
source "http://rubygems.org"
gem 'rails', '2.3.8'
gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'effigy', :path => '../../', :require => 'effigy/rails'
"""
When I run "bundle lock"
When I run `rails new testapp`
And I cd to "testapp"
And I configure my routes to allow global access
And I add "effigy" from this project as a dependency
And I add "thin" from rubygems as a dependency
When I run `bundle install`
Scenario: render a template a reference assigns
When I save the following as "app/controllers/magic_controller.rb"
@disable-bundler
Scenario: render a template and reference assigns
When I write to "app/controllers/magic_controller.rb" with:
"""
class MagicController < ApplicationController
def index
@@ -22,93 +19,98 @@ Feature: Integrate with Rails 2.3
end
end
"""
When I save the following as "app/views/magic/index.html.effigy"
When I write to "app/views/magic/index.html.effigy" with:
"""
class MagicIndexView < Effigy::Rails::View
def transform
text('h1', @spell)
end
end
"""
When I save the following as "app/templates/magic/index.html"
When I write to "app/templates/magic/index.html" with:
"""
<h1 class="success">placeholder title</h1>
"""
When I request "/magic/index"
Then I should see:
When I start the application
And I GET /magic/index
Then the response should contain:
"""
<h1 class="success">hocus pocus</h1>
"""
@disable-bundler
Scenario: render a template within a layout
When I save the following as "app/controllers/magic_controller.rb"
When I write to "app/controllers/magic_controller.rb" with:
"""
class MagicController < ApplicationController
layout 'application'
layout 'example'
end
"""
When I save the following as "app/views/magic/index.html.effigy"
When I write to "app/views/magic/index.html.effigy" with:
"""
class MagicIndexView < Effigy::Rails::View
end
"""
When I save the following as "app/templates/magic/index.html"
When I write to "app/templates/magic/index.html" with:
"""
<h1 class="success">title</h1>
"""
When I save the following as "app/views/layouts/application.html.effigy"
When I write to "app/views/layouts/example.html.effigy" with:
"""
class ApplicationLayout < Effigy::Rails::View
class ExampleLayout < Effigy::Rails::View
def transform
html('body', content_for(:layout))
end
end
"""
When I save the following as "app/templates/layouts/application.html"
When I write to "app/templates/layouts/example.html" with:
"""
<html><body></body></html>
"""
When I request "/magic/index"
Then I should see:
When I start the application
And I GET /magic/index
Then the response should contain:
"""
<html><body><h1 class="success">title</h1></body></html>
"""
@disable-bundler
Scenario: render a partial
When I save the following as "app/controllers/wand_controller.rb"
When I write to "app/controllers/wand_controller.rb" with:
"""
class WandController < ApplicationController
end
"""
When I save the following as "app/views/wand/index.html.effigy"
When I write to "app/views/wand/index.html.effigy" with:
"""
class WandIndexView < Effigy::Rails::View
def transform
replace_with('p', partial('spell', :locals => { :name => 'hocus pocus' }))
end
end
"""
When I save the following as "app/templates/wand/index.html"
When I write to "app/templates/wand/index.html" with:
"""
<div>
<h1 class="success">spell</h1>
<p>placeholder</p>
</div>
"""
When I save the following as "app/views/wand/_spell.html.effigy"
When I write to "app/views/wand/_spell.html.effigy" with:
"""
class WandSpellPartial < Effigy::Rails::View
def transform
text('p', @name)
end
end
"""
When I save the following as "app/templates/wand/_spell.html"
When I write to "app/templates/wand/_spell.html" with:
"""
<p>put a spell on me</p>
"""
When I request "/wand/index"
Then I should see:
When I start the application
And I GET /wand/index
Then the response should contain:
"""
<div>
<h1 class="success">spell</h1>
Oops, something went wrong.

0 comments on commit 26cb432

Please sign in to comment.