Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 4d2f05d65c2dcf5ef0e5992203177a0c3003ab17 1 parent 4b8aeeb
Norman Clarke authored
Showing with 130 additions and 89 deletions.
  1. +1 −0  .gitignore
  2. +8 −0 History.txt
  3. +12 −12 Manifest.txt
  4. +19 −11 README.rdoc
  5. +3 −3 Rakefile
  6. +18 −27 generators/haml_scaffold/haml_scaffold_generator.rb
  7. 0  generators/haml_scaffold/templates/{_form.html.erb → _form.html.haml.erb}
  8. 0  generators/haml_scaffold/templates/{_object.html.erb → _object.html.haml.erb}
  9. 0  generators/haml_scaffold/templates/{controller.rb → controller.rb.erb}
  10. +10 −10 generators/haml_scaffold/templates/{functional_test.rb → functional_test.rb.erb}
  11. 0  generators/haml_scaffold/templates/{helper.rb → helper.rb.erb}
  12. 0  generators/haml_scaffold/templates/{helper_test.rb → helper_test.rb.erb}
  13. +21 −0 generators/haml_scaffold/templates/layout.html.haml.erb
  14. +11 −0 generators/haml_scaffold/templates/stylesheet.sass
  15. +2 −1  generators/haml_scaffold/templates/{view_edit.html.erb → view_edit.html.haml.erb}
  16. 0  generators/haml_scaffold/templates/{view_index.html.erb → view_index.html.haml.erb}
  17. 0  generators/haml_scaffold/templates/{view_new.html.erb → view_new.html.haml.erb}
  18. 0  generators/haml_scaffold/templates/{view_show.html.erb → view_show.html.haml.erb}
  19. +12 −13 haml_scaffold.gemspec
  20. +1 −1  lib/haml_scaffold/version.rb
  21. +10 −10 samples/posts_controller_test.rb
  22. +2 −1  samples/views/edit.html.haml
View
1  .gitignore
@@ -1,3 +1,4 @@
doc
*.log
.DS_Store
+pkg
View
8 History.txt
@@ -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
24 Manifest.txt
@@ -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
30 README.rdoc
@@ -21,20 +21,19 @@ 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
@@ -42,7 +41,7 @@ generator, with a few differences.
== 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
6 Rakefile
@@ -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']
View
45 generators/haml_scaffold/haml_scaffold_generator.rb
@@ -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
View
0  generators/haml_scaffold/templates/_form.html.erb → ...ators/haml_scaffold/templates/_form.html.haml.erb
File renamed without changes
View
0  generators/haml_scaffold/templates/_object.html.erb → ...ors/haml_scaffold/templates/_object.html.haml.erb
File renamed without changes
View
0  generators/haml_scaffold/templates/controller.rb → generators/haml_scaffold/templates/controller.rb.erb
File renamed without changes
View
20 ...rators/haml_scaffold/templates/functional_test.rb → ...rs/haml_scaffold/templates/functional_test.rb.erb
@@ -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"
View
0  generators/haml_scaffold/templates/helper.rb → generators/haml_scaffold/templates/helper.rb.erb
File renamed without changes
View
0  generators/haml_scaffold/templates/helper_test.rb → ...rators/haml_scaffold/templates/helper_test.rb.erb
File renamed without changes
View
21 generators/haml_scaffold/templates/layout.html.haml.erb
@@ -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
View
11 generators/haml_scaffold/templates/stylesheet.sass
@@ -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
View
3  ...rators/haml_scaffold/templates/view_edit.html.erb → ...s/haml_scaffold/templates/view_edit.html.haml.erb
@@ -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
0  ...ators/haml_scaffold/templates/view_index.html.erb → .../haml_scaffold/templates/view_index.html.haml.erb
File renamed without changes
View
0  generators/haml_scaffold/templates/view_new.html.erb → ...rs/haml_scaffold/templates/view_new.html.haml.erb
File renamed without changes
View
0  ...rators/haml_scaffold/templates/view_show.html.erb → ...s/haml_scaffold/templates/view_show.html.haml.erb
File renamed without changes
View
25 haml_scaffold.gemspec
@@ -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
View
2  lib/haml_scaffold/version.rb
@@ -1,7 +1,7 @@
module HamlScaffold
class Version
MAJOR = 1
- MINOR = 0
+ MINOR = 1
TINY = 0
STRING = "#{MAJOR}.#{MINOR}.#{TINY}"
end
View
20 samples/posts_controller_test.rb
@@ -2,60 +2,60 @@
class PostsControllerTest < ActionController::TestCase
- def test_create
+ test "should create post" do
Post.any_instance.expects(:save).returns(true)
post :create, :post => { }
assert_response :redirect
end
- def test_create_with_failure
+ test "should handle failure to create post" do
Post.any_instance.expects(:save).returns(false)
post :create, :post => { }
assert_template "new"
end
- def test_destroy
+ test "should destroy post" do
Post.any_instance.expects(:destroy).returns(true)
delete :destroy, :id => posts(:one).to_param
assert_not_nil flash[:notice]
assert_response :redirect
end
- def test_destroy_with_failure
+ test "should handle failure to destroy post" do
Post.any_instance.expects(:destroy).returns(false)
delete :destroy, :id => posts(:one).to_param
assert_not_nil flash[:error]
assert_response :redirect
end
- def test_edit
+ test "should get edit for post" do
get :edit, :id => posts(:one).to_param
assert_response :success
end
- def test_index
+ test "should get index for posts" do
get :index
assert_response :success
assert_not_nil assigns(:posts)
end
- def test_new
+ test "should get new for post" do
get :new
assert_response :success
end
- def test_show
+ test "should get show for post" do
get :show, :id => posts(:one).to_param
assert_response :success
end
- def test_update
+ test "should update post" do
Post.any_instance.expects(:save).returns(true)
put :update, :id => posts(:one).to_param, :post => { }
assert_response :redirect
end
- def test_update_with_failure
+ test "should handle failure to update post" do
Post.any_instance.expects(:save).returns(false)
put :update, :id => posts(:one).to_param, :post => { }
assert_template "edit"
View
3  samples/views/edit.html.haml
@@ -2,4 +2,5 @@
= render :partial => "form", :locals => {:post => @post}
%ul
%li= link_to 'Show', @post
- %li= link_to 'Back', posts_path
+ %li= link_to 'Back', posts_path
+ %li= link_to 'Destroy', @post, :confirm => 'Are you sure?', :method => :delete
Please sign in to comment.
Something went wrong with that request. Please try again.