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

Routes path specs #135

Merged
merged 6 commits into from
Dec 17, 2014
Merged

Routes path specs #135

merged 6 commits into from
Dec 17, 2014

Conversation

le0pard
Copy link
Member

@le0pard le0pard commented Dec 8, 2014

Based by #123 , but here we don't have separate function spec to get spec of route. We override toString for route function, and this give for us to get function spec in this way:

Routes.users_path // => "/users(.:format)"
Routes.users_path.required_params // => []
Routes.users_path() // => "/users"
Routes.user_path // => "/users/:id(.:format)"
Routes.user_path.required_params // => ['id']
Routes.user_path(1) // => "/users/1"


context "when params" do
it "should show inbox spec" do
expect(evaljs("Routes.inbox_path.params").map{|v| v }).to eq(["_id", "options"])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've implemented _ as a prefix for parameter name for the case of collision with javascript reserved word. Ex. /returns/:return - JS function generated from this route using previous implementation required the underscore otherwise JS would not complile function(return, options) {} because of reserved name return.

I think this solution is not required now at all and params should return id without underscore.

@le0pard
Copy link
Member Author

le0pard commented Dec 8, 2014

@bogdan fixed.

@le0pard
Copy link
Member Author

le0pard commented Dec 11, 2014

@bogdan ping :)

@@ -192,6 +215,15 @@ Utils =
prefix

#
# route function: create route path function and add spec to it
#
route: (required_params, required_parts, optional_parts, route_spec) ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the difference between required_params and required_parts? Why can't we use only one of them?

@le0pard
Copy link
Member Author

le0pard commented Dec 11, 2014

Fixed

#{route_name}: function(#{build_params(required_parts)}) {
return Utils.build_path(#{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments);
}#{",\n" + url_link if url_link.length > 0}
#{route_name}: Utils.route(#{build_params(required_parts, true)}, #{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments)#{",\n" + url_link if url_link.length > 0}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It will be hard to guess the required parameters based on currently generated code:

inbox_message_path: Utils.route(["inbox_id", "id"], "inbox_id", "id", ....)

If we can not make it clear than lets make an extra line of comments that shows the correct function signature, like:

// function(inbox_id, id, options)

@le0pard
Copy link
Member Author

le0pard commented Dec 11, 2014

Done :)

@bogdan
Copy link
Collaborator

bogdan commented Dec 11, 2014

It will be hard to guess the required parameters based on currently generated code:

inbox_message_path: Utils.route(["inbox_id", "id"], ["format"], ....)

If we can not make it clear than lets make an extra line of comments that shows the correct function signature, like:

// function(inbox_id, id, options)

@le0pard
Copy link
Member Author

le0pard commented Dec 11, 2014

Done 😀

#{route_name}: function(#{build_params(required_parts)}) {
return Utils.build_path(#{json(required_parts)}, #{json(optional_parts)}, #{json(serialize(route.path.spec, parent_spec))}, arguments);
}#{",\n" + url_link if url_link.length > 0}
// function(#{required_parts.join(', ')})
Copy link
Collaborator

Choose a reason for hiding this comment

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

options should be part of signature.

@bogdan
Copy link
Collaborator

bogdan commented Dec 11, 2014

This one looks good, but want to merge #137 first.

This one is easier so it will be easier to merge conflicts here than there.

@le0pard
Copy link
Member Author

le0pard commented Dec 11, 2014

@bogdan no problem. I just squashed commits, because it was too much for this pull request :)

Routes.users_path() // => "/users"
'' + Routes.user_path // => "/users/:id(.:format)"
Routes.user_path.toString() // => "/users/:id(.:format)"
Routes.user_path.required_params // => ['id']
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are advanced things. Lets extract them to its own part of readme.

Don't want tricky features to be mixed with core.

@le0pard
Copy link
Member Author

le0pard commented Dec 17, 2014

Done

bogdan added a commit that referenced this pull request Dec 17, 2014
@bogdan bogdan merged commit 5efc050 into railsware:master Dec 17, 2014
@le0pard
Copy link
Member Author

le0pard commented Dec 17, 2014

🎉 🆒 Thanks!

@le0pard
Copy link
Member Author

le0pard commented Dec 17, 2014

BTW, I think we can close in this case #123 and #122

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.

2 participants