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

Uri template support #27

Merged
merged 1 commit into from Apr 2, 2013
Merged

Conversation

adstage-david
Copy link

Replacing the dynamic urls via blocks in pr #26.

Some uri template examples:

set_url "/users{/username}" # 1.
set_url "/pages{+slug}" # 2.
set_url "/search{?query*}" # 3.
set_url "/index" # 4.

#1.
Page.new.load(username: 'bob') #=> visit /users/bob
Page.new.load #=> visit /users

#url takes expansions as well:

Page.new.url(username: 'bob') #=> /users/bob

#2.
Page.new.load(slug: '/my/crazy-slug') #=> visit /pages/my/crazy-slug

#3
Page.new.load(query: 'simple') #=> visit /search?query=simple
Page.new.load(query: {color: 'red', text: 'blue'}) #=> visit /search?color=red&text=blue

#4
Page.new.load(query: 'simple') #=> visit /index
Page.new.load(a: 1, b: 2) #=> visit /index

@adstage-david
Copy link
Author

I should note I just noticed this one doesn't seem to work - it wants string keys, rather than symbol keys. Possibly a bug in the addressable implementation:

Page.new.load(query: {color: 'red', text: 'blue'})

the stringified keys version should work though (one of the specs in my commit tests this case):

Page.new.load(query: {'color'=> 'red', 'text'=> 'blue'})

natritmeyer added a commit that referenced this pull request Apr 2, 2013
@natritmeyer natritmeyer merged commit baa8bed into natritmeyer:master Apr 2, 2013
@natritmeyer
Copy link
Owner

Thanks for this! I need to update the README.rb before I release it... I'll try to get to this ASAP...

@natritmeyer
Copy link
Owner

README.md updated...

@sillylogger
Copy link

I was going to try to forge a pull request to this effect tonight. Thanks!

What are your thoughts on taking the hash in the constructor? Then you could check to see if that page is loaded.

@abotalov
Copy link
Contributor

abotalov commented Apr 5, 2013

What are your thoughts on taking the hash in the constructor? Then you could check to see if that page is loaded.

@natritmeyer Will you accept a PR on that?

@natritmeyer
Copy link
Owner

I may do in the future but not now. I want to see how this change goes first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants