Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename public_folder to public_dir #427

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.de.rdoc
Expand Up @@ -244,9 +244,9 @@ Oder unter Verwendung eines negativen look ahead:

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

set :public_folder, File.dirname(__FILE__) + '/static'
set :public_dir, 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 @@ -1299,8 +1299,8 @@ Schutzmechanismen zu deaktivieren:
wird oder nicht. Weitere Informationen im vorhergehenden
Abschnitt.

[public_folder] Das öffentliche Verzeichnis, aus dem Daten zur
Verfügung gestellt werden können.
[public_dir] 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 @@ -240,9 +240,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_folder</tt>:
opción <tt>:public_dir</tt>:

set :public_folder, File.dirname(__FILE__) + '/estaticos'
set :public_dir, 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 @@ -1387,7 +1387,7 @@ O varias:
sección sobre la configuración de protección de ataques
más arriba.

[public_folder] path del directorio desde donde se sirven los archivos
[public_dir] path del directorio desde donde se sirven los archivos
públicos. Solo se utiliza cuando se sirven archivos
estáticos (ver la opción <tt>static</tt>). Si no
está presente, se infiere del valor de la opción
Expand Down
6 changes: 3 additions & 3 deletions README.fr.rdoc
Expand Up @@ -245,9 +245,9 @@ Ou bien en utilisant la forme négative :

Les fichiers du dossier <tt>./public</tt> sont servis de façon statique. Vous
avez la possibilité d'utiliser un autre répertoire en définissant le paramètre
<tt>:public_folder</tt> :
<tt>:public_dir</tt> :

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

Notez que le nom du dossier public n'apparait pas dans l'URL. Le fichier
<tt>./public/css/style.css</tt> sera appelé via l'URL :
Expand Down Expand Up @@ -1365,7 +1365,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_folder] dossier duquel les fichiers publics sont servis
[public_dir] 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_folder</tt> kapcsoló beállításával:
mégpedig a <tt>:public_dir</tt> kapcsoló beállításával:

set :public_folder, File.dirname(__FILE__) + '/static'
set :public_dir, 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_folder</tt>オプションを指定することで別の場所を指定することができます。
<tt>:public_dir</tt>オプションを指定することで別の場所を指定することができます。

set :public_folder, File.dirname(__FILE__) + '/static'
set :public_dir, 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_folder</tt>
um local diferente pela opção <tt>:public_dir</tt>

set :public_folder, File.dirname(__FILE__) + '/estatico'
set :public_dir, 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_folder</tt>
um local diferente através da opção <tt>:public_dir</tt>

set :public_folder, File.dirname(__FILE__) + '/estatico'
set :public_dir, 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 @@ -238,9 +238,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_folder</tt> option:
a different location by setting the <tt>:public_dir</tt> option:

set :public_folder, File.dirname(__FILE__) + '/static'
set :public_dir, 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 @@ -1335,7 +1335,7 @@ You can also hand in an array in order to disable a list of protections:
[protection] Whether or not to enable web attack protections. See
protection section above.

[public_folder] Path to the folder public files are served from. Only
[public_dir] Path to the folder public files are served from. Only
used if static file serving is enabled (see
<tt>static</tt> setting below). Inferred from
<tt>app_file</tt> setting if not set.
Expand Down
6 changes: 3 additions & 3 deletions README.ru.rdoc
Expand Up @@ -206,9 +206,9 @@ Thin - это более производительный и функциона
== Статические файлы

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

set :public_folder, File.dirname(__FILE__) + '/static'
set :public_dir, 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_folder] директория, откуда будут раздаваться статические файлы.
[public_dir] директория, откуда будут раздаваться статические файлы.

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

== 静态文件

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

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

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

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

[reload_templates] 是否每个请求都重新载入模板。
在development mode和 Ruby 1.8.6 中被企业(用来
Expand Down
15 changes: 10 additions & 5 deletions lib/sinatra/base.rb
Expand Up @@ -831,7 +831,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_folder).nil?
return if (public_dir = settings.public_dir).nil?
public_dir = File.expand_path(public_dir)

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a similar warning for public_folder too then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zzak Do you mean like the one that it's a few lines below? (from lines 1119 to 1122)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahahaha, yup! Must have missed that..

Good look!

set(:public_dir, value)
end

def public_folder=(value)
warn ":public_folder has been renamed to :public_dir"
set(:public_dir, value)
end

private
Expand Down Expand Up @@ -1516,8 +1521,8 @@ class << self
set :lock, false
set :threaded, true

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

error ::Exception do
Expand Down
4 changes: 2 additions & 2 deletions test/filter_test.rb
Expand Up @@ -125,7 +125,7 @@ class BeforeFilterTest < Test::Unit::TestCase
mock_app {
before { ran_filter = true }
set :static, true
set :public_folder, File.dirname(__FILE__)
set :public_dir, File.dirname(__FILE__)
}
get "/#{File.basename(__FILE__)}"
assert ok?
Expand Down Expand Up @@ -248,7 +248,7 @@ class AfterFilterTest < Test::Unit::TestCase
mock_app {
after { ran_filter = true }
set :static, true
set :public_folder, File.dirname(__FILE__)
set :public_dir, 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_folder is set and exists' do
it 'is enabled on Base when public_dir is set and exists' do
@base.set :environment, :development
@base.set :public_folder, File.dirname(__FILE__)
@base.set :public_dir, File.dirname(__FILE__)
assert @base.static?
end

it 'is enabled on Base when root is set and root/public_folder exists' do
it 'is enabled on Base when root is set and root/public_dir 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_folder is set and exists' do
it 'is enabled on Application when public_dir is set and exists' do
@application.set :environment, :development
@application.set :public_folder, File.dirname(__FILE__)
@application.set :public_dir, File.dirname(__FILE__)
assert @application.static?
end

it 'is enabled on Application when root is set and root/public_folder exists' do
it 'is enabled on Application when root is set and root/public_dir 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_folder' do
describe 'public_dir' do
it 'is nil if root is not set' do
assert @base.public_folder.nil?
assert @application.public_folder.nil?
assert @base.public_dir.nil?
assert @application.public_dir.nil?
end

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

@application.root = File.dirname(__FILE__)
assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
assert_equal File.dirname(__FILE__) + "/public", @application.public_dir
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_folder, File.dirname(__FILE__)
set :public_dir, 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_folder, nil
@app.set :public_dir, 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_folder, File.dirname(__FILE__) + '/data'
set :public_dir, File.dirname(__FILE__) + '/data'
}
get "/../#{File.basename(__FILE__)}"
assert not_found?
Expand Down