Skip to content

Commit

Permalink
Update readme for templates
Browse files Browse the repository at this point in the history
  • Loading branch information
therabidbanana committed Apr 11, 2013
1 parent eda47a5 commit a650ee4
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions README.md
Expand Up @@ -20,7 +20,6 @@ RFC 6570 (level 4), providing support for IRIs and URI templates.

- {Addressable::URI}
- {Addressable::Template}
- {Addressable::UriTemplate}

# Example usage

Expand All @@ -38,32 +37,38 @@ uri.path
uri = Addressable::URI.parse("http://www.詹姆斯.com/")
uri.normalize
#=> #<Addressable::URI:0xc9a4c8 URI:http://www.xn--8ws00zhy3a.com/>
```


# URI Templates

For more details, see [RFC 6570](https://www.rfc-editor.org/rfc/rfc6570.txt).


```ruby

require "addressable/template"

template = Addressable::Template.new("http://example.com/{-list|+|query}/")
template = Addressable::Template.new("http://example.com/{?query*}/")
template.expand({
"query" => "an example query".split(" ")
"query" => {
'foo' => 'bar',
'color' => 'red'
}
})
#=> #<Addressable::URI:0xc9d95c URI:http://example.com/an+example+query/>
#=> #<Addressable::URI:0xc9d95c URI:http://example.com/?foo=bar&color=red>

template = Addressable::Template.new(
"http://example.com/{-join|&|one,two,three}/"
)
template = Addressable::Template.new("http://example.com/{?one,two,three}/")
template.partial_expand({"one" => "1", "three" => 3}).pattern
#=> "http://example.com/?one=1{-prefix|&two=|two}&three=3"
#=> "http://example.com/?one=1{&two}&three=3"

template = Addressable::Template.new(
"http://{host}/{-suffix|/|segments}?{-join|&|one,two,bogus}\#{fragment}"
)
template2 = Addressable::UriTemplate.new(
"http://{host}{/segments}/{?one,two,bogus}{#fragment}"
)
uri = Addressable::URI.parse(
"http://example.com/a/b/c/?one=1&two=2#foo"
)
template.extract(uri)
template2.extract(uri)
#=>
# {
# "host" => "example.com",
Expand Down

0 comments on commit a650ee4

Please sign in to comment.