haml_scaffold 1.0.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.
- data.tar.gz.sig +2 -0
- data/History.txt +6 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +27 -0
- data/README.rdoc +87 -0
- data/Rakefile +25 -0
- data/config/website.yml +2 -0
- data/generators/haml_scaffold/haml_scaffold_generator.rb +98 -0
- data/generators/haml_scaffold/templates/_form.html.erb +10 -0
- data/generators/haml_scaffold/templates/_object.html.erb +10 -0
- data/generators/haml_scaffold/templates/controller.rb +80 -0
- data/generators/haml_scaffold/templates/functional_test.rb +64 -0
- data/generators/haml_scaffold/templates/helper.rb +2 -0
- data/generators/haml_scaffold/templates/view_edit.html.erb +5 -0
- data/generators/haml_scaffold/templates/view_index.html.erb +8 -0
- data/generators/haml_scaffold/templates/view_new.html.erb +4 -0
- data/generators/haml_scaffold/templates/view_show.html.erb +11 -0
- data/haml_scaffold.gemspec +46 -0
- data/init.rb +0 -0
- data/lib/haml_scaffold/version.rb +8 -0
- data/samples/posts_controller.rb +80 -0
- data/samples/posts_controller_test.rb +64 -0
- data/samples/views/_form.html.haml +16 -0
- data/samples/views/_post.html.haml +14 -0
- data/samples/views/edit.html.haml +5 -0
- data/samples/views/index.html.haml +8 -0
- data/samples/views/new.html.haml +4 -0
- data/samples/views/show.html.haml +15 -0
- metadata +153 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
data/History.txt
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
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.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
History.txt
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
config/website.yml
|
7
|
+
generators/haml_scaffold/haml_scaffold_generator.rb
|
8
|
+
generators/haml_scaffold/templates/_form.html.erb
|
9
|
+
generators/haml_scaffold/templates/_object.html.erb
|
10
|
+
generators/haml_scaffold/templates/controller.rb
|
11
|
+
generators/haml_scaffold/templates/functional_test.rb
|
12
|
+
generators/haml_scaffold/templates/helper.rb
|
13
|
+
generators/haml_scaffold/templates/view_edit.html.erb
|
14
|
+
generators/haml_scaffold/templates/view_index.html.erb
|
15
|
+
generators/haml_scaffold/templates/view_new.html.erb
|
16
|
+
generators/haml_scaffold/templates/view_show.html.erb
|
17
|
+
haml_scaffold.gemspec
|
18
|
+
init.rb
|
19
|
+
lib/haml_scaffold/version.rb
|
20
|
+
samples/posts_controller.rb
|
21
|
+
samples/posts_controller_test.rb
|
22
|
+
samples/views/_form.html.haml
|
23
|
+
samples/views/_post.html.haml
|
24
|
+
samples/views/edit.html.haml
|
25
|
+
samples/views/index.html.haml
|
26
|
+
samples/views/new.html.haml
|
27
|
+
samples/views/show.html.haml
|
data/README.rdoc
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
= Haml Scaffold
|
2
|
+
|
3
|
+
A collection of hacks to the Rails scaffold generator, to make it output
|
4
|
+
templates using Haml rather than ERB. You may like some of it, and may hate
|
5
|
+
other parts. You're free to use it under the terms of the MIT license if the
|
6
|
+
parts you like outweigh the parts you hate.
|
7
|
+
|
8
|
+
This scaffold generator does the same thing as the default Rails scaffold
|
9
|
+
generator, with a few differences.
|
10
|
+
|
11
|
+
== Differences from Rails Scaffolding:
|
12
|
+
|
13
|
+
* Haml not ERB.
|
14
|
+
|
15
|
+
=== Controller
|
16
|
+
|
17
|
+
* Loads object with a before_filter to be DRYer.
|
18
|
+
* "Destroy" method handles error conditions.
|
19
|
+
* Actions are alphabetized for more obvious consistency.
|
20
|
+
* Uses will_paginate.
|
21
|
+
|
22
|
+
=== Controller Test
|
23
|
+
|
24
|
+
* Tests error conditions, not just the "happy-path."
|
25
|
+
* Has 100% code coverage with RCov.
|
26
|
+
* Simplifies test method names and alphabetizes them for more obvious consistency.
|
27
|
+
* Uses some very simple mocking with mocha to limit calls to the DB.
|
28
|
+
|
29
|
+
=== Views
|
30
|
+
|
31
|
+
* Have cleaner, more semantic XHTML.
|
32
|
+
* Are broken up into a couple of partials to be DRYer.
|
33
|
+
* Use will_paginate.
|
34
|
+
|
35
|
+
=== Misc
|
36
|
+
|
37
|
+
* Doesn't generate a layout or CSS file.
|
38
|
+
|
39
|
+
== Samples
|
40
|
+
|
41
|
+
{View them here}[http://github.com/norman/haml-scaffold/tree/master/samples].
|
42
|
+
|
43
|
+
== Installation
|
44
|
+
|
45
|
+
There are three ways you can install this generator:
|
46
|
+
|
47
|
+
=== Gem
|
48
|
+
|
49
|
+
sudo gem install norman-haml_scaffold --source http://gems.github.com
|
50
|
+
|
51
|
+
or
|
52
|
+
|
53
|
+
git clone git://github.com/norman/haml-scaffold.git
|
54
|
+
cd haml-scaffold
|
55
|
+
gem build haml_scaffold.gemspec
|
56
|
+
sudo gem install haml_scaffold-*.gem
|
57
|
+
|
58
|
+
=== Manual
|
59
|
+
|
60
|
+
Download the tarball from the Github repository and unarchive it in ~/.rails/generators.
|
61
|
+
|
62
|
+
=== Rails Plugin
|
63
|
+
|
64
|
+
./script/plugin install git://github.com/norman/haml-scaffold.git
|
65
|
+
|
66
|
+
== Dependencies
|
67
|
+
|
68
|
+
The generated code will depend on:
|
69
|
+
|
70
|
+
* will_paginate[http://github.com/mislav/will_paginate/]
|
71
|
+
* mocha[http://mocha.rubyforge.org/]
|
72
|
+
|
73
|
+
You'll need to add the gems and/or requires to your config/environment.rb
|
74
|
+
manually.
|
75
|
+
|
76
|
+
== Other stuff you might be interested in:
|
77
|
+
|
78
|
+
* Haml[http://haml.hamptoncatlin.com/]
|
79
|
+
* {RSpec Haml scaffold generator}[http://github.com/dfischer/rspec-haml-scaffold-generator]
|
80
|
+
* {Randomba scaffold}[https://github.com/norman/randomba-scaffold/tree] (like this one, but ERB)
|
81
|
+
|
82
|
+
== Author
|
83
|
+
|
84
|
+
{Norman Clarke}[mailto:norman@randomba.org]
|
85
|
+
|
86
|
+
This work is derived from code in {Ruby on Rails}[http://rubyonrails.org/] and
|
87
|
+
is released under its same license, the MIT License.
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'newgem'
|
2
|
+
require File.dirname(__FILE__) + "/lib/haml_scaffold/version"
|
3
|
+
$hoe = Hoe.new("haml_scaffold", HamlScaffold::Version::STRING) do |p|
|
4
|
+
p.rubyforge_name = "haml-scaffold"
|
5
|
+
p.author = ['Norman Clarke']
|
6
|
+
p.email = ['norman@randomba.org']
|
7
|
+
p.summary = "Rails scaffolding with HAML rather than ERB"
|
8
|
+
p.description = "Rails scaffolding with HAML rather than ERB"
|
9
|
+
p.url = 'http://haml-scaffold.rubyforge.org/'
|
10
|
+
p.extra_deps << ['haml', '>= 2.0.6']
|
11
|
+
p.extra_deps << ['will_paginate', '>= 2.2.2']
|
12
|
+
p.extra_deps << ['mocha', '>= 0.9.0']
|
13
|
+
p.extra_dev_deps << ['newgem', ">= #{::Newgem::VERSION}"]
|
14
|
+
p.remote_rdoc_dir = "/"
|
15
|
+
end
|
16
|
+
puts $hoe.inspect
|
17
|
+
require 'newgem/tasks'
|
18
|
+
|
19
|
+
desc 'Publish RDoc to RubyForge.'
|
20
|
+
task :publish_docs => [:clean, :docs] do
|
21
|
+
host = "compay@rubyforge.org"
|
22
|
+
remote_dir = "/var/www/gforge-projects/haml-scaffold"
|
23
|
+
local_dir = 'doc'
|
24
|
+
sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
|
25
|
+
end
|
data/config/website.yml
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
class HamlScaffoldGenerator < Rails::Generator::NamedBase
|
2
|
+
default_options :skip_timestamps => false, :skip_migration => false
|
3
|
+
|
4
|
+
attr_reader :controller_name,
|
5
|
+
:controller_class_path,
|
6
|
+
:controller_file_path,
|
7
|
+
:controller_class_nesting,
|
8
|
+
:controller_class_nesting_depth,
|
9
|
+
:controller_class_name,
|
10
|
+
:controller_underscore_name,
|
11
|
+
:controller_singular_name,
|
12
|
+
:controller_plural_name
|
13
|
+
alias_method :controller_file_name, :controller_underscore_name
|
14
|
+
alias_method :controller_table_name, :controller_plural_name
|
15
|
+
|
16
|
+
def initialize(runtime_args, runtime_options = {})
|
17
|
+
super
|
18
|
+
|
19
|
+
@controller_name = @name.pluralize
|
20
|
+
|
21
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
22
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
23
|
+
@controller_singular_name=base_name.singularize
|
24
|
+
if @controller_class_nesting.empty?
|
25
|
+
@controller_class_name = @controller_class_name_without_nesting
|
26
|
+
else
|
27
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def manifest
|
32
|
+
record do |m|
|
33
|
+
|
34
|
+
# Check for class naming collisions.
|
35
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
36
|
+
m.class_collisions(class_path, "#{class_name}")
|
37
|
+
|
38
|
+
# Controller, helper, views, test and stylesheets directories.
|
39
|
+
m.directory(File.join('app/models', class_path))
|
40
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
41
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
42
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
43
|
+
m.directory(File.join('test/functional', controller_class_path))
|
44
|
+
m.directory(File.join('test/unit', class_path))
|
45
|
+
|
46
|
+
for action in scaffold_views
|
47
|
+
m.template(
|
48
|
+
"view_#{action}.html.erb",
|
49
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml")
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
m.template(
|
54
|
+
"_form.html.erb",
|
55
|
+
File.join('app/views', controller_class_path, controller_file_name, "_form.html.haml")
|
56
|
+
)
|
57
|
+
|
58
|
+
m.template(
|
59
|
+
"_object.html.erb",
|
60
|
+
File.join('app/views', controller_class_path, controller_file_name, "_#{name}.html.haml")
|
61
|
+
)
|
62
|
+
|
63
|
+
m.template(
|
64
|
+
'controller.rb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
65
|
+
)
|
66
|
+
|
67
|
+
m.template('functional_test.rb', File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb"))
|
68
|
+
m.template('helper.rb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
69
|
+
|
70
|
+
m.route_resources controller_file_name
|
71
|
+
|
72
|
+
m.dependency 'model', [name] + @args, :collision => :skip
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
protected
|
77
|
+
# Override with your own usage banner.
|
78
|
+
def banner
|
79
|
+
"Usage: #{$0} scaffold ModelName [field:type, field:type]"
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_options!(opt)
|
83
|
+
opt.separator ''
|
84
|
+
opt.separator 'Options:'
|
85
|
+
opt.on("--skip-timestamps",
|
86
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
87
|
+
opt.on("--skip-migration",
|
88
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
89
|
+
end
|
90
|
+
|
91
|
+
def scaffold_views
|
92
|
+
%w[ index show new edit ]
|
93
|
+
end
|
94
|
+
|
95
|
+
def model_name
|
96
|
+
class_name.demodulize
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
- content_tag_for :div, <%= singular_name %> do
|
2
|
+
%ul
|
3
|
+
<% for attribute in attributes -%>
|
4
|
+
%li
|
5
|
+
%strong <%= attribute.column.human_name %>:
|
6
|
+
=h <%= singular_name %>.<%= attribute.name %>
|
7
|
+
<% end -%>
|
8
|
+
= link_to 'Show', <%= singular_name %>
|
9
|
+
= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>)
|
10
|
+
= link_to 'Destroy', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
|
3
|
+
before_filter :find_<%= file_name %>
|
4
|
+
|
5
|
+
<%= file_name.pluralize.upcase %>_PER_PAGE = 20
|
6
|
+
|
7
|
+
def create
|
8
|
+
@<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>])
|
9
|
+
respond_to do |format|
|
10
|
+
if @<%= file_name %>.save
|
11
|
+
flash[:notice] = '<%= class_name %> was successfully created.'
|
12
|
+
format.html { redirect_to @<%= file_name %> }
|
13
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
14
|
+
else
|
15
|
+
format.html { render :action => "new" }
|
16
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy
|
22
|
+
respond_to do |format|
|
23
|
+
if @<%= file_name %>.destroy
|
24
|
+
flash[:notice] = '<%= class_name %> was successfully destroyed.'
|
25
|
+
format.html { redirect_to <%= file_name.pluralize %>_path }
|
26
|
+
format.xml { head :ok }
|
27
|
+
else
|
28
|
+
flash[:error] = '<%= class_name %> could not be destroyed.'
|
29
|
+
format.html { redirect_to @<%= file_name %> }
|
30
|
+
format.xml { head :unprocessable_entity }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def index
|
36
|
+
@<%= table_name %> = <%= class_name %>.paginate(:page => params[:page], :per_page => <%= file_name.pluralize.upcase %>_PER_PAGE)
|
37
|
+
respond_to do |format|
|
38
|
+
format.html
|
39
|
+
format.xml { render :xml => @<%= table_name %> }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def edit
|
44
|
+
end
|
45
|
+
|
46
|
+
def new
|
47
|
+
@<%= file_name %> = <%= class_name %>.new
|
48
|
+
respond_to do |format|
|
49
|
+
format.html
|
50
|
+
format.xml { render :xml => @<%= file_name %> }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def show
|
55
|
+
respond_to do |format|
|
56
|
+
format.html
|
57
|
+
format.xml { render :xml => @<%= file_name %> }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def update
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = '<%= class_name %> was successfully updated.'
|
65
|
+
format.html { redirect_to @<%= file_name %> }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def find_<%= file_name %>
|
77
|
+
@<%= file_name %> = <%= class_name %>.find(params[:id]) if params[:id]
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
<%= class_name %>.any_instance.expects(:save).returns(true)
|
7
|
+
post :create, :<%= file_name %> => { }
|
8
|
+
assert_response :redirect
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_create_with_failure
|
12
|
+
<%= class_name %>.any_instance.expects(:save).returns(false)
|
13
|
+
post :create, :<%= file_name %> => { }
|
14
|
+
assert_template "new"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_destroy
|
18
|
+
<%= class_name %>.any_instance.expects(:destroy).returns(true)
|
19
|
+
delete :destroy, :id => <%= table_name %>(:one).to_param
|
20
|
+
assert_not_nil flash[:notice]
|
21
|
+
assert_response :redirect
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_destroy_with_failure
|
25
|
+
<%= class_name %>.any_instance.expects(:destroy).returns(false)
|
26
|
+
delete :destroy, :id => <%= table_name %>(:one).to_param
|
27
|
+
assert_not_nil flash[:error]
|
28
|
+
assert_response :redirect
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_edit
|
32
|
+
get :edit, :id => <%= table_name %>(:one).to_param
|
33
|
+
assert_response :success
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_index
|
37
|
+
get :index
|
38
|
+
assert_response :success
|
39
|
+
assert_not_nil assigns(:<%= table_name %>)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_new
|
43
|
+
get :new
|
44
|
+
assert_response :success
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_show
|
48
|
+
get :show, :id => <%= table_name %>(:one).to_param
|
49
|
+
assert_response :success
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update
|
53
|
+
<%= class_name %>.any_instance.expects(:save).returns(true)
|
54
|
+
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
55
|
+
assert_response :redirect
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_update_with_failure
|
59
|
+
<%= class_name %>.any_instance.expects(:save).returns(false)
|
60
|
+
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
|
61
|
+
assert_template "edit"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
%h2 Listing <%= plural_name %>
|
2
|
+
- if !@<%= plural_name %>.empty?
|
3
|
+
.<%= plural_name %>
|
4
|
+
= render :partial => "<%= singular_name %>", :collection => @<%= plural_name %>
|
5
|
+
= will_paginate(@<%= plural_name %>)
|
6
|
+
- else
|
7
|
+
%p There are no <%= plural_name %> to show yet.
|
8
|
+
= link_to 'New <%= singular_name %>', new_<%= singular_name %>_path
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%h2= "<%= class_name %> \"#{@<%= singular_name %>.to_param}\""
|
2
|
+
- content_tag_for :div, @<%= singular_name %> do
|
3
|
+
%ul
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
%li
|
6
|
+
%strong <%= attribute.column.human_name %>:
|
7
|
+
=h @<%= singular_name %>.<%= attribute.name %>
|
8
|
+
<% end -%>
|
9
|
+
%ul
|
10
|
+
%li= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
|
11
|
+
%li= link_to 'Back', <%= plural_name %>_path
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{haml_scaffold}
|
5
|
+
s.version = "1.0.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Norman Clarke"]
|
9
|
+
s.date = %q{2009-02-10}
|
10
|
+
s.description = %q{Rails scaffolding with HAML rather than ERB}
|
11
|
+
s.email = ["norman@randomba.org"]
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
+
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"]
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.homepage = %q{http://github.com/norman/haml-scaffold}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{haml-scaffold}
|
19
|
+
s.rubygems_version = %q{1.3.1}
|
20
|
+
s.summary = %q{Rails scaffolding with HAML rather than ERB}
|
21
|
+
|
22
|
+
if s.respond_to? :specification_version then
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
24
|
+
s.specification_version = 2
|
25
|
+
|
26
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
27
|
+
s.add_runtime_dependency(%q<haml>, [">= 2.0.6"])
|
28
|
+
s.add_runtime_dependency(%q<will_paginate>, [">= 2.2.2"])
|
29
|
+
s.add_runtime_dependency(%q<mocha>, [">= 0.9.0"])
|
30
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
31
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<haml>, [">= 2.0.6"])
|
34
|
+
s.add_dependency(%q<will_paginate>, [">= 2.2.2"])
|
35
|
+
s.add_dependency(%q<mocha>, [">= 0.9.0"])
|
36
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
37
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
38
|
+
end
|
39
|
+
else
|
40
|
+
s.add_dependency(%q<haml>, [">= 2.0.6"])
|
41
|
+
s.add_dependency(%q<will_paginate>, [">= 2.2.2"])
|
42
|
+
s.add_dependency(%q<mocha>, [">= 0.9.0"])
|
43
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
44
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
45
|
+
end
|
46
|
+
end
|
data/init.rb
ADDED
File without changes
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :find_post
|
4
|
+
|
5
|
+
POSTS_PER_PAGE = 20
|
6
|
+
|
7
|
+
def create
|
8
|
+
@post = Post.new(params[:post])
|
9
|
+
respond_to do |format|
|
10
|
+
if @post.save
|
11
|
+
flash[:notice] = 'Post was successfully created.'
|
12
|
+
format.html { redirect_to @post }
|
13
|
+
format.xml { render :xml => @post, :status => :created, :location => @post }
|
14
|
+
else
|
15
|
+
format.html { render :action => "new" }
|
16
|
+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def destroy
|
22
|
+
respond_to do |format|
|
23
|
+
if @post.destroy
|
24
|
+
flash[:notice] = 'Post was successfully destroyed.'
|
25
|
+
format.html { redirect_to posts_path }
|
26
|
+
format.xml { head :ok }
|
27
|
+
else
|
28
|
+
flash[:error] = 'Post could not be destroyed.'
|
29
|
+
format.html { redirect_to @post }
|
30
|
+
format.xml { head :unprocessable_entity }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def index
|
36
|
+
@posts = Post.paginate(:page => params[:page], :per_page => POSTS_PER_PAGE)
|
37
|
+
respond_to do |format|
|
38
|
+
format.html
|
39
|
+
format.xml { render :xml => @posts }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def edit
|
44
|
+
end
|
45
|
+
|
46
|
+
def new
|
47
|
+
@post = Post.new
|
48
|
+
respond_to do |format|
|
49
|
+
format.html
|
50
|
+
format.xml { render :xml => @post }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def show
|
55
|
+
respond_to do |format|
|
56
|
+
format.html
|
57
|
+
format.xml { render :xml => @post }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def update
|
62
|
+
respond_to do |format|
|
63
|
+
if @post.update_attributes(params[:post])
|
64
|
+
flash[:notice] = 'Post was successfully updated.'
|
65
|
+
format.html { redirect_to @post }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @post.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def find_post
|
77
|
+
@post = Post.find(params[:id]) if params[:id]
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PostsControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def test_create
|
6
|
+
Post.any_instance.expects(:save).returns(true)
|
7
|
+
post :create, :post => { }
|
8
|
+
assert_response :redirect
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_create_with_failure
|
12
|
+
Post.any_instance.expects(:save).returns(false)
|
13
|
+
post :create, :post => { }
|
14
|
+
assert_template "new"
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_destroy
|
18
|
+
Post.any_instance.expects(:destroy).returns(true)
|
19
|
+
delete :destroy, :id => posts(:one).to_param
|
20
|
+
assert_not_nil flash[:notice]
|
21
|
+
assert_response :redirect
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_destroy_with_failure
|
25
|
+
Post.any_instance.expects(:destroy).returns(false)
|
26
|
+
delete :destroy, :id => posts(:one).to_param
|
27
|
+
assert_not_nil flash[:error]
|
28
|
+
assert_response :redirect
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_edit
|
32
|
+
get :edit, :id => posts(:one).to_param
|
33
|
+
assert_response :success
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_index
|
37
|
+
get :index
|
38
|
+
assert_response :success
|
39
|
+
assert_not_nil assigns(:posts)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_new
|
43
|
+
get :new
|
44
|
+
assert_response :success
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_show
|
48
|
+
get :show, :id => posts(:one).to_param
|
49
|
+
assert_response :success
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_update
|
53
|
+
Post.any_instance.expects(:save).returns(true)
|
54
|
+
put :update, :id => posts(:one).to_param, :post => { }
|
55
|
+
assert_response :redirect
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_update_with_failure
|
59
|
+
Post.any_instance.expects(:save).returns(false)
|
60
|
+
put :update, :id => posts(:one).to_param, :post => { }
|
61
|
+
assert_template "edit"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- content_tag_for :div, post do
|
2
|
+
%ul
|
3
|
+
%li
|
4
|
+
%strong Title:
|
5
|
+
=h post.title
|
6
|
+
%li
|
7
|
+
%strong Author:
|
8
|
+
=h post.author
|
9
|
+
%li
|
10
|
+
%strong Content:
|
11
|
+
=h post.content
|
12
|
+
= link_to 'Show', post
|
13
|
+
= link_to 'Edit', edit_post_path(post)
|
14
|
+
= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%h2= "Post \"#{@post.to_param}\""
|
2
|
+
- content_tag_for :div, @post do
|
3
|
+
%ul
|
4
|
+
%li
|
5
|
+
%strong Title:
|
6
|
+
=h @post.title
|
7
|
+
%li
|
8
|
+
%strong Author:
|
9
|
+
=h @post.author
|
10
|
+
%li
|
11
|
+
%strong Content:
|
12
|
+
=h @post.content
|
13
|
+
%ul
|
14
|
+
%li= link_to 'Edit', edit_post_path(@post)
|
15
|
+
%li= link_to 'Back', posts_path
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haml_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Norman Clarke
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDNDCCAhygAwIBAgIBADANBgkqhkiG9w0BAQUFADBAMQ8wDQYDVQQDDAZub3Jt
|
14
|
+
YW4xGDAWBgoJkiaJk/IsZAEZFghyYW5kb21iYTETMBEGCgmSJomT8ixkARkWA29y
|
15
|
+
ZzAeFw0wODA3MjUxOTEyMDJaFw0wOTA3MjUxOTEyMDJaMEAxDzANBgNVBAMMBm5v
|
16
|
+
cm1hbjEYMBYGCgmSJomT8ixkARkWCHJhbmRvbWJhMRMwEQYKCZImiZPyLGQBGRYD
|
17
|
+
b3JnMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0MuX/i3u1A7Gu2pC
|
18
|
+
y3tUIeGen3nJ8KrMpugJ2bo/VRcOLwo3bQl742idpfUE/Wq3rXexxc0Dg9jKQ8yb
|
19
|
+
1vHqM0s29UmC+UJjKG87eqQDXiq8jHgRcvykGmTZE8GBAVYvm0Wsm7aXWW6hMM/z
|
20
|
+
9QnhZHmBjCaBb8LXsXCgNHFctKkbtxmEXQk2j9pfWuMVSWVVXJR8Nd03u8G2k4RS
|
21
|
+
DhvPTP0eAsWRda/6oxGm+QDYv1tfwDVtqUEgD0zFFlpqJcJiKjn/vquJc8tPMYwK
|
22
|
+
E7eh4J9cT83sgTGs65l9e2Z9cF920DQMJmkzSAVpm7LKSglfO+WWGQlpagZbcC3J
|
23
|
+
hoR5WQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
|
24
|
+
axQXpjRK4llQWMZYVQvaZIJ7/a0wDQYJKoZIhvcNAQEFBQADggEBABappQnc8jtY
|
25
|
+
ZjbWN1Ya8emsRx2w//Z0LElusQ4PjBfWOzDjQ/BM6JjBA0tC1UyDISpTxD507lZ8
|
26
|
+
ydTETFAbzTrjJwBwwc1fxwgNm6MZQkZ/7A6WO7OfQw+nkiEaDw7fa10Gd4DBCqhY
|
27
|
+
Ot72besSspWtxuzTkpl/9YjbUk/XGL2ZjONUUsdzig12eGA659E0AM7LreIiLvSu
|
28
|
+
EI6rjC8mzEcTVXpeZKtVL5Ba7JSpWT5ojVXF8b4+5o3W5iSH2s4vWeRCS3KK3cww
|
29
|
+
sJ9/D9IfrPBgbrLYAldiZhGbSxBmwc6mbpPxWaT7SKRbw+XhSGhEeYbBcJs+8gvo
|
30
|
+
h7fbBRfStxI=
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2009-02-10 00:00:00 -02:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: haml
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.0.6
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: will_paginate
|
48
|
+
type: :runtime
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.2.2
|
55
|
+
version:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: mocha
|
58
|
+
type: :runtime
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.9.0
|
65
|
+
version:
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: newgem
|
68
|
+
type: :development
|
69
|
+
version_requirement:
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.2.3
|
75
|
+
version:
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: hoe
|
78
|
+
type: :development
|
79
|
+
version_requirement:
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.8.0
|
85
|
+
version:
|
86
|
+
description: Rails scaffolding with HAML rather than ERB
|
87
|
+
email:
|
88
|
+
- norman@randomba.org
|
89
|
+
executables: []
|
90
|
+
|
91
|
+
extensions: []
|
92
|
+
|
93
|
+
extra_rdoc_files:
|
94
|
+
- History.txt
|
95
|
+
- Manifest.txt
|
96
|
+
- README.rdoc
|
97
|
+
files:
|
98
|
+
- History.txt
|
99
|
+
- MIT-LICENSE
|
100
|
+
- Manifest.txt
|
101
|
+
- README.rdoc
|
102
|
+
- Rakefile
|
103
|
+
- config/website.yml
|
104
|
+
- generators/haml_scaffold/haml_scaffold_generator.rb
|
105
|
+
- generators/haml_scaffold/templates/_form.html.erb
|
106
|
+
- generators/haml_scaffold/templates/_object.html.erb
|
107
|
+
- generators/haml_scaffold/templates/controller.rb
|
108
|
+
- generators/haml_scaffold/templates/functional_test.rb
|
109
|
+
- generators/haml_scaffold/templates/helper.rb
|
110
|
+
- generators/haml_scaffold/templates/view_edit.html.erb
|
111
|
+
- generators/haml_scaffold/templates/view_index.html.erb
|
112
|
+
- generators/haml_scaffold/templates/view_new.html.erb
|
113
|
+
- generators/haml_scaffold/templates/view_show.html.erb
|
114
|
+
- haml_scaffold.gemspec
|
115
|
+
- init.rb
|
116
|
+
- lib/haml_scaffold/version.rb
|
117
|
+
- samples/posts_controller.rb
|
118
|
+
- samples/posts_controller_test.rb
|
119
|
+
- samples/views/_form.html.haml
|
120
|
+
- samples/views/_post.html.haml
|
121
|
+
- samples/views/edit.html.haml
|
122
|
+
- samples/views/index.html.haml
|
123
|
+
- samples/views/new.html.haml
|
124
|
+
- samples/views/show.html.haml
|
125
|
+
has_rdoc: true
|
126
|
+
homepage: http://haml-scaffold.rubyforge.org/
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options:
|
129
|
+
- --main
|
130
|
+
- README.rdoc
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: "0"
|
138
|
+
version:
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: "0"
|
144
|
+
version:
|
145
|
+
requirements: []
|
146
|
+
|
147
|
+
rubyforge_project: haml-scaffold
|
148
|
+
rubygems_version: 1.3.1
|
149
|
+
signing_key:
|
150
|
+
specification_version: 2
|
151
|
+
summary: Rails scaffolding with HAML rather than ERB
|
152
|
+
test_files: []
|
153
|
+
|
metadata.gz.sig
ADDED
Binary file
|