Skip to content

Commit

Permalink
rename public to public_folder, fixes #301
Browse files Browse the repository at this point in the history
  • Loading branch information
rkh committed Jun 15, 2011
1 parent 2d89712 commit d1ab58d
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 52 deletions.
8 changes: 4 additions & 4 deletions README.de.rdoc
Expand Up @@ -210,10 +210,10 @@ Oder unter Verwendung eines negativen look ahead:
== Statische Dateien

Statische Dateien werden aus dem <tt>./public</tt>-Ordner ausgeliefert. Es ist
möglich, einen anderen Ort zu definieren, indem man die <tt>:public</tt>-Option
setzt:
möglich, einen anderen Ort zu definieren, indem man die
<tt>:public_folder</tt>-Option setzt:

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

Zu beachten ist, dass der Ordnername public nicht Teil der URL ist. Die Datei
<tt>./public/css/style.css</tt> ist unter
Expand Down Expand Up @@ -1159,7 +1159,7 @@ Diese Einstellungen sind über +settings+ erreichbar:
<tt>redirect to('/foo')</tt>. Standardmäßig nicht
aktiviert.

[public] Das öffentliche Verzeichnis, aus dem Daten zur
[public_folder] Das öffentliche Verzeichnis, aus dem Daten zur
Verfügung gestellt werden können.

[reload_templates] Im development-Modus aktiviert.
Expand Down
6 changes: 3 additions & 3 deletions README.es.rdoc
Expand Up @@ -209,9 +209,9 @@ O, usando un lookahead negativo:

Los archivos estáticos son servidos desde el directorio público
<tt>./public</tt>. Podés especificar una ubicación diferente ajustando la
opción <tt>:public</tt>:
opción <tt>:public_folder</tt>:

set :public, File.dirname(__FILE__) + '/estaticos'
set :public_folder, File.dirname(__FILE__) + '/estaticos'

Notá que el nombre del directorio público no está incluido en la URL. Por
ejemplo, el archivo <tt>./public/css/style.css</tt> se accede a través de
Expand Down Expand Up @@ -1228,7 +1228,7 @@ Podés acceder a estas opciones utilizando el método <tt>settings</tt>:
que <tt>redirect to('/foo')</tt>. Se encuentra
deshabilitada por defecto.

[public] directorio desde donde se sirven los archivos públicos.
[public_folder] directorio desde donde se sirven los archivos públicos.

[reload_templates] define si se recargan las plantillas entre peticiones.

Expand Down
6 changes: 3 additions & 3 deletions README.fr.rdoc
Expand Up @@ -209,9 +209,9 @@ Ou bien en utilisant la forme négative :

Par défaut, le dossier <tt>./public</tt> est utilisé pour servir les fichiers
statiques. Vous pouvez changer ce dossier pour un autre nom grâce au paramètre
<tt>:public</tt> :
<tt>:public_folder</tt> :

set :public, File.dirname(__FILE__) + '/statique'
set :public_folder, File.dirname(__FILE__) + '/statique'

Notez que le nom du dossier public n'est pas inclus dans l'URL. Un fichier
sous <tt>./public/css/style.css</tt> est appelé avec l'URL : <tt>http://exemple.com/css/style.css</tt>.
Expand Down Expand Up @@ -1243,7 +1243,7 @@ Vous pouvez accéder à ces paramètres via <tt>settings</tt> :
comportera comme <tt>redirect to('/foo')</tt>.
Désactivé par défaut.

[public] dossier duquel les fichiers publics sont servis
[public_folder] dossier duquel les fichiers publics sont servis

[reload_templates] si oui ou non les templates doivent être rechargés
entre les requêtes. Activé en mode développement.
Expand Down
4 changes: 2 additions & 2 deletions README.hu.rdoc
Expand Up @@ -99,9 +99,9 @@ tervezhetők, így például az user agent karakterláncot alapul véve:

A statikus fájlok kiszolgálása a <tt>./public</tt> könyvtárból
történik, de természetesen más könyvtárat is megadhatsz erre a célra,
mégpedig a <tt>:public</tt> kapcsoló beállításával:
mégpedig a <tt>:public_folder</tt> kapcsoló beállításával:

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

Fontos mgejegyezni, hogy a nyilvános könyvtár neve nem szerepel az URL-ben.
A <tt>./public/css/style.css</tt> fájl az
Expand Down
4 changes: 2 additions & 2 deletions README.jp.rdoc
Expand Up @@ -153,9 +153,9 @@ Rackレスポンス、Rackボディオブジェクト、HTTPステータスコ
== 静的ファイル

静的ファイルは<tt>./public</tt>ディレクトリから配信されます。
<tt>:public</tt>オプションを指定することで別の場所を指定することができます。
<tt>:public_folder</tt>オプションを指定することで別の場所を指定することができます。

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

注意: この静的ファイル用のディレクトリ名はURL中に含まれません。
例えば、<tt>./public/css/style.css</tt>は<tt>http://example.com/css/style.css</tt>でアクセスできます。
Expand Down
4 changes: 2 additions & 2 deletions README.pt-br.rdoc
Expand Up @@ -95,9 +95,9 @@ Rotas podem incluir uma variedade de condições correspondes, tal como o agente
== Arquivos estáticos

Arquivos estáticos são disponibilizados a partir do diretório <tt>./public</tt>. Você pode especificar
um local diferente pela opção <tt>:public</tt>
um local diferente pela opção <tt>:public_folder</tt>

set :public, File.dirname(__FILE__) + '/estatico'
set :public_folder, File.dirname(__FILE__) + '/estatico'

Note que o nome do diretório público não é incluido na URL. Um arquivo
<tt>./public/css/style.css</tt> é disponibilizado como
Expand Down
4 changes: 2 additions & 2 deletions README.pt-pt.rdoc
Expand Up @@ -95,9 +95,9 @@ Rotas podem incluir uma variedade de condições correspondentes, por exemplo, o
== Arquivos estáticos

Arquivos estáticos são disponibilizados a partir do directório <tt>./public</tt>. Você pode especificar
um local diferente através da opção <tt>:public</tt>
um local diferente através da opção <tt>:public_folder</tt>

set :public, File.dirname(__FILE__) + '/estatico'
set :public_folder, File.dirname(__FILE__) + '/estatico'

Note que o nome do directório público não é incluido no URL. Um arquivo
<tt>./public/css/style.css</tt> é disponibilizado como
Expand Down
6 changes: 3 additions & 3 deletions README.rdoc
Expand Up @@ -208,9 +208,9 @@ Or, using negative look ahead:
== Static Files

Static files are served from the <tt>./public</tt> directory. You can specify
a different location by setting the <tt>:public</tt> option:
a different location by setting the <tt>:public_folder</tt> option:

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

Note that the public directory name is not included in the URL. A file
<tt>./public/css/style.css</tt> is made available as
Expand Down Expand Up @@ -1184,7 +1184,7 @@ You can access those options via <tt>settings</tt>:
<tt>redirect '/foo'</tt> would behave like
<tt>redirect to('/foo')</tt>. Disabled per default.

[public] folder public files are served from
[public_folder] folder public files are served from

[reload_templates] whether or not to reload templates between requests.
Enabled in development mode.
Expand Down
6 changes: 3 additions & 3 deletions README.ru.rdoc
Expand Up @@ -206,9 +206,9 @@ Thin - это более производительный и функциона
== Статические файлы

Статические файлы отдаются из <tt>./public</tt> директории. Вы можете указать другое место,
указав его через опцию <tt>:public</tt>:
указав его через опцию <tt>:public_folder</tt>:

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

Учтите, что имя директории со статическими файлами не включено в URL. Например, файл
<tt>./public/css/style.css</tt> будет доступен как
Expand Down Expand Up @@ -1182,7 +1182,7 @@ Thin - это более производительный и функциона
если не задан абсолютный путь. Таким образом, <tt>redirect '/foo'</tt>
будет вести себя как <tt>redirect to('/foo')</tt>. Отключено по умолчанию.

[public] директория, откуда будут раздаваться статические файлы.
[public_folder] директория, откуда будут раздаваться статические файлы.

[reload_templates] перезагружать или нет шаблоны на каждый запрос.
Включено в режиме разработки.
Expand Down
6 changes: 3 additions & 3 deletions README.zh.rdoc
Expand Up @@ -194,10 +194,10 @@ Rack body对象或者HTTP状态码:

== 静态文件

静态文件是从 <tt>./public</tt> 目录提供服务。你可以通过设置<tt>:public</tt>
静态文件是从 <tt>./public_folder</tt> 目录提供服务。你可以通过设置<tt>:public</tt>
选项设定一个不同的位置:

set :public, File.dirname(__FILE__) + '/static'
set :public_folder, File.dirname(__FILE__) + '/static'

请注意public目录名并没有被包含在URL之中。文件
<tt>./public/css/style.css</tt>是通过
Expand Down Expand Up @@ -1268,7 +1268,7 @@ Sinatra会自动处理range请求。
<tt>redirect '/foo'</tt> 会和
<tt>redirect to('/foo')</tt>起相同作用。默认禁用。

[public] public文件夹的位置。
[public_folder] public文件夹的位置。

[reload_templates] 是否每个请求都重新载入模板。
在development mode和 Ruby 1.8.6 中被企业(用来
Expand Down
33 changes: 24 additions & 9 deletions lib/sinatra/base.rb
Expand Up @@ -408,7 +408,7 @@ def erb(template, options={}, locals={})

def erubis(template, options={}, locals={})
warn "Sinatra::Templates#erubis is deprecated and will be removed, use #erb instead.\n" \
"If you have Erubis installed, it will be used automatically.\n\tfrom #{caller.first}"
"If you have Erubis installed, it will be used automatically."
render :erubis, template, options, locals
end

Expand Down Expand Up @@ -623,7 +623,7 @@ def settings

def options
warn "Sinatra::Base#options is deprecated and will be removed, " \
"use #settings instead.\n\tfrom #{caller.first}"
"use #settings instead."
settings
end

Expand Down Expand Up @@ -735,7 +735,7 @@ def route_missing
# Attempt to serve static files from public directory. Throws :halt when
# a matching file is found, returns nil otherwise.
def static!
return if (public_dir = settings.public).nil?
return if (public_dir = settings.public_folder).nil?
public_dir = File.expand_path(public_dir)

path = File.expand_path(public_dir + unescape(request.path_info))
Expand Down Expand Up @@ -1011,6 +1011,11 @@ def condition(name = "#{caller.first[/`.*'/]} condition", &block)
@conditions << generate_method(name, &block)
end

def public=(value)
warn ":public is no longer used to avoid overloading Module#public, use :public_folder instead"
set(:public_folder, value)
end

private
# Condition for matching host name. Parameter might be String or Regexp.
def host_name(pattern)
Expand Down Expand Up @@ -1291,16 +1296,26 @@ def synchronize(&block)
# Like Kernel#caller but excluding certain magic entries and without
# line / method information; the resulting array contains filenames only.
def caller_files
caller_locations.
map { |file,line| file }
cleaned_caller(1).flatten
end

# Like caller_files, but containing Arrays rather than strings with the
# first element being the file, and the second being the line.
def caller_locations
cleaned_caller 2
end

private
# used for deprecation warnings
def warn(message)
super message + "\n\tfrom #{cleaned_caller.first.join(':')}"
end

# Like Kernel#caller but excluding certain magic entries
def cleaned_caller(keep = 3)
caller(1).
map { |line| line.split(/:(?=\d|in )/)[0,2] }.
reject { |file,line| CALLERS_TO_IGNORE.any? { |pattern| file =~ pattern } }
map { |line| line.split(/:(?=\d|in )/, 3)[0,keep] }.
reject { |file, *_| CALLERS_TO_IGNORE.any? { |pattern| file =~ pattern } }
end
end

Expand Down Expand Up @@ -1370,8 +1385,8 @@ class << self
set :reload_templates, Proc.new { development? }
set :lock, false

set :public, Proc.new { root && File.join(root, 'public') }
set :static, Proc.new { public && File.exist?(public) }
set :public_folder, Proc.new { root && File.join(root, 'public') }
set :static, Proc.new { public_folder && File.exist?(public_folder) }
set :static_cache_control, false

error ::Exception do
Expand Down
4 changes: 2 additions & 2 deletions test/filter_test.rb
Expand Up @@ -114,7 +114,7 @@ class BeforeFilterTest < Test::Unit::TestCase
mock_app {
before { ran_filter = true }
set :static, true
set :public, File.dirname(__FILE__)
set :public_folder, File.dirname(__FILE__)
}
get "/#{File.basename(__FILE__)}"
assert ok?
Expand Down Expand Up @@ -237,7 +237,7 @@ class AfterFilterTest < Test::Unit::TestCase
mock_app {
after { ran_filter = true }
set :static, true
set :public, File.dirname(__FILE__)
set :public_folder, File.dirname(__FILE__)
}
get "/#{File.basename(__FILE__)}"
assert ok?
Expand Down
22 changes: 11 additions & 11 deletions test/settings_test.rb
Expand Up @@ -359,13 +359,13 @@ def foo=(value)
assert ! @base.static?
end

it 'is enabled on Base when public is set and exists' do
it 'is enabled on Base when public_folder is set and exists' do
@base.set :environment, :development
@base.set :public, File.dirname(__FILE__)
@base.set :public_folder, File.dirname(__FILE__)
assert @base.static?
end

it 'is enabled on Base when root is set and root/public exists' do
it 'is enabled on Base when root is set and root/public_folder exists' do
@base.set :environment, :development
@base.set :root, File.dirname(__FILE__)
assert @base.static?
Expand All @@ -375,13 +375,13 @@ def foo=(value)
assert ! @application.static?
end

it 'is enabled on Application when public is set and exists' do
it 'is enabled on Application when public_folder is set and exists' do
@application.set :environment, :development
@application.set :public, File.dirname(__FILE__)
@application.set :public_folder, File.dirname(__FILE__)
assert @application.static?
end

it 'is enabled on Application when root is set and root/public exists' do
it 'is enabled on Application when root is set and root/public_folder exists' do
@application.set :environment, :development
@application.set :root, File.dirname(__FILE__)
assert @application.static?
Expand Down Expand Up @@ -469,18 +469,18 @@ def pub; end
end
end

describe 'public' do
describe 'public_folder' do
it 'is nil if root is not set' do
assert @base.public.nil?
assert @application.public.nil?
assert @base.public_folder.nil?
assert @application.public_folder.nil?
end

it 'is set to root joined with public/' do
@base.root = File.dirname(__FILE__)
assert_equal File.dirname(__FILE__) + "/public", @base.public
assert_equal File.dirname(__FILE__) + "/public", @base.public_folder

@application.root = File.dirname(__FILE__)
assert_equal File.dirname(__FILE__) + "/public", @application.public
assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/static_test.rb
Expand Up @@ -4,7 +4,7 @@ class StaticTest < Test::Unit::TestCase
setup do
mock_app {
set :static, true
set :public, File.dirname(__FILE__)
set :public_folder, File.dirname(__FILE__)
}
end

Expand Down Expand Up @@ -66,7 +66,7 @@ class StaticTest < Test::Unit::TestCase
end

it 'passes to the next handler when the public option is nil' do
@app.set :public, nil
@app.set :public_folder, nil
get "/#{File.basename(__FILE__)}"
assert not_found?
end
Expand All @@ -85,7 +85,7 @@ class StaticTest < Test::Unit::TestCase
it '404s when .. path traverses outside of public directory' do
mock_app {
set :static, true
set :public, File.dirname(__FILE__) + '/data'
set :public_folder, File.dirname(__FILE__) + '/data'
}
get "/../#{File.basename(__FILE__)}"
assert not_found?
Expand Down

0 comments on commit d1ab58d

Please sign in to comment.