Permalink
Browse files

Upated generator code to Rails 2.3.2. Haml Scaffold now generates lay…

…out and a

SASS stylesheet. Tests now use 'test "name" do' syntax.
  • Loading branch information...
1 parent 4b8aeeb commit 4d2f05d65c2dcf5ef0e5992203177a0c3003ab17 Norman Clarke committed Jul 1, 2009
View
@@ -1,3 +1,4 @@
doc
*.log
.DS_Store
+pkg
View
@@ -1,3 +1,11 @@
+=== 1.1.0 / 2009-07-30
+
+* 3 major enhancements
+
+ * Upated generator code to Rails 2.3.2.
+ * Haml Scaffold now generates layout and a SASS stylesheet.
+ * Tests now use 'test "name" do' syntax.
+
=== 1.0.0 / 2009-02-10
* 1 major enhancement
View
@@ -3,19 +3,19 @@ MIT-LICENSE
Manifest.txt
README.rdoc
Rakefile
-config/website.yml
generators/haml_scaffold/haml_scaffold_generator.rb
-generators/haml_scaffold/templates/_form.html.erb
-generators/haml_scaffold/templates/_object.html.erb
-generators/haml_scaffold/templates/controller.rb
-generators/haml_scaffold/templates/functional_test.rb
-generators/haml_scaffold/templates/helper.rb
-generators/haml_scaffold/templates/helper_test.rb
-generators/haml_scaffold/templates/view_edit.html.erb
-generators/haml_scaffold/templates/view_index.html.erb
-generators/haml_scaffold/templates/view_new.html.erb
-generators/haml_scaffold/templates/view_show.html.erb
-haml_scaffold.gemspec
+generators/haml_scaffold/templates/_form.html.haml.erb
+generators/haml_scaffold/templates/_object.html.haml.erb
+generators/haml_scaffold/templates/controller.rb.erb
+generators/haml_scaffold/templates/functional_test.rb.erb
+generators/haml_scaffold/templates/helper.rb.erb
+generators/haml_scaffold/templates/helper_test.rb.erb
+generators/haml_scaffold/templates/layout.html.haml.erb
+generators/haml_scaffold/templates/stylesheet.sass
+generators/haml_scaffold/templates/view_edit.html.haml.erb
+generators/haml_scaffold/templates/view_index.html.haml.erb
+generators/haml_scaffold/templates/view_new.html.haml.erb
+generators/haml_scaffold/templates/view_show.html.haml.erb
init.rb
lib/haml_scaffold/version.rb
samples/posts_controller.rb
View
@@ -21,28 +21,27 @@ generator, with a few differences.
=== Controller Test
-* Tests error conditions, not just the "happy-path."
+* Tests error conditions, not just the "happy path."
* Has 100% code coverage with RCov.
-* Simplifies test method names and alphabetizes them for more obvious consistency.
-* Uses some very simple mocking with mocha to limit calls to the DB.
+* Uses very simple mocking with mocha to limit calls to the DB.
=== Views
-* Have cleaner, more semantic XHTML.
+* Have cleaner, more semantic XHTML that's easier to quickly replace with your own markup.
* Are broken up into a couple of partials to be DRYer.
* Use will_paginate.
=== Misc
-* Doesn't generate a layout or CSS file.
+* Generates Haml layout and SASS stylesheet.
== Samples
{View them here}[http://github.com/norman/haml-scaffold/tree/master/samples].
== Installation
-HAML Scaffold is available on RubyForge as a gem:
+Haml Scaffold is available on RubyForge as a gem:
sudo gem install haml_scaffold
@@ -54,21 +53,30 @@ You can also install it as a Rails plugin if you wish:
The generated code will depend on:
+* haml[http://haml.hamptoncatlin.com/] (of course!)
* will_paginate[http://github.com/mislav/will_paginate/]
* mocha[http://mocha.rubyforge.org/]
-You'll need to add the gems and/or requires to your config/environment.rb
-manually.
+You'll need to add the gem dependencies to your config/environment.rb
+manually:
+
+ config.gem "haml"
+ config.gem "will_paginate"
+ config.gem "mocha"
+
+Also, don't forget to Hamlize your Rails app:
+
+ $ cd my_rails_app
+ $ haml --rails .
== Other stuff you might be interested in:
* Haml[http://haml.hamptoncatlin.com/]
* {RSpec Haml scaffold generator}[http://github.com/dfischer/rspec-haml-scaffold-generator]
-* {Randomba scaffold}[https://github.com/norman/randomba-scaffold/tree] (like this one, but ERB)
== Author
-{Norman Clarke}[mailto:norman@randomba.org]
+{Norman Clarke}[mailto:norman@njclarke.com]
This work is derived from code in {Ruby on Rails}[http://rubyonrails.org/] and
-is released under its same license, the MIT License.
+is released under its same license, the MIT License.
View
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + "/lib/haml_scaffold/version"
$hoe = Hoe.new("haml_scaffold", HamlScaffold::Version::STRING) do |p|
p.rubyforge_name = "haml-scaffold"
p.author = ['Norman Clarke']
- p.email = ['norman@randomba.org']
- p.summary = "Rails scaffolding with HAML rather than ERB"
- p.description = "Rails scaffolding with HAML rather than ERB"
+ p.email = ['norman@njclarke.com']
+ p.summary = "Rails scaffolding with Haml rather than ERB"
+ p.description = "Rails scaffolding with Haml rather than ERB, and various other improvements."
p.url = 'http://haml-scaffold.rubyforge.org/'
p.extra_deps << ['haml', '>= 2.0.6']
p.extra_deps << ['will_paginate', '>= 2.2.2']
@@ -9,23 +9,24 @@ class HamlScaffoldGenerator < Rails::Generator::NamedBase
:controller_class_name,
:controller_underscore_name,
:controller_singular_name,
- :controller_plural_name
+ :controller_plural_name,
+ :application_name
alias_method :controller_file_name, :controller_underscore_name
alias_method :controller_table_name, :controller_plural_name
def initialize(runtime_args, runtime_options = {})
super
-
+
if @name == @name.pluralize && !options[:force_plural]
logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
@name = @name.singularize
end
@controller_name = @name.pluralize
-
+ @application_name = File.basename(Rails.root.to_s).humanize
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
- @controller_singular_name=base_name.singularize
+ @controller_singular_name = base_name.singularize
if @controller_class_nesting.empty?
@controller_class_name = @controller_class_name_without_nesting
else
@@ -50,34 +51,24 @@ def manifest
m.directory(File.join('test/unit/helpers', class_path))
for action in scaffold_views
- m.template(
- "view_#{action}.html.erb",
- File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml")
- )
+ m.template("view_#{action}.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml"))
end
- m.template(
- "_form.html.erb",
- File.join('app/views', controller_class_path, controller_file_name, "_form.html.haml")
- )
-
- m.template(
- "_object.html.erb",
- File.join('app/views', controller_class_path, controller_file_name, "_#{name}.html.haml")
- )
-
- m.template(
- 'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
- )
-
- m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
- m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
- m.template('helper_test.rb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
-
+ m.template("_form.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "_form.html.haml"))
+ m.template("_object.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "_#{name}.html.haml"))
+ m.template('controller.rb.erb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
+ m.template('functional_test.rb.erb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
+ m.template('helper.rb.erb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
+ m.template('helper_test.rb.erb', File.join('test/unit/helpers', controller_class_path, "#{controller_file_name}_helper_test.rb"))
+ m.directory('app/views/layouts')
+ m.directory('public/stylesheets/sass')
+ m.template('layout.html.haml.erb', 'app/views/layouts/application.html.haml', :collision => :skip, :assigns => {:application_name => @application_name})
+ m.template('stylesheet.sass', 'public/stylesheets/sass/application.sass', :collision => :skip)
m.route_resources controller_file_name
-
m.dependency 'model', [name] + @args, :collision => :skip
+
end
+
end
protected
@@ -2,60 +2,60 @@
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
- def test_create
+ test "should create <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:save).returns(true)
post :create, :<%= file_name %> => { }
assert_response :redirect
end
- def test_create_with_failure
+ test "should handle failure to create <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:save).returns(false)
post :create, :<%= file_name %> => { }
assert_template "new"
end
- def test_destroy
+ test "should destroy <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:destroy).returns(true)
delete :destroy, :id => <%= table_name %>(:one).to_param
assert_not_nil flash[:notice]
assert_response :redirect
end
- def test_destroy_with_failure
+ test "should handle failure to destroy <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:destroy).returns(false)
delete :destroy, :id => <%= table_name %>(:one).to_param
assert_not_nil flash[:error]
assert_response :redirect
end
- def test_edit
+ test "should get edit for <%= singular_name %>" do
get :edit, :id => <%= table_name %>(:one).to_param
assert_response :success
end
- def test_index
+ test "should get index for <%= plural_name %>" do
get :index
assert_response :success
assert_not_nil assigns(:<%= table_name %>)
end
- def test_new
+ test "should get new for <%= singular_name %>" do
get :new
assert_response :success
end
- def test_show
+ test "should get show for <%= singular_name %>" do
get :show, :id => <%= table_name %>(:one).to_param
assert_response :success
end
- def test_update
+ test "should update <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:save).returns(true)
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
assert_response :redirect
end
- def test_update_with_failure
+ test "should handle failure to update <%= singular_name %>" do
<%= class_name %>.any_instance.expects(:save).returns(false)
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
assert_template "edit"
@@ -0,0 +1,21 @@
+!!! XML
+!!!
+%html{ :'xml:lang' => "en", :lang => "en" }
+ %head
+ %title= "#{controller.class.to_s}: #{controller.action_name}"
+ %meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
+ %link{ :rel => "shortcut icon", :href => "/favicon.ico" }
+ = stylesheet_link_tag "application", :media => "screen"
+ = javascript_include_tag :defaults
+ %body
+ #wrapper
+ #content
+ %h1 <%= application_name %>
+ #flash
+ - unless flash.empty?
+ = content_tag :div, flash[:notice], :class => "notice" if flash[:notice]
+ = content_tag :div, flash[:warning], :class => "warning" if flash[:warning]
+ = content_tag :div, flash[:error], :class => "error" if flash[:error]
+ :javascript
+ #{visual_effect :highlight, "flash"}
+ = yield
@@ -0,0 +1,11 @@
+body
+ :text-align center
+
+h1
+ :border-bottom 1px #000 solid
+ :padding-bottom 5px
+
+#wrapper
+ :width 800px
+ :text-align left
+ :margin auto
@@ -2,4 +2,5 @@
= render :partial => "form", :locals => {:<%= singular_name %> => @<%= singular_name %>}
%ul
%li= link_to 'Show', @<%= singular_name %>
- %li= link_to 'Back', <%= plural_name %>_path
+ %li= link_to 'Back', <%= plural_name %>_path
+ %li= link_to 'Destroy', @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
View
@@ -2,45 +2,44 @@
Gem::Specification.new do |s|
s.name = %q{haml_scaffold}
- s.version = "1.0.0"
+ s.version = "1.1.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Norman Clarke"]
- s.date = %q{2009-02-10}
- s.description = %q{Rails scaffolding with HAML rather than ERB}
- s.email = ["norman@randomba.org"]
+ s.date = %q{2009-07-01}
+ s.description = %q{Rails scaffolding with Haml rather than ERB, and various other improvements.}
+ s.email = ["norman@njclarke.com"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
- s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "config/website.yml", "generators/haml_scaffold/haml_scaffold_generator.rb", "generators/haml_scaffold/templates/_form.html.erb", "generators/haml_scaffold/templates/_object.html.erb", "generators/haml_scaffold/templates/controller.rb", "generators/haml_scaffold/templates/functional_test.rb", "generators/haml_scaffold/templates/helper.rb", "generators/haml_scaffold/templates/view_edit.html.erb", "generators/haml_scaffold/templates/view_index.html.erb", "generators/haml_scaffold/templates/view_new.html.erb", "generators/haml_scaffold/templates/view_show.html.erb", "haml_scaffold.gemspec", "init.rb", "lib/haml_scaffold/version.rb", "samples/posts_controller.rb", "samples/posts_controller_test.rb", "samples/views/_form.html.haml", "samples/views/_post.html.haml", "samples/views/edit.html.haml", "samples/views/index.html.haml", "samples/views/new.html.haml", "samples/views/show.html.haml"]
- s.has_rdoc = true
- s.homepage = %q{http://github.com/norman/haml-scaffold}
+ s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "generators/haml_scaffold/haml_scaffold_generator.rb", "generators/haml_scaffold/templates/_form.html.haml.erb", "generators/haml_scaffold/templates/_object.html.haml.erb", "generators/haml_scaffold/templates/controller.rb.erb", "generators/haml_scaffold/templates/functional_test.rb.erb", "generators/haml_scaffold/templates/helper.rb.erb", "generators/haml_scaffold/templates/helper_test.rb.erb", "generators/haml_scaffold/templates/layout.html.haml.erb", "generators/haml_scaffold/templates/stylesheet.sass", "generators/haml_scaffold/templates/view_edit.html.haml.erb", "generators/haml_scaffold/templates/view_index.html.haml.erb", "generators/haml_scaffold/templates/view_new.html.haml.erb", "generators/haml_scaffold/templates/view_show.html.haml.erb", "init.rb", "lib/haml_scaffold/version.rb", "samples/posts_controller.rb", "samples/posts_controller_test.rb", "samples/views/_form.html.haml", "samples/views/_post.html.haml", "samples/views/edit.html.haml", "samples/views/index.html.haml", "samples/views/new.html.haml", "samples/views/show.html.haml"]
+ s.homepage = %q{http://haml-scaffold.rubyforge.org/}
s.rdoc_options = ["--main", "README.rdoc"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{haml-scaffold}
- s.rubygems_version = %q{1.3.1}
- s.summary = %q{Rails scaffolding with HAML rather than ERB}
+ s.rubygems_version = %q{1.3.4}
+ s.summary = %q{Rails scaffolding with Haml rather than ERB}
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
- s.specification_version = 2
+ s.specification_version = 3
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<haml>, [">= 2.0.6"])
s.add_runtime_dependency(%q<will_paginate>, [">= 2.2.2"])
s.add_runtime_dependency(%q<mocha>, [">= 0.9.0"])
- s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
+ s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
else
s.add_dependency(%q<haml>, [">= 2.0.6"])
s.add_dependency(%q<will_paginate>, [">= 2.2.2"])
s.add_dependency(%q<mocha>, [">= 0.9.0"])
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
else
s.add_dependency(%q<haml>, [">= 2.0.6"])
s.add_dependency(%q<will_paginate>, [">= 2.2.2"])
s.add_dependency(%q<mocha>, [">= 0.9.0"])
- s.add_dependency(%q<newgem>, [">= 1.2.3"])
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
s.add_dependency(%q<hoe>, [">= 1.8.0"])
end
end
@@ -1,7 +1,7 @@
module HamlScaffold
class Version
MAJOR = 1
- MINOR = 0
+ MINOR = 1
TINY = 0
STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
end
Oops, something went wrong.

0 comments on commit 4d2f05d

Please sign in to comment.