A new application now comes with a layout and a stylesheet.

This commit is contained in:
José Valim 2010-04-06 00:12:28 +02:00
parent 4eab983b95
commit ea2c5fa804
17 changed files with 28 additions and 67 deletions

View File

@ -1,3 +1,5 @@
* A new application now comes with a layout and a stylesheet. [JV]
* Renamed config.cookie_secret to config.secret_token and pass it as env key. [JV]
*Rails 3.0.0 [beta 2] (April 1st, 2010)*

View File

@ -26,7 +26,6 @@ module Rails
:orm => '-o',
:resource_controller => '-c',
:scaffold_controller => '-c',
:stylesheets => '-y',
:template_engine => '-e',
:test_framework => '-t'
},
@ -56,7 +55,6 @@ module Rails
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:singleton => false,
:stylesheets => true,
:test_framework => nil,
:template_engine => :erb
},

View File

@ -25,12 +25,6 @@ module Erb
end
end
def copy_layout_file
return unless options[:layout]
template filename_with_extensions(:layout),
File.join("app/views/layouts", controller_class_path, filename_with_extensions(controller_file_name))
end
protected
def available_views

View File

@ -1,17 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title><%= controller_class_name %>: <%%= controller.action_name %></title>
<%%= stylesheet_link_tag 'scaffold' %>
<%%= javascript_include_tag :defaults %>
<%%= csrf_meta_tag %>
</head>
<body>
<p class="notice"><%%= notice %></p>
<p class="alert"><%%= alert %></p>
<%%= yield %>
</body>
</html>

View File

@ -137,7 +137,7 @@ module Rails::Generators
end
def create_public_stylesheets_files
empty_directory_with_gitkeep "public/stylesheets"
directory "public/stylesheets"
end
def create_prototype_files

View File

@ -1,3 +1,4 @@
class ApplicationController < ActionController::Base
protect_from_forgery
layout 'application'
end

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title><%= controller_name.humanize %>: <%= action_name %></title>
<%= stylesheet_link_tag 'application' %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<p class="notice"><%= notice %></p>
<p class="alert"><%= alert %></p>
<%= yield %>
</body>
</html>

View File

@ -7,7 +7,6 @@ module Rails
remove_class_option :actions
hook_for :scaffold_controller, :required => true
hook_for :stylesheets
end
end
end

View File

@ -1,5 +0,0 @@
Description:
Copies scaffold stylesheets to public/stylesheets/.
Examples:
`rails generate stylesheets`

View File

@ -1,9 +0,0 @@
module Rails
module Generators
class StylesheetsGenerator < Base
def copy_stylesheets_file
template "scaffold.css", "public/stylesheets/scaffold.css" if behavior == :invoke
end
end
end
end

View File

@ -51,6 +51,13 @@ class AppGeneratorTest < Rails::Generators::TestCase
).each{ |path| assert_file path }
end
def test_application_controller_and_layout_files
run_generator
assert_file "app/controllers/application_controller.rb", /layout 'application'/
assert_file "app/views/layouts/application.html.erb", /stylesheet_link_tag 'application'/
assert_file "public/stylesheets/application.css"
end
def test_name_collision_raises_an_error
content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] }
assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content

View File

@ -66,7 +66,6 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
new
show
).each { |view| assert_file "app/views/users/#{view}.html.erb" }
assert_file "app/views/layouts/users.html.erb"
end
def test_functional_tests

View File

@ -70,14 +70,10 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
show
_form
).each { |view| assert_file "app/views/product_lines/#{view}.html.erb" }
assert_file "app/views/layouts/product_lines.html.erb"
# Helpers
assert_file "app/helpers/product_lines_helper.rb"
assert_file "test/unit/helpers/product_lines_helper_test.rb"
# Stylesheets
assert_file "public/stylesheets/scaffold.css"
end
def test_scaffold_on_revoke
@ -101,13 +97,9 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase
# Views
assert_no_file "app/views/product_lines"
assert_no_file "app/views/layouts/product_lines.html.erb"
# Helpers
assert_no_file "app/helpers/product_lines_helper.rb"
assert_no_file "test/unit/helpers/product_lines_helper_test.rb"
# Stylesheets (should not be removed)
assert_file "public/stylesheets/scaffold.css"
end
end

View File

@ -1,17 +0,0 @@
require 'generators/generators_test_helper'
require 'rails/generators/rails/stylesheets/stylesheets_generator'
class StylesheetsGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper
def test_copy_stylesheets
run_generator
assert_file "public/stylesheets/scaffold.css"
end
def test_stylesheets_are_not_deleted_on_revoke
run_generator
run_generator [], :behavior => :revoke
assert_file "public/stylesheets/scaffold.css"
end
end