#1667 - Custom Route Matchers documentation updated to fix or remove error-prone examples

This commit is contained in:
Brian Olpin 2022-03-12 08:28:31 -08:00
parent 2b5d1b4509
commit 77e669cf53
9 changed files with 74 additions and 135 deletions

View File

@ -385,15 +385,16 @@ Routen-Muster erstellt werden:
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -410,20 +411,12 @@ Beachte, dass das obige Beispiel etwas übertrieben wirkt. Es geht auch
einfacher:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Oder unter Verwendung eines negativen look ahead:
```ruby
get %r{(?!/index)} do
# ...
end
```
## Statische Dateien
Statische Dateien werden im `./public`-Ordner erwartet. Es ist möglich,

View File

@ -345,15 +345,16 @@ get('/') { Stream.new }
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -369,20 +370,12 @@ end
ノート: この例はオーバースペックであり、以下のようにも書くことができます。
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
または、否定先読みを使って:
```ruby
get %r{(?!/index)} do
# ...
end
```
## 静的ファイル(Static Files)
静的ファイルは`./public`ディレクトリから配信されます。

View File

@ -339,15 +339,16 @@ get('/') { Stream.new }
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -363,20 +364,12 @@ end
사실 위의 예제는 조금 과하게 작성된 면이 있습니다. 간단하게 표현할 수도 있어요.
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
또는 거꾸로 탐색(negative look ahead)할 수도 있습니다.
```ruby
get %r{(?!/index)} do
# ...
end
```
## 정적 파일(Static Files)
정적 파일들은 `./public` 디렉터리에서 제공됩니다. 위치를 다른 곳으로

View File

@ -358,16 +358,18 @@ get('/') { Stream.new }
മുകളിൽ കാണിച്ചിരിക്കുന്ന പോലെ , സിനാട്ര ഉപയോഗിച്ച String patterns, regular expressions കൈകാര്യം ചെയ്യാം മാത്രമല്ല നിങ്ങളുടെ സ്വന്തം matchers ഉം ഉണ്ടാക്കാം
```ruby
class AllButPattern
Match = Struct.new(:captures)
class AllButPattern
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -383,20 +385,12 @@ end
ഇതിനെ ഇങ്ങനെയും കാണിക്കാം
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Or, using negative look ahead:
```ruby
get %r{(?!/index)} do
# ...
end
```
## Static Files
സ്റ്റാറ്റിക് ഫിലെസ് `./public` എന്ന ഡയറക്ടറി ഇത് ആണ് ഉണ്ടാകുക

View File

@ -380,15 +380,16 @@ stop there. You can easily define your own matchers:
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -405,20 +406,12 @@ Note that the above example might be over-engineered, as it can also be
expressed as:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Or, using negative look ahead:
```ruby
get %r{(?!/index)} do
# ...
end
```
## Static Files
Static files are served from the `./public` directory. You can specify

View File

@ -379,15 +379,16 @@ stop there. You can easily define your own matchers:
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -404,20 +405,12 @@ Note that the above example might be over-engineered, as it can also be
expressed as:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Or, using negative look ahead:
```ruby
get %r{(?!/index)} do
# ...
end
```
## Static Files
Static files are served from the `./public` directory. You can specify

View File

@ -396,15 +396,16 @@ facilmente definir os seus próprios validadores:
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -421,20 +422,12 @@ Note que o exemplo acima pode ser robusto e complicado em excesso. Pode
também ser implementado como:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Ou, usando algo mais denso à frente:
```ruby
get %r{(?!/index)} do
# ...
end
```
## Arquivos estáticos
Arquivos estáticos são disponibilizados a partir do diretório

View File

@ -382,15 +382,16 @@ get('/') { Stream.new }
```ruby
class AllButPattern
Match = Struct.new(:captures)
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -407,20 +408,12 @@ end
может быть реализован следующим образом:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
Или с использованием негативной опережающей проверки (отрицательное look-ahead условие):
```ruby
get %r{(?!/index)} do
# ...
end
```
## Статические файлы
Статические файлы раздаются из `./public` директории. Вы можете указать другое

View File

@ -347,16 +347,18 @@ get('/') { Stream.new }
本身支持使用字符串和正则表达式作为路由匹配。但不限于此,你可以轻松地定义自己的匹配器:
```ruby
class AllButPattern
Match = Struct.new(:captures)
class AllButPattern
def initialize(except)
@except = except
@captures = Match.new([])
@except = except
end
def match(str)
@captures unless @except === str
def to_pattern(options)
return self
end
def params(route)
return {} unless @except === route
end
end
@ -372,20 +374,12 @@ end
上面的例子可能太繁琐了, 因为它也可以用更简单的方式表述:
```ruby
get // do
get /.*/ do
pass if request.path_info == "/index"
# ...
end
```
或者,使用消极向前查找:
```ruby
get %r{(?!/index)} do
# ...
end
```
## 静态文件
静态文件从 `./public` 目录提供服务。可以通过设置`:public_folder` 选项设定一个不同的位置: