#1667 - Custom Route Matchers documentation updated to fix or remove error-prone examples
This commit is contained in:
parent
2b5d1b4509
commit
77e669cf53
23
README.de.md
23
README.de.md
|
@ -385,15 +385,16 @@ Routen-Muster erstellt werden:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -410,20 +411,12 @@ Beachte, dass das obige Beispiel etwas übertrieben wirkt. Es geht auch
|
||||||
einfacher:
|
einfacher:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Oder unter Verwendung eines negativen look ahead:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Statische Dateien
|
## Statische Dateien
|
||||||
|
|
||||||
Statische Dateien werden im `./public`-Ordner erwartet. Es ist möglich,
|
Statische Dateien werden im `./public`-Ordner erwartet. Es ist möglich,
|
||||||
|
|
23
README.ja.md
23
README.ja.md
|
@ -345,15 +345,16 @@ get('/') { Stream.new }
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -369,20 +370,12 @@ end
|
||||||
ノート: この例はオーバースペックであり、以下のようにも書くことができます。
|
ノート: この例はオーバースペックであり、以下のようにも書くことができます。
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
または、否定先読みを使って:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## 静的ファイル(Static Files)
|
## 静的ファイル(Static Files)
|
||||||
|
|
||||||
静的ファイルは`./public`ディレクトリから配信されます。
|
静的ファイルは`./public`ディレクトリから配信されます。
|
||||||
|
|
23
README.ko.md
23
README.ko.md
|
@ -339,15 +339,16 @@ get('/') { Stream.new }
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -363,20 +364,12 @@ end
|
||||||
사실 위의 예제는 조금 과하게 작성된 면이 있습니다. 간단하게 표현할 수도 있어요.
|
사실 위의 예제는 조금 과하게 작성된 면이 있습니다. 간단하게 표현할 수도 있어요.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
또는 거꾸로 탐색(negative look ahead)할 수도 있습니다.
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## 정적 파일(Static Files)
|
## 정적 파일(Static Files)
|
||||||
|
|
||||||
정적 파일들은 `./public` 디렉터리에서 제공됩니다. 위치를 다른 곳으로
|
정적 파일들은 `./public` 디렉터리에서 제공됩니다. 위치를 다른 곳으로
|
||||||
|
|
|
@ -358,16 +358,18 @@ get('/') { Stream.new }
|
||||||
|
|
||||||
മുകളിൽ കാണിച്ചിരിക്കുന്ന പോലെ , സിനാട്ര ഉപയോഗിച്ച String patterns, regular expressions കൈകാര്യം ചെയ്യാം മാത്രമല്ല നിങ്ങളുടെ സ്വന്തം matchers ഉം ഉണ്ടാക്കാം
|
മുകളിൽ കാണിച്ചിരിക്കുന്ന പോലെ , സിനാട്ര ഉപയോഗിച്ച String patterns, regular expressions കൈകാര്യം ചെയ്യാം മാത്രമല്ല നിങ്ങളുടെ സ്വന്തം matchers ഉം ഉണ്ടാക്കാം
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
|
class AllButPattern
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -383,20 +385,12 @@ end
|
||||||
ഇതിനെ ഇങ്ങനെയും കാണിക്കാം
|
ഇതിനെ ഇങ്ങനെയും കാണിക്കാം
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, using negative look ahead:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Static Files
|
## Static Files
|
||||||
|
|
||||||
സ്റ്റാറ്റിക് ഫിലെസ് `./public` എന്ന ഡയറക്ടറി ഇത് ആണ് ഉണ്ടാകുക
|
സ്റ്റാറ്റിക് ഫിലെസ് `./public` എന്ന ഡയറക്ടറി ഇത് ആണ് ഉണ്ടാകുക
|
||||||
|
|
23
README.md
23
README.md
|
@ -380,15 +380,16 @@ stop there. You can easily define your own matchers:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -405,20 +406,12 @@ Note that the above example might be over-engineered, as it can also be
|
||||||
expressed as:
|
expressed as:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, using negative look ahead:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Static Files
|
## Static Files
|
||||||
|
|
||||||
Static files are served from the `./public` directory. You can specify
|
Static files are served from the `./public` directory. You can specify
|
||||||
|
|
23
README.pl.md
23
README.pl.md
|
@ -379,15 +379,16 @@ stop there. You can easily define your own matchers:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -404,20 +405,12 @@ Note that the above example might be over-engineered, as it can also be
|
||||||
expressed as:
|
expressed as:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Or, using negative look ahead:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Static Files
|
## Static Files
|
||||||
|
|
||||||
Static files are served from the `./public` directory. You can specify
|
Static files are served from the `./public` directory. You can specify
|
||||||
|
|
|
@ -396,15 +396,16 @@ facilmente definir os seus próprios validadores:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -421,20 +422,12 @@ Note que o exemplo acima pode ser robusto e complicado em excesso. Pode
|
||||||
também ser implementado como:
|
também ser implementado como:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Ou, usando algo mais denso à frente:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Arquivos estáticos
|
## Arquivos estáticos
|
||||||
|
|
||||||
Arquivos estáticos são disponibilizados a partir do diretório
|
Arquivos estáticos são disponibilizados a partir do diretório
|
||||||
|
|
23
README.ru.md
23
README.ru.md
|
@ -382,15 +382,16 @@ get('/') { Stream.new }
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
class AllButPattern
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -407,20 +408,12 @@ end
|
||||||
может быть реализован следующим образом:
|
может быть реализован следующим образом:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
Или с использованием негативной опережающей проверки (отрицательное look-ahead условие):
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## Статические файлы
|
## Статические файлы
|
||||||
|
|
||||||
Статические файлы раздаются из `./public` директории. Вы можете указать другое
|
Статические файлы раздаются из `./public` директории. Вы можете указать другое
|
||||||
|
|
24
README.zh.md
24
README.zh.md
|
@ -347,16 +347,18 @@ get('/') { Stream.new }
|
||||||
本身支持使用字符串和正则表达式作为路由匹配。但不限于此,你可以轻松地定义自己的匹配器:
|
本身支持使用字符串和正则表达式作为路由匹配。但不限于此,你可以轻松地定义自己的匹配器:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class AllButPattern
|
|
||||||
Match = Struct.new(:captures)
|
|
||||||
|
|
||||||
|
class AllButPattern
|
||||||
def initialize(except)
|
def initialize(except)
|
||||||
@except = except
|
@except = except
|
||||||
@captures = Match.new([])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(str)
|
def to_pattern(options)
|
||||||
@captures unless @except === str
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
def params(route)
|
||||||
|
return {} unless @except === route
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -372,20 +374,12 @@ end
|
||||||
上面的例子可能太繁琐了, 因为它也可以用更简单的方式表述:
|
上面的例子可能太繁琐了, 因为它也可以用更简单的方式表述:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
get // do
|
get /.*/ do
|
||||||
pass if request.path_info == "/index"
|
pass if request.path_info == "/index"
|
||||||
# ...
|
# ...
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
或者,使用消极向前查找:
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
get %r{(?!/index)} do
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
## 静态文件
|
## 静态文件
|
||||||
|
|
||||||
静态文件从 `./public` 目录提供服务。可以通过设置`:public_folder` 选项设定一个不同的位置:
|
静态文件从 `./public` 目录提供服务。可以通过设置`:public_folder` 选项设定一个不同的位置:
|
||||||
|
|
Loading…
Reference in New Issue