haml_formtastic_scaffold 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.
- data/History.txt +3 -0
- data/MIT-LICENSE +20 -0
- data/Manifest.txt +25 -0
- data/README.rdoc +84 -0
- data/Rakefile +24 -0
- data/generators/haml_scaffold/haml_scaffold_generator.rb +96 -0
- data/generators/haml_scaffold/templates/_form.html.haml.erb +7 -0
- data/generators/haml_scaffold/templates/_object.html.haml.erb +10 -0
- data/generators/haml_scaffold/templates/controller.rb.erb +80 -0
- data/generators/haml_scaffold/templates/helper.rb.erb +2 -0
- data/generators/haml_scaffold/templates/layout.html.haml.erb +21 -0
- data/generators/haml_scaffold/templates/stylesheet.sass +11 -0
- data/generators/haml_scaffold/templates/view_edit.html.haml.erb +6 -0
- data/generators/haml_scaffold/templates/view_index.html.haml.erb +8 -0
- data/generators/haml_scaffold/templates/view_new.html.haml.erb +4 -0
- data/generators/haml_scaffold/templates/view_show.html.haml.erb +11 -0
- data/init.rb +0 -0
- data/lib/haml_scaffold/version.rb +8 -0
- data/samples/posts_controller.rb +80 -0
- data/samples/views/_form.html.haml +16 -0
- data/samples/views/_post.html.haml +14 -0
- data/samples/views/edit.html.haml +6 -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 +158 -0
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,25 @@
|
|
1
|
+
History.txt
|
2
|
+
MIT-LICENSE
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
generators/haml_scaffold/haml_scaffold_generator.rb
|
7
|
+
generators/haml_scaffold/templates/_form.html.haml.erb
|
8
|
+
generators/haml_scaffold/templates/_object.html.haml.erb
|
9
|
+
generators/haml_scaffold/templates/controller.rb.erb
|
10
|
+
generators/haml_scaffold/templates/helper.rb.erb
|
11
|
+
generators/haml_scaffold/templates/layout.html.haml.erb
|
12
|
+
generators/haml_scaffold/templates/stylesheet.sass
|
13
|
+
generators/haml_scaffold/templates/view_edit.html.haml.erb
|
14
|
+
generators/haml_scaffold/templates/view_index.html.haml.erb
|
15
|
+
generators/haml_scaffold/templates/view_new.html.haml.erb
|
16
|
+
generators/haml_scaffold/templates/view_show.html.haml.erb
|
17
|
+
init.rb
|
18
|
+
lib/haml_scaffold/version.rb
|
19
|
+
samples/posts_controller.rb
|
20
|
+
samples/views/_form.html.haml
|
21
|
+
samples/views/_post.html.haml
|
22
|
+
samples/views/edit.html.haml
|
23
|
+
samples/views/index.html.haml
|
24
|
+
samples/views/new.html.haml
|
25
|
+
samples/views/show.html.haml
|
data/README.rdoc
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= Haml Scaffold - Formtastic Fork
|
2
|
+
|
3
|
+
This is fork of norman/haml-scaffold adds support for formtastic style forms.
|
4
|
+
|
5
|
+
A collection of hacks to the Rails scaffold generator, to make it output
|
6
|
+
templates using Haml rather than ERB. You may like some of it, and may hate
|
7
|
+
other parts. You're free to use it under the terms of the MIT license if the
|
8
|
+
parts you like outweigh the parts you hate.
|
9
|
+
|
10
|
+
This scaffold generator does the same thing as the default Rails scaffold
|
11
|
+
generator, with a few differences.
|
12
|
+
|
13
|
+
== Differences from Rails Scaffolding:
|
14
|
+
|
15
|
+
* Haml not ERB.
|
16
|
+
|
17
|
+
=== Controller
|
18
|
+
|
19
|
+
* Loads object with a before_filter to be DRYer.
|
20
|
+
* "Destroy" method handles error conditions.
|
21
|
+
* Actions are alphabetized for more obvious consistency.
|
22
|
+
* Uses will_paginate.
|
23
|
+
|
24
|
+
=== Controller Test
|
25
|
+
|
26
|
+
* Tests error conditions, not just the "happy path."
|
27
|
+
* Has 100% code coverage with RCov.
|
28
|
+
|
29
|
+
=== Views
|
30
|
+
|
31
|
+
* Have cleaner, more semantic XHTML that's easier to quickly replace with your own markup.
|
32
|
+
* Are broken up into a couple of partials to be DRYer.
|
33
|
+
* Use will_paginate.
|
34
|
+
|
35
|
+
=== Misc
|
36
|
+
|
37
|
+
* Generates Haml layout and SASS stylesheet.
|
38
|
+
|
39
|
+
== Samples
|
40
|
+
|
41
|
+
{View them here}[http://github.com/norman/haml-scaffold/tree/master/samples].
|
42
|
+
|
43
|
+
== Installation
|
44
|
+
|
45
|
+
Haml Scaffold is available on RubyForge as a gem:
|
46
|
+
|
47
|
+
sudo gem install haml_scaffold
|
48
|
+
|
49
|
+
You can also install it as a Rails plugin if you wish:
|
50
|
+
|
51
|
+
./script/plugin install git://github.com/norman/haml-scaffold.git
|
52
|
+
|
53
|
+
== Dependencies
|
54
|
+
|
55
|
+
The generated code will depend on:
|
56
|
+
|
57
|
+
* haml[http://haml.hamptoncatlin.com/] (of course!)
|
58
|
+
* will_paginate[http://github.com/mislav/will_paginate/]
|
59
|
+
* formtastic[http://github.com/justinfrench/formtastic/]
|
60
|
+
|
61
|
+
You'll need to add the gem dependencies to your config/environment.rb
|
62
|
+
manually:
|
63
|
+
|
64
|
+
config.gem "haml"
|
65
|
+
config.gem "will_paginate"
|
66
|
+
config.gem "formtastic"
|
67
|
+
|
68
|
+
Also, don't forget to Hamlize your Rails app:
|
69
|
+
|
70
|
+
$ cd my_rails_app
|
71
|
+
$ haml --rails .
|
72
|
+
|
73
|
+
== Other stuff you might be interested in:
|
74
|
+
|
75
|
+
* Haml[http://haml.hamptoncatlin.com/]
|
76
|
+
* {RSpec Haml scaffold generator}[http://github.com/dfischer/rspec-haml-scaffold-generator]
|
77
|
+
|
78
|
+
== Author
|
79
|
+
|
80
|
+
{Matthew Soldo}[mailto:haml_scaffold@soldo.org]
|
81
|
+
|
82
|
+
This work is derived from code in {Ruby on Rails}[http://rubyonrails.org/]
|
83
|
+
and the haml_scaffold generator[http://github.com/norman/haml-scaffold/].
|
84
|
+
It is released under its same license, the MIT License.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
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@njclarke.com']
|
7
|
+
p.summary = "Rails scaffolding with Haml rather than ERB"
|
8
|
+
p.description = "Rails scaffolding with Haml rather than ERB, and various other improvements."
|
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
|
+
require 'newgem/tasks'
|
17
|
+
|
18
|
+
desc 'Publish RDoc to RubyForge.'
|
19
|
+
task :publish_docs => [:clean, :docs] do
|
20
|
+
host = "compay@rubyforge.org"
|
21
|
+
remote_dir = "/var/www/gforge-projects/haml-scaffold"
|
22
|
+
local_dir = 'doc'
|
23
|
+
sh %{rsync -av --delete #{local_dir}/ #{host}:#{remote_dir}}
|
24
|
+
end
|
@@ -0,0 +1,96 @@
|
|
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
|
+
:application_name
|
14
|
+
alias_method :controller_file_name, :controller_underscore_name
|
15
|
+
alias_method :controller_table_name, :controller_plural_name
|
16
|
+
|
17
|
+
def initialize(runtime_args, runtime_options = {})
|
18
|
+
super
|
19
|
+
|
20
|
+
if @name == @name.pluralize && !options[:force_plural]
|
21
|
+
logger.warning "Plural version of the model detected, using singularized version. Override with --force-plural."
|
22
|
+
@name = @name.singularize
|
23
|
+
end
|
24
|
+
|
25
|
+
@controller_name = @name.pluralize
|
26
|
+
@application_name = File.basename(Rails.root.to_s).humanize
|
27
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
28
|
+
@controller_class_name_without_nesting, @controller_underscore_name, @controller_plural_name = inflect_names(base_name)
|
29
|
+
@controller_singular_name = base_name.singularize
|
30
|
+
if @controller_class_nesting.empty?
|
31
|
+
@controller_class_name = @controller_class_name_without_nesting
|
32
|
+
else
|
33
|
+
@controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def manifest
|
38
|
+
record do |m|
|
39
|
+
|
40
|
+
# Check for class naming collisions.
|
41
|
+
m.class_collisions(controller_class_path, "#{controller_class_name}Controller", "#{controller_class_name}Helper")
|
42
|
+
m.class_collisions(class_path, "#{class_name}")
|
43
|
+
|
44
|
+
# Controller, helper, views, test and stylesheets directories.
|
45
|
+
m.directory(File.join('app/models', class_path))
|
46
|
+
m.directory(File.join('app/controllers', controller_class_path))
|
47
|
+
m.directory(File.join('app/helpers', controller_class_path))
|
48
|
+
m.directory(File.join('app/views', controller_class_path, controller_file_name))
|
49
|
+
# m.directory(File.join('test/functional', controller_class_path))
|
50
|
+
# m.directory(File.join('test/unit', class_path))
|
51
|
+
# m.directory(File.join('test/unit/helpers', class_path))
|
52
|
+
|
53
|
+
for action in scaffold_views
|
54
|
+
m.template("view_#{action}.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "#{action}.html.haml"))
|
55
|
+
end
|
56
|
+
|
57
|
+
m.template("_form.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "_form.html.haml"))
|
58
|
+
m.template("_object.html.haml.erb", File.join('app/views', controller_class_path, controller_file_name, "_#{name}.html.haml"))
|
59
|
+
m.template('controller.rb.erb', File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb"))
|
60
|
+
m.template('helper.rb.erb', File.join('app/helpers', controller_class_path, "#{controller_file_name}_helper.rb"))
|
61
|
+
m.directory('app/views/layouts')
|
62
|
+
m.directory('public/stylesheets/sass')
|
63
|
+
m.template('layout.html.haml.erb', 'app/views/layouts/application.html.haml', :collision => :skip, :assigns => {:application_name => @application_name})
|
64
|
+
m.template('stylesheet.sass', 'public/stylesheets/sass/application.sass', :collision => :skip)
|
65
|
+
m.route_resources controller_file_name
|
66
|
+
m.dependency 'model', [name] + @args, :collision => :skip
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
protected
|
73
|
+
# Override with your own usage banner.
|
74
|
+
def banner
|
75
|
+
"Usage: #{$0} haml_scaffold ModelName [field:type, field:type]"
|
76
|
+
end
|
77
|
+
|
78
|
+
def add_options!(opt)
|
79
|
+
opt.separator ''
|
80
|
+
opt.separator 'Options:'
|
81
|
+
opt.on("--skip-timestamps",
|
82
|
+
"Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
|
83
|
+
opt.on("--skip-migration",
|
84
|
+
"Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
|
85
|
+
opt.on("--force-plural",
|
86
|
+
"Forces the generation of a plural ModelName") { |v| options[:force_plural] = v }
|
87
|
+
end
|
88
|
+
|
89
|
+
def scaffold_views
|
90
|
+
%w[ index show new edit ]
|
91
|
+
end
|
92
|
+
|
93
|
+
def model_name
|
94
|
+
class_name.demodulize
|
95
|
+
end
|
96
|
+
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,21 @@
|
|
1
|
+
!!! XML
|
2
|
+
!!!
|
3
|
+
%html{ :'xml:lang' => "en", :lang => "en" }
|
4
|
+
%head
|
5
|
+
%title= "#{controller.class.to_s}: #{controller.action_name}"
|
6
|
+
%meta{ :"http-equiv" => "Content-Type", :content => "text/html; charset=utf-8" }
|
7
|
+
%link{ :rel => "shortcut icon", :href => "/favicon.ico" }
|
8
|
+
= stylesheet_link_tag "application", :media => "screen"
|
9
|
+
= javascript_include_tag :defaults
|
10
|
+
%body
|
11
|
+
#wrapper
|
12
|
+
#content
|
13
|
+
%h1 <%= application_name %>
|
14
|
+
#flash
|
15
|
+
- unless flash.empty?
|
16
|
+
= content_tag :div, flash[:notice], :class => "notice" if flash[:notice]
|
17
|
+
= content_tag :div, flash[:warning], :class => "warning" if flash[:warning]
|
18
|
+
= content_tag :div, flash[:error], :class => "error" if flash[:error]
|
19
|
+
:javascript
|
20
|
+
#{visual_effect :highlight, "flash"}
|
21
|
+
= yield
|
@@ -0,0 +1,6 @@
|
|
1
|
+
%h2 Editing <%= singular_name %>
|
2
|
+
= render :partial => "form", :locals => {:<%= singular_name %> => @<%= singular_name %>}
|
3
|
+
%ul
|
4
|
+
%li= link_to 'Show', @<%= singular_name %>
|
5
|
+
%li= link_to 'Back', <%= plural_name %>_path
|
6
|
+
%li= link_to 'Destroy', @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
|
@@ -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
|
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,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,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: haml_formtastic_scaffold
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
version: "1.0"
|
9
|
+
platform: ruby
|
10
|
+
authors:
|
11
|
+
- Matthew Soldo
|
12
|
+
autorequire:
|
13
|
+
bindir: bin
|
14
|
+
cert_chain: []
|
15
|
+
|
16
|
+
date: 2009-07-01 00:00:00 -07:00
|
17
|
+
default_executable:
|
18
|
+
dependencies:
|
19
|
+
- !ruby/object:Gem::Dependency
|
20
|
+
name: haml
|
21
|
+
prerelease: false
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
segments:
|
27
|
+
- 2
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
version: 2.0.6
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: will_paginate
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 2
|
42
|
+
- 2
|
43
|
+
- 2
|
44
|
+
version: 2.2.2
|
45
|
+
type: :runtime
|
46
|
+
version_requirements: *id002
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: formtastic
|
49
|
+
prerelease: false
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
- 9
|
57
|
+
- 8
|
58
|
+
version: 0.9.8
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: newgem
|
63
|
+
prerelease: false
|
64
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
segments:
|
69
|
+
- 1
|
70
|
+
- 4
|
71
|
+
- 1
|
72
|
+
version: 1.4.1
|
73
|
+
type: :development
|
74
|
+
version_requirements: *id004
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: hoe
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 8
|
85
|
+
- 0
|
86
|
+
version: 1.8.0
|
87
|
+
type: :development
|
88
|
+
version_requirements: *id005
|
89
|
+
description: Rails scaffolding with Haml and Formtastic rather than ERB, and various other improvements. Based the haml_scaffold by Norman Clarke.
|
90
|
+
email:
|
91
|
+
- haml_formtastic@soldo.org
|
92
|
+
executables: []
|
93
|
+
|
94
|
+
extensions: []
|
95
|
+
|
96
|
+
extra_rdoc_files:
|
97
|
+
- History.txt
|
98
|
+
- Manifest.txt
|
99
|
+
- README.rdoc
|
100
|
+
files:
|
101
|
+
- History.txt
|
102
|
+
- MIT-LICENSE
|
103
|
+
- Manifest.txt
|
104
|
+
- README.rdoc
|
105
|
+
- Rakefile
|
106
|
+
- generators/haml_scaffold/haml_scaffold_generator.rb
|
107
|
+
- generators/haml_scaffold/templates/_form.html.haml.erb
|
108
|
+
- generators/haml_scaffold/templates/_object.html.haml.erb
|
109
|
+
- generators/haml_scaffold/templates/controller.rb.erb
|
110
|
+
- generators/haml_scaffold/templates/helper.rb.erb
|
111
|
+
- generators/haml_scaffold/templates/layout.html.haml.erb
|
112
|
+
- generators/haml_scaffold/templates/stylesheet.sass
|
113
|
+
- generators/haml_scaffold/templates/view_edit.html.haml.erb
|
114
|
+
- generators/haml_scaffold/templates/view_index.html.haml.erb
|
115
|
+
- generators/haml_scaffold/templates/view_new.html.haml.erb
|
116
|
+
- generators/haml_scaffold/templates/view_show.html.haml.erb
|
117
|
+
- init.rb
|
118
|
+
- lib/haml_scaffold/version.rb
|
119
|
+
- samples/posts_controller.rb
|
120
|
+
- samples/views/_form.html.haml
|
121
|
+
- samples/views/_post.html.haml
|
122
|
+
- samples/views/edit.html.haml
|
123
|
+
- samples/views/index.html.haml
|
124
|
+
- samples/views/new.html.haml
|
125
|
+
- samples/views/show.html.haml
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: http://github.com/mattsoldo/rspec-haml-scaffold-generator/
|
128
|
+
licenses: []
|
129
|
+
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options:
|
132
|
+
- --main
|
133
|
+
- README.rdoc
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
segments:
|
148
|
+
- 0
|
149
|
+
version: "0"
|
150
|
+
requirements: []
|
151
|
+
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 1.3.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 3
|
156
|
+
summary: Rails scaffolding with Haml and Formtastic rather than ERB
|
157
|
+
test_files: []
|
158
|
+
|