aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails.rb9
-rw-r--r--railties/lib/rails/application/configuration.rb24
-rw-r--r--railties/lib/rails/engine/configuration.rb2
-rw-r--r--railties/lib/rails/generators.rb2
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb11
-rw-r--r--railties/lib/rails/generators/erb/scaffold/templates/show.html.erb2
-rw-r--r--railties/lib/rails/generators/rails/app/app_generator.rb4
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb17
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt14
-rw-r--r--railties/lib/rails/generators/rails/app/templates/config/application.rb5
-rw-r--r--railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js73
-rw-r--r--railties/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory0
-rw-r--r--railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt (renamed from railties/lib/rails/generators/rails/app/templates/test/test_helper.rb)2
-rw-r--r--railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb1
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/USAGE5
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb9
-rw-r--r--railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css (renamed from railties/lib/rails/generators/rails/app/templates/public/stylesheets/application.css)11
-rw-r--r--railties/lib/rails/test_unit/testing.rake18
-rw-r--r--railties/lib/rails/version.rb2
19 files changed, 131 insertions, 80 deletions
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index 9d02da104d..0611b2a9f5 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -79,6 +79,10 @@ module Rails
@_env ||= ActiveSupport::StringInquirer.new(ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
end
+ def env=(environment)
+ @_env = ActiveSupport::StringInquirer.new(environment)
+ end
+
def cache
RAILS_CACHE
end
@@ -88,11 +92,12 @@ module Rails
end
def public_path
- @@public_path ||= self.root ? File.join(self.root, "public") : "public"
+ application && application.paths.public.to_a.first
end
def public_path=(path)
- @@public_path = path
+ ActiveSupport::Deprecation.warn "Setting Rails.public_path= is deprecated. " <<
+ "Please set paths.public = in config/application.rb instead.", caller
end
end
end
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index d3e4742e8a..7ce3494fa6 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -6,21 +6,29 @@ module Rails
include ::Rails::Configuration::Deprecated
attr_accessor :allow_concurrency, :cache_classes, :cache_store,
- :secret_token, :consider_all_requests_local, :dependency_loading,
+ :encoding, :consider_all_requests_local, :dependency_loading,
:filter_parameters, :log_level, :logger, :metals,
:plugins, :preload_frameworks, :reload_engines, :reload_plugins,
- :serve_static_assets, :time_zone, :whiny_nils
+ :secret_token, :serve_static_assets, :time_zone, :whiny_nils
def initialize(*)
super
- @allow_concurrency = false
- @filter_parameters = []
- @dependency_loading = true
+ @allow_concurrency = false
+ @consider_all_requests_local = false
+ @encoding = "utf-8"
+ @filter_parameters = []
+ @dependency_loading = true
@serve_static_assets = true
- @time_zone = "UTC"
- @consider_all_requests_local = true
@session_store = :cookie_store
@session_options = {}
+ @time_zone = "UTC"
+ end
+
+ def encoding=(value)
+ @encoding = value
+ if defined?(Encoding) && Encoding.respond_to?(:default_external=)
+ Encoding.default_external = value
+ end
end
def middleware
@@ -129,7 +137,7 @@ module Rails
def default_middleware_stack
ActionDispatch::MiddlewareStack.new.tap do |middleware|
- middleware.use('::ActionDispatch::Static', lambda { Rails.public_path }, :if => lambda { serve_static_assets })
+ middleware.use('::ActionDispatch::Static', lambda { paths.public.to_a.first }, :if => lambda { serve_static_assets })
middleware.use('::Rack::Lock', :if => lambda { !allow_concurrency })
middleware.use('::Rack::Runtime')
middleware.use('::Rails::Rack::Logger')
diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb
index 28e7ef947d..c5411a0331 100644
--- a/railties/lib/rails/engine/configuration.rb
+++ b/railties/lib/rails/engine/configuration.rb
@@ -43,7 +43,7 @@ module Rails
end
def load_once_paths
- @eager_load_paths ||= paths.load_once
+ @load_once_paths ||= paths.load_once
end
def load_paths
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb
index 5f93dbf18f..9bc019b152 100644
--- a/railties/lib/rails/generators.rb
+++ b/railties/lib/rails/generators.rb
@@ -26,6 +26,7 @@ module Rails
:orm => '-o',
:resource_controller => '-c',
:scaffold_controller => '-c',
+ :stylesheets => '-y',
:template_engine => '-e',
:test_framework => '-t'
},
@@ -50,6 +51,7 @@ module Rails
:resource_controller => :controller,
:scaffold_controller => :scaffold_controller,
:singleton => false,
+ :stylesheets => true,
:test_framework => nil,
:template_engine => :erb
},
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
index 01ec58c615..0615a34a85 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/_form.html.erb
@@ -1,5 +1,14 @@
<%%= form_for(@<%= singular_name %>) do |f| %>
- <%%= f.error_messages %>
+ <%% if @<%= singular_name %>.errors.any? %>
+ <div id="errorExplanation">
+ <h2><%%= pluralize(@<%= singular_name %>.errors.count, "error") %> prohibited this <%= singular_name %> from being saved:</h2>
+ <ul>
+ <%% @<%= singular_name %>.errors.full_messages.each do |msg| %>
+ <li><%%= msg %></li>
+ <%% end %>
+ </ul>
+ </div>
+ <%% end %>
<% for attribute in attributes -%>
<div class="field">
diff --git a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
index 24f13fc0f8..4dd2e6bf8c 100644
--- a/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
+++ b/railties/lib/rails/generators/erb/scaffold/templates/show.html.erb
@@ -1,3 +1,5 @@
+<p class="notice"><%%= notice %></p>
+
<% for attribute in attributes -%>
<p>
<b><%= attribute.human_name %>:</b>
diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb
index df6e98f38d..bb2a080286 100644
--- a/railties/lib/rails/generators/rails/app/app_generator.rb
+++ b/railties/lib/rails/generators/rails/app/app_generator.rb
@@ -78,7 +78,7 @@ module Rails::Generators
end
def create_app_files
- directory "app"
+ directory 'app'
end
def create_config_files
@@ -137,7 +137,7 @@ module Rails::Generators
end
def create_public_stylesheets_files
- directory "public/stylesheets"
+ empty_directory_with_gitkeep "public/stylesheets"
end
def create_prototype_files
diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb
deleted file mode 100644
index 6b87d9d3ec..0000000000
--- a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb
+++ /dev/null
@@ -1,17 +0,0 @@
-<!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>
-
-<%=raw yield %>
-
-</body>
-</html>
diff --git a/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
new file mode 100644
index 0000000000..1dd112b4a6
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title><%= app_const_base %></title>
+ <%%= stylesheet_link_tag :all %>
+ <%%= javascript_include_tag :defaults %>
+ <%%= csrf_meta_tag %>
+</head>
+<body>
+
+<%%= yield %>
+
+</body>
+</html>
diff --git a/railties/lib/rails/generators/rails/app/templates/config/application.rb b/railties/lib/rails/generators/rails/app/templates/config/application.rb
index bd4fedcdec..0066e2b0c2 100644
--- a/railties/lib/rails/generators/rails/app/templates/config/application.rb
+++ b/railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -46,7 +46,10 @@ module <%= app_const_base %>
# g.test_framework :test_unit, :fixture => true
# end
+ # Configure the default encoding used in templates for Ruby 1.9.
+ config.encoding = "utf-8"
+
# Configure sensitive parameters which will be filtered from the log file.
- config.filter_parameters << :password
+ config.filter_parameters += [:password]
end
end
diff --git a/railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js b/railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js
index 7342e1b830..c5fa02ae35 100644
--- a/railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js
+++ b/railties/lib/rails/generators/rails/app/templates/public/javascripts/rails.js
@@ -1,15 +1,8 @@
document.observe("dom:loaded", function() {
- var authToken = $$('meta[name=csrf-token]').first().readAttribute('content'),
- authParam = $$('meta[name=csrf-param]').first().readAttribute('content'),
- formTemplate = '<form method="#{method}" action="#{action}">\
- #{realmethod}<input name="#{param}" value="#{token}" type="hidden">\
- </form>',
- realmethodTemplate = '<input name="_method" value="#{method}" type="hidden">';
-
function handleRemote(element) {
var method, url, params;
- if (element.tagName.toLowerCase() == 'form') {
+ if (element.tagName.toLowerCase() === 'form') {
method = element.readAttribute('method') || 'post';
url = element.readAttribute('action');
params = element.serialize(true);
@@ -39,65 +32,81 @@ document.observe("dom:loaded", function() {
element.fire("ajax:after");
}
+ function handleMethod(element) {
+ var method, url, token_name, token;
+
+ method = element.readAttribute('data-method');
+ url = element.readAttribute('href');
+ csrf_param = $$('meta[name=csrf-param]').first();
+ csrf_token = $$('meta[name=csrf-token]').first();
+
+ var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
+ element.parentNode.appendChild(form);
+
+ if (method != 'post') {
+ var field = new Element('input', { type: 'hidden', name: '_method', value: method });
+ form.appendChild(field);
+ }
+
+ if (csrf_param) {
+ var param = csrf_param.readAttribute('content');
+ var token = csrf_token.readAttribute('content');
+ var field = new Element('input', { type: 'hidden', name: param, value: token });
+ form.appendChild(field);
+ }
+
+ form.submit();
+ }
+
$(document.body).observe("click", function(event) {
- var message = event.element().readAttribute('data-confirm');
+ var message = event.findElement().readAttribute('data-confirm');
if (message && !confirm(message)) {
event.stop();
return false;
}
- var element = event.findElement("a[data-remote=true]");
+ var element = event.findElement("a[data-remote]");
if (element) {
handleRemote(element);
event.stop();
+ return true;
}
var element = event.findElement("a[data-method]");
- if (element && element.readAttribute('data-remote') != 'true') {
- var method = element.readAttribute('data-method'),
- piggyback = method.toLowerCase() != 'post',
- formHTML = formTemplate.interpolate({
- method: 'POST',
- realmethod: piggyback ? realmethodTemplate.interpolate({ method: method }) : '',
- action: element.readAttribute('href'),
- token: authToken,
- param: authParam
- });
-
- var form = new Element('div').update(formHTML).down().hide();
- this.insert({ bottom: form });
-
- form.submit();
+ if (element) {
+ handleMethod(element);
event.stop();
+ return true;
}
});
// TODO: I don't think submit bubbles in IE
$(document.body).observe("submit", function(event) {
- var message = event.element().readAttribute('data-confirm');
+ var element = event.findElement(),
+ message = element.readAttribute('data-confirm');
if (message && !confirm(message)) {
event.stop();
return false;
}
- var inputs = event.element().select("input[type=submit][data-disable-with]");
+ var inputs = element.select("input[type=submit][data-disable-with]");
inputs.each(function(input) {
input.disabled = true;
input.writeAttribute('data-original-value', input.value);
input.value = input.readAttribute('data-disable-with');
});
- var element = event.findElement("form[data-remote=true]");
+ var element = event.findElement("form[data-remote]");
if (element) {
handleRemote(element);
event.stop();
}
});
- $(document.body).observe("ajax:complete", function(event) {
- var element = event.element();
+ $(document.body).observe("ajax:after", function(event) {
+ var element = event.findElement();
- if (element.tagName.toLowerCase() == 'form') {
+ if (element.tagName.toLowerCase() === 'form') {
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
inputs.each(function(input) {
input.value = input.readAttribute('data-original-value');
@@ -106,4 +115,4 @@ document.observe("dom:loaded", function() {
});
}
});
-});
+}); \ No newline at end of file
diff --git a/railties/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory b/railties/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/public/stylesheets/.empty_directory
diff --git a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt
index 8bf1192ffe..86564031f5 100644
--- a/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb
+++ b/railties/lib/rails/generators/rails/app/templates/test/test_helper.rb.tt
@@ -3,11 +3,13 @@ require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
+<% unless options[:skip_activerecord] -%>
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting
fixtures :all
+<% end -%>
# Add more helper methods to be used by all tests here...
end
diff --git a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
index bd156f399c..779f933785 100644
--- a/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
+++ b/railties/lib/rails/generators/rails/scaffold/scaffold_generator.rb
@@ -7,6 +7,7 @@ module Rails
remove_class_option :actions
hook_for :scaffold_controller, :required => true
+ hook_for :stylesheets
end
end
end
diff --git a/railties/lib/rails/generators/rails/stylesheets/USAGE b/railties/lib/rails/generators/rails/stylesheets/USAGE
new file mode 100644
index 0000000000..59e5495d0b
--- /dev/null
+++ b/railties/lib/rails/generators/rails/stylesheets/USAGE
@@ -0,0 +1,5 @@
+Description:
+ Copies scaffold stylesheets to public/stylesheets/.
+
+Examples:
+ `rails generate stylesheets`
diff --git a/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb b/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
new file mode 100644
index 0000000000..ce68443c39
--- /dev/null
+++ b/railties/lib/rails/generators/rails/stylesheets/stylesheets_generator.rb
@@ -0,0 +1,9 @@
+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
diff --git a/railties/lib/rails/generators/rails/app/templates/public/stylesheets/application.css b/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css
index ea3dc9b8b5..f3f46d8b98 100644
--- a/railties/lib/rails/generators/rails/app/templates/public/stylesheets/application.css
+++ b/railties/lib/rails/generators/rails/stylesheets/templates/scaffold.css
@@ -35,10 +35,10 @@ div.field, div.actions {
}
#errorExplanation {
- width: 400px;
+ width: 450px;
border: 2px solid red;
padding: 7px;
- padding-bottom: 12px;
+ padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
}
@@ -49,16 +49,11 @@ div.field, div.actions {
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
+ margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
-#errorExplanation p {
- color: #333;
- margin-bottom: 0;
- padding: 5px;
-}
-
#errorExplanation ul li {
font-size: 12px;
list-style: square;
diff --git a/railties/lib/rails/test_unit/testing.rake b/railties/lib/rails/test_unit/testing.rake
index 57857fb911..23b8f92abd 100644
--- a/railties/lib/rails/test_unit/testing.rake
+++ b/railties/lib/rails/test_unit/testing.rake
@@ -52,7 +52,11 @@ task :test do
end
namespace :test do
- Rake::TestTask.new(:recent => "db:test:prepare") do |t|
+ task :prepare do
+ # Placeholder task for other Railtie and plugins to enhance. See Active Record for an example.
+ end
+
+ Rake::TestTask.new(:recent => "test:prepare") do |t|
since = TEST_CHANGES_SINCE
touched = FileList['test/**/*_test.rb'].select { |path| File.mtime(path) > since } +
recent_tests('app/models/**/*.rb', 'test/unit', since) +
@@ -63,7 +67,7 @@ namespace :test do
end
Rake::Task['test:recent'].comment = "Test recent changes"
- Rake::TestTask.new(:uncommitted => "db:test:prepare") do |t|
+ Rake::TestTask.new(:uncommitted => "test:prepare") do |t|
def t.file_list
if File.directory?(".svn")
changed_since_checkin = silence_stderr { `svn status` }.map { |path| path.chomp[7 .. -1] }
@@ -86,32 +90,32 @@ namespace :test do
end
Rake::Task['test:uncommitted'].comment = "Test changes since last checkin (only Subversion and Git)"
- Rake::TestTask.new(:units => "db:test:prepare") do |t|
+ Rake::TestTask.new(:units => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/unit/**/*_test.rb'
end
Rake::Task['test:units'].comment = "Run the unit tests in test/unit"
- Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
+ Rake::TestTask.new(:functionals => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/functional/**/*_test.rb'
end
Rake::Task['test:functionals'].comment = "Run the functional tests in test/functional"
- Rake::TestTask.new(:integration => "db:test:prepare") do |t|
+ Rake::TestTask.new(:integration => "test:prepare") do |t|
t.libs << "test"
t.pattern = 'test/integration/**/*_test.rb'
end
Rake::Task['test:integration'].comment = "Run the integration tests in test/integration"
- Rake::TestTask.new(:benchmark => 'db:test:prepare') do |t|
+ Rake::TestTask.new(:benchmark => 'test:prepare') do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
t.options = '-- --benchmark'
end
Rake::Task['test:benchmark'].comment = 'Benchmark the performance tests'
- Rake::TestTask.new(:profile => 'db:test:prepare') do |t|
+ Rake::TestTask.new(:profile => 'test:prepare') do |t|
t.libs << 'test'
t.pattern = 'test/performance/**/*_test.rb'
end
diff --git a/railties/lib/rails/version.rb b/railties/lib/rails/version.rb
index 7c47cbeabd..c10876134a 100644
--- a/railties/lib/rails/version.rb
+++ b/railties/lib/rails/version.rb
@@ -3,7 +3,7 @@ module Rails
MAJOR = 3
MINOR = 0
TINY = 0
- BUILD = "beta2"
+ BUILD = "beta3"
STRING = [MAJOR, MINOR, TINY, BUILD].join('.')
end