locale_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +7 -0
- data/NEWS +7 -0
- data/README +33 -0
- data/Rakefile +72 -0
- data/doc/classes/ActionController/Base.html +442 -0
- data/doc/classes/ActionController/Caching.html +348 -0
- data/doc/classes/ActionController/Caching/Fragments.html +424 -0
- data/doc/classes/ActionView/Base.html +422 -0
- data/doc/classes/I18n.html +492 -0
- data/doc/classes/Locale.html +364 -0
- data/doc/created.rid +1 -0
- data/doc/files/ChangeLog.html +355 -0
- data/doc/files/README.html +409 -0
- data/doc/files/lib/locale_rails/action_controller_rb.html +349 -0
- data/doc/files/lib/locale_rails/action_view_rb.html +349 -0
- data/doc/files/lib/locale_rails/i18n_rb.html +342 -0
- data/doc/files/lib/locale_rails/version_rb.html +342 -0
- data/doc/files/lib/locale_rails_rb.html +349 -0
- data/doc/fr_class_index.html +7 -0
- data/doc/fr_file_index.html +8 -0
- data/doc/fr_method_index.html +11 -0
- data/doc/index.html +1 -0
- data/doc/rdoc-style.css +320 -0
- data/lib/locale_rails.rb +18 -0
- data/lib/locale_rails/action_controller.rb +141 -0
- data/lib/locale_rails/action_view.rb +43 -0
- data/lib/locale_rails/i18n.rb +56 -0
- data/lib/locale_rails/version.rb +4 -0
- data/locale_rails-0.1.0.gem +0 -0
- data/sample/README +22 -0
- data/sample/Rakefile +10 -0
- data/sample/app/controllers/application.rb +41 -0
- data/sample/app/controllers/samples_controller.rb +30 -0
- data/sample/app/helpers/application_helper.rb +3 -0
- data/sample/app/views/layouts/samples.html.erb +20 -0
- data/sample/app/views/samples/#cookie.rb# +3 -0
- data/sample/app/views/samples/_part.html.erb +68 -0
- data/sample/app/views/samples/_part_nl.html.erb +2 -0
- data/sample/app/views/samples/cached_action.html.erb +6 -0
- data/sample/app/views/samples/index.html.erb +24 -0
- data/sample/app/views/samples/index_uz_UZ.html.erb +15 -0
- data/sample/config/boot.rb +109 -0
- data/sample/config/database.yml +22 -0
- data/sample/config/environment.rb +25 -0
- data/sample/config/environments/development.rb +17 -0
- data/sample/config/environments/production.rb +24 -0
- data/sample/config/environments/test.rb +22 -0
- data/sample/config/initializers/inflections.rb +10 -0
- data/sample/config/initializers/mime_types.rb +5 -0
- data/sample/config/initializers/new_rails_defaults.rb +17 -0
- data/sample/config/routes.rb +13 -0
- data/sample/db/development.sqlite3 +0 -0
- data/sample/db/production.sqlite3 +0 -0
- data/sample/doc/README_FOR_APP +2 -0
- data/sample/log/development.log +2573 -0
- data/sample/log/production.log +80 -0
- data/sample/public/404.html +30 -0
- data/sample/public/422.html +30 -0
- data/sample/public/500.html +33 -0
- data/sample/public/dispatch.cgi +10 -0
- data/sample/public/dispatch.fcgi +24 -0
- data/sample/public/dispatch.rb +10 -0
- data/sample/public/favicon.ico +0 -0
- data/sample/public/images/rails.png +0 -0
- data/sample/public/javascripts/application.js +2 -0
- data/sample/public/javascripts/controls.js +963 -0
- data/sample/public/javascripts/dragdrop.js +972 -0
- data/sample/public/javascripts/effects.js +1120 -0
- data/sample/public/javascripts/prototype.js +4221 -0
- data/sample/public/robots.txt +5 -0
- data/sample/public/stylesheets/locale.css +81 -0
- data/sample/public/stylesheets/scaffold.css +74 -0
- data/sample/script/about +4 -0
- data/sample/script/console +3 -0
- data/sample/script/dbconsole +3 -0
- data/sample/script/destroy +3 -0
- data/sample/script/generate +3 -0
- data/sample/script/performance/benchmarker +3 -0
- data/sample/script/performance/profiler +3 -0
- data/sample/script/performance/request +3 -0
- data/sample/script/plugin +3 -0
- data/sample/script/process/inspector +3 -0
- data/sample/script/process/reaper +3 -0
- data/sample/script/process/spawner +3 -0
- data/sample/script/runner +3 -0
- data/sample/script/server +3 -0
- data/sample/test/performance/browsing_test.rb +9 -0
- data/sample/test/test_helper.rb +38 -0
- metadata +195 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
=begin
|
2
|
+
locale_rails/lib/action_view.rb - Ruby/Locale for "Ruby on Rails"
|
3
|
+
|
4
|
+
Copyright (C) 2008 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
Original: Ruby-GetText-Package-1.92.0
|
10
|
+
|
11
|
+
$Id: action_view.rb 23 2008-11-24 09:22:35Z mutoh $
|
12
|
+
=end
|
13
|
+
|
14
|
+
require 'action_view'
|
15
|
+
|
16
|
+
module ActionView #:nodoc:
|
17
|
+
class Base
|
18
|
+
def _pick_template_with_locale_main(template_path, tags)
|
19
|
+
path = template_path.sub(/^\//, '')
|
20
|
+
if m = path.match(/(.*)\.(\w+)$/)
|
21
|
+
template_file_name, template_file_extension = m[1], m[2]
|
22
|
+
else
|
23
|
+
template_file_name = path
|
24
|
+
end
|
25
|
+
|
26
|
+
tags.each do |v|
|
27
|
+
file_name = "#{template_file_name}_#{v}"
|
28
|
+
begin
|
29
|
+
return _pick_template_without_locale(file_name)
|
30
|
+
rescue MissingTemplate => e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
_pick_template_without_locale(template_path)
|
34
|
+
end
|
35
|
+
memoize :_pick_template_with_locale_main
|
36
|
+
|
37
|
+
def _pick_template_with_locale(template_path) #: shouldn't memoize.
|
38
|
+
_pick_template_with_locale_main(template_path, I18n.candidates)
|
39
|
+
end
|
40
|
+
alias_method_chain :_pick_template, :locale
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
=begin
|
2
|
+
locale_rails/lib/i18n.rb - Ruby/Locale for "Ruby on Rails"
|
3
|
+
|
4
|
+
Copyright (C) 2008 Masao Mutoh
|
5
|
+
|
6
|
+
You may redistribute it and/or modify it under the same
|
7
|
+
license terms as Ruby.
|
8
|
+
|
9
|
+
$Id: i18n.rb 25 2008-11-30 15:44:24Z mutoh $
|
10
|
+
=end
|
11
|
+
|
12
|
+
module I18n
|
13
|
+
@@supported_locales = nil
|
14
|
+
module_function
|
15
|
+
|
16
|
+
# Gets the supported locales.
|
17
|
+
def supported_locales
|
18
|
+
@@supported_locales
|
19
|
+
end
|
20
|
+
|
21
|
+
# Sets the supported locales as an Array.
|
22
|
+
# I18n.supported_locales = ["ja-JP", "ko-KR"]
|
23
|
+
def supported_locales=(tags)
|
24
|
+
@@supported_locales = tags
|
25
|
+
end
|
26
|
+
|
27
|
+
# Sets the locale.
|
28
|
+
# I18n.locale = "ja-JP"
|
29
|
+
def locale=(tag)
|
30
|
+
Locale.clear
|
31
|
+
Locale.current = tag
|
32
|
+
Thread.current[:locale] = candidates(:rfc)[0]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get the locale candidates as a Locale::TagList.
|
36
|
+
# This is the utility function which calls Locale.candidates with
|
37
|
+
# supported_language_tags.
|
38
|
+
#
|
39
|
+
# I18n.locale is also overrided by Ruby-Locale and it returns
|
40
|
+
# the result of this method with :rfc option.
|
41
|
+
#
|
42
|
+
# +type+ :simple, :common(default), :rfc, :cldr.
|
43
|
+
#
|
44
|
+
# This is used by Rails application, but it may be better not to
|
45
|
+
# use this method in Rails plugins/libraries, because they have their
|
46
|
+
# own supported languages.
|
47
|
+
def candidates(type = :common)
|
48
|
+
default = [I18n.default_locale.to_s]
|
49
|
+
default = ["en-US", "en"] if default[0] == "en-US"
|
50
|
+
Locale.candidates(:type => type,
|
51
|
+
:supported_language_tags => supported_locales,
|
52
|
+
:default_language_tags => default)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
Binary file
|
data/sample/README
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== Ruby-Locale for Ruby on Rails sample application
|
2
|
+
This is the sample application for localization.
|
3
|
+
|
4
|
+
=== Includes
|
5
|
+
1. How to get current language.
|
6
|
+
2. Auto-Detect the locale from the WWW browser
|
7
|
+
3. Set locale as the "lang" parameter
|
8
|
+
4. Set "lang" as the cookie value
|
9
|
+
5. Localized Routes
|
10
|
+
6. Action caching
|
11
|
+
7. Separate Localized View template file
|
12
|
+
|
13
|
+
== Installation
|
14
|
+
|
15
|
+
1. Instal rails-2.2.x.
|
16
|
+
2. Install sqlite3-ruby
|
17
|
+
gem install sqlite3-ruby
|
18
|
+
3. Install locale_rails
|
19
|
+
gem install locale_rails
|
20
|
+
4. rake db:create
|
21
|
+
5. ruby script/server
|
22
|
+
6. Access http://localhost:3000/ from the WWW browser.
|
data/sample/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
helper :all # include all helpers, all the time
|
6
|
+
|
7
|
+
# See ActionController::RequestForgeryProtection for details
|
8
|
+
# Uncomment the :secret if you're not using the cookie session store
|
9
|
+
protect_from_forgery # :secret => '639df270d82028344f5a50f543530c57'
|
10
|
+
|
11
|
+
# See ActionController::Base for details
|
12
|
+
# Uncomment this to filter the contents of submitted sensitive data parameters
|
13
|
+
# from your application log (in this case, all fields with names like "password").
|
14
|
+
# filter_parameter_logging :password
|
15
|
+
|
16
|
+
# Set the charset of Content-Type.
|
17
|
+
# This is not Ruby-Locale method but useful.
|
18
|
+
# self.default_charset = "iso8859-1"
|
19
|
+
|
20
|
+
=begin
|
21
|
+
def before_init_i18n
|
22
|
+
# Initialize other i18n libraries before init_locale if you need.
|
23
|
+
# Or set "lang" to it's own value before initializing Locale.
|
24
|
+
if (cookies["lang"].nil? or cookies["lang"].empty?)
|
25
|
+
params["lang"] = "ko_KR"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
before_init_locale :before_init_i18n
|
29
|
+
|
30
|
+
def after_init_i18n
|
31
|
+
# Initialize other i18n libraries after init_locale if you need.
|
32
|
+
#
|
33
|
+
# LocalizeFoo.locale = Locale.current
|
34
|
+
# I18n.locale is set in init_locale, but other I18n features
|
35
|
+
# is not set by Ruby-Locale. So you may need to add the code to work your
|
36
|
+
# Rails i18n plugins.
|
37
|
+
end
|
38
|
+
after_init_locale :after_init_i18n
|
39
|
+
=end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class SamplesController < ApplicationController
|
2
|
+
caches_action :cached_action
|
3
|
+
|
4
|
+
def index
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_cookie
|
8
|
+
flash[:notice] = "Cookie lang value is: " + params[:id]
|
9
|
+
|
10
|
+
cookies["lang"] = params[:id]
|
11
|
+
|
12
|
+
respond_to do |format|
|
13
|
+
format.html { redirect_to :action => "index" }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def clear_cookie
|
18
|
+
cookies["lang"] = nil
|
19
|
+
|
20
|
+
flash[:notice] = "Cookie lang value is cleared. "
|
21
|
+
respond_to do |format|
|
22
|
+
format.html { redirect_to :action => "index" }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cached_action
|
27
|
+
p "cached_action. This is shown first time only."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%= Locale.current.to_rfc %>" lang="<%= Locale.current.to_rfc %>">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html;charset=<%= Locale.charset %>" />
|
7
|
+
<title>Ruby-Locale Sample on Ruby on Rails: <%= controller.action_name %></title>
|
8
|
+
<%= stylesheet_link_tag 'scaffold' %>
|
9
|
+
<%= stylesheet_link_tag 'locale' %>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<p style="color: red"><%= flash[:notice] %></p>
|
13
|
+
|
14
|
+
<%= yield %>
|
15
|
+
|
16
|
+
<div class="copyright">
|
17
|
+
Copyright (C) 2008 Masao Mutoh
|
18
|
+
</div>
|
19
|
+
</body>
|
20
|
+
</html>
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<%
|
2
|
+
app_lang_tags = ["ja_JP", "fr", "pt_BR", "zh_CN", "en_Latn_US_NYNORSK", "uz_UZ", "nl"]
|
3
|
+
%>
|
4
|
+
|
5
|
+
<h2>Get the current locale</h2>
|
6
|
+
<h3>I18n.candidates(with no option)</h3>
|
7
|
+
<p>Requested Locales order by the priority. This method is added by Ruby-Locale for Ruby on Rails.</p>
|
8
|
+
<div class="result">
|
9
|
+
<%=h I18n.candidates.inspect %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<h3>I18n.locale (with inspect)</h3>
|
13
|
+
<p>I18n.locale is set the result(Locale::TagList) of locale_candidates(:type => :rfc).<br/>
|
14
|
+
This method is extended by Ruby-Locale for Ruby on Rails and returns all candidates as the Locale::TagList.
|
15
|
+
</p>
|
16
|
+
<div class="result">
|
17
|
+
<%=h I18n.locale.inspect %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<h3>I18n.locale (without inspect)</h3>
|
21
|
+
<p>Locale::TagList(the result of I18n.locale) can behave like a single tag string to follow I18n.locale specification.</p>
|
22
|
+
<div class="result">
|
23
|
+
<%=h I18n.locale %>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<h2>Auto-Detect the locale from the WWW browser</h2>
|
27
|
+
<p><a href="<%= samples_path %>">Reload this URL</a></p>
|
28
|
+
|
29
|
+
<h2>Set locale as the "lang" parameter</h2>
|
30
|
+
|
31
|
+
<ol>
|
32
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
33
|
+
url = samples_path(:lang => lang) %>
|
34
|
+
<li><%= link_to h(url), url %> [<%= lang %>]</li>
|
35
|
+
<% end %>
|
36
|
+
</ol>
|
37
|
+
|
38
|
+
<h2>Set "lang" as the cookie value.</h2>
|
39
|
+
<p>Click one of the link below, and then click "Auto-Detect the locale from the WWW browser".</p>
|
40
|
+
|
41
|
+
<ol>
|
42
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
43
|
+
url = url_for(:controller => :samples, :action => :set_cookie, :id => lang) %>
|
44
|
+
<li><%= link_to h(url), {:action => :set_cookie, :id => lang} %> [<%= lang %>]</li>
|
45
|
+
<% end %>
|
46
|
+
<li><%= link_to "Clear cookie", :action => :clear_cookie %> </li>
|
47
|
+
</ol>
|
48
|
+
|
49
|
+
<h2>Localized Routes</h2>
|
50
|
+
<p>See config/routes.rb</p>
|
51
|
+
|
52
|
+
<ol>
|
53
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
54
|
+
url = url_for(:controller => :samples, :lang => lang, :action => :index) %>
|
55
|
+
<li><%= link_to h(url),:controller => :samples, :lang => lang, :action => :index %> [<%= lang %>]</li>
|
56
|
+
<% end %>
|
57
|
+
</ol>
|
58
|
+
|
59
|
+
<h2>Caching</h2>
|
60
|
+
<p>Fragment/Action caching is supported. Here is the sample for action caching. <br/>
|
61
|
+
Click the links then check %{RAILS_ROOT}/tmp/cache/ where Cached file is stored.
|
62
|
+
</p>
|
63
|
+
<ol>
|
64
|
+
<% (app_lang_tags - ["uz_UZ", "nl"]).each do |lang|
|
65
|
+
url = url_for(:controller => :samples, :action => :cached_action, :lang => lang) %>
|
66
|
+
<li><%= link_to h(url), {:controller => :samples, :action => :cached_action, :lang => lang} %> [<%= lang %>]</li>
|
67
|
+
<% end %>
|
68
|
+
</ol>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<p style="color:red">This page is cached for [<%= I18n.locale %>]. <br/>
|
5
|
+
See %{RAILS_ROOT}/tmp/cache/*.</p>
|
6
|
+
<p><%= link_to "[BACK]", samples_path %></p>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<h2>The values from Rails</h2>
|
5
|
+
<table border="1" cellspacing="0" cellpadding="2">
|
6
|
+
<tr><th>Variables</th><th>Values</th></tr>
|
7
|
+
<tr><td>HTTP_ACCEPT_LANGUAGE</td><td> <%= request.cgi.accept_language %></td></tr>
|
8
|
+
<tr><td>HTTP_ACCEPT_CHARSET</td><td> <%= request.cgi.accept_charset %></td></tr>
|
9
|
+
<tr><td>QUERY_STRING</td><td> <%= request.cgi.query_string %></td></tr>
|
10
|
+
<tr><td>params[:lang]</td><td><%= params[:lang] %></td></tr>
|
11
|
+
<tr><td>cookies[:lang]</td><td> <%= cookies[:lang] %></td></tr>
|
12
|
+
</table>
|
13
|
+
|
14
|
+
<%= render :partial => 'part' %>
|
15
|
+
|
16
|
+
<h2>Separate Localized View template file in each languages</h2>
|
17
|
+
<p>View template can be separeted with language tags.</p>
|
18
|
+
<ol>
|
19
|
+
<li><%= link_to "uz_UZ has special index page(index_uz_UZ.html.erb)", :controller => :samples, :action => :index, :lang => "uz_UZ" %></li>
|
20
|
+
<li><%= link_to "uz uses normal index page", :controller => :samples, :action => :index, :lang => "uz" %></li>
|
21
|
+
<li><%= link_to "nl has special _part page(_part_nl.html.erb)", :controller => :samples, :action => :index, :lang => "nl" %></li>
|
22
|
+
<li><%= link_to "nl_BE also uses the special _part page(_part_nl.html.erb)", :controller => :samples, :action => :index, :lang => "nl_BE" %></li>
|
23
|
+
</ol>
|
24
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<h1>Ruby-Locale and Ruby on Rails 2.2 sample</h1>
|
2
|
+
<p><a href ="http://locale.rubyforge.org/svn/trunk/locale_rails/sample">[source code]</a></p>
|
3
|
+
|
4
|
+
<h2>The values from Rails</h2>
|
5
|
+
<table border="1" cellspacing="0" cellpadding="2">
|
6
|
+
<tr><th>Variables</th><th>Values</th></tr>
|
7
|
+
<tr><td>HTTP_ACCEPT_LANGUAGE</td><td> <%= request.cgi.accept_language %></td></tr>
|
8
|
+
<tr><td>HTTP_ACCEPT_CHARSET</td><td> <%= request.cgi.accept_charset %></td></tr>
|
9
|
+
<tr><td>QUERY_STRING</td><td> <%= request.cgi.query_string %></td></tr>
|
10
|
+
<tr><td>params[:lang]</td><td><%= params[:lang] %></td></tr>
|
11
|
+
<tr><td>cookies[:lang]</td><td> <%= cookies[:lang] %></td></tr>
|
12
|
+
</table>
|
13
|
+
|
14
|
+
<p style="color:red">This page is for uz_UZ only. See app/views/samples/index_uz_UZ.html.erb.</p>
|
15
|
+
<p><%= link_to "[BACK]", samples_path %></p>
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
3
|
+
|
4
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
5
|
+
|
6
|
+
module Rails
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
preinitialize
|
11
|
+
pick_boot.run
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def booted?
|
16
|
+
defined? Rails::Initializer
|
17
|
+
end
|
18
|
+
|
19
|
+
def pick_boot
|
20
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
21
|
+
end
|
22
|
+
|
23
|
+
def vendor_rails?
|
24
|
+
File.exist?("#{RAILS_ROOT}/vendor/rails")
|
25
|
+
end
|
26
|
+
|
27
|
+
def preinitialize
|
28
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
def preinitializer_path
|
32
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Boot
|
37
|
+
def run
|
38
|
+
load_initializer
|
39
|
+
Rails::Initializer.run(:set_load_path)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class VendorBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
|
46
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class GemBoot < Boot
|
51
|
+
def load_initializer
|
52
|
+
self.class.load_rubygems
|
53
|
+
load_rails_gem
|
54
|
+
require 'initializer'
|
55
|
+
end
|
56
|
+
|
57
|
+
def load_rails_gem
|
58
|
+
if version = self.class.gem_version
|
59
|
+
gem 'rails', version
|
60
|
+
else
|
61
|
+
gem 'rails'
|
62
|
+
end
|
63
|
+
rescue Gem::LoadError => load_error
|
64
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
65
|
+
exit 1
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def rubygems_version
|
70
|
+
Gem::RubyGemsVersion if defined? Gem::RubyGemsVersion
|
71
|
+
end
|
72
|
+
|
73
|
+
def gem_version
|
74
|
+
if defined? RAILS_GEM_VERSION
|
75
|
+
RAILS_GEM_VERSION
|
76
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
77
|
+
ENV['RAILS_GEM_VERSION']
|
78
|
+
else
|
79
|
+
parse_gem_version(read_environment_rb)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_rubygems
|
84
|
+
require 'rubygems'
|
85
|
+
min_version = '1.1.1'
|
86
|
+
unless rubygems_version >= min_version
|
87
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
88
|
+
exit 1
|
89
|
+
end
|
90
|
+
|
91
|
+
rescue LoadError
|
92
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
93
|
+
exit 1
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_gem_version(text)
|
97
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def read_environment_rb
|
102
|
+
File.read("#{RAILS_ROOT}/config/environment.rb")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# All that for this:
|
109
|
+
Rails.boot!
|