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

Allow partial expansion of templates #30

Closed
plexus opened this issue Jun 26, 2014 · 6 comments
Closed

Allow partial expansion of templates #30

plexus opened this issue Jun 26, 2014 · 6 comments

Comments

@plexus
Copy link

plexus commented Jun 26, 2014

This would make it possible to do this

tpl = Mustermann.new("/comments/{id}{?page}", type: template)
tpl.expand_partial(id: 7) # => "/comments/7{?page}"

Not sure how hard it would be. Eventually I'd like to switch Yaks over from uri-template to Mustermann, but I'll need this feature.

For reference

https://twitter.com/plexus/status/482057311775891456

@rkh
Copy link
Member

rkh commented Aug 18, 2014

I'd love this feature, btw. It would require a more complex (thus potentially slower) data structure, since you'd actually have to generate a new Pattern object from the Expander.

I think building a separate PartialExpander along side Expander would allow people to opt into the added computational and/or memory cost (I think it would be very easy to sacrifice memory for performance).

@rkh rkh added this to the 1.0.0 milestone Aug 18, 2014
@plexus
Copy link
Author

plexus commented Oct 22, 2014

Care to pair on this? Friday maybe, or next week?

@rkh
Copy link
Member

rkh commented Oct 22, 2014

I'd like to. I'm pretty busy right now until I get back from Israel November 8, unfortunately.

@plexus
Copy link
Author

plexus commented Oct 23, 2014

ok, no rush. I'll ping you in a couple weeks then :)

@rkh
Copy link
Member

rkh commented Dec 13, 2014

Which features do you expect?

Things that could be possible but will influence the API, internals and performance:

  1. Generating URI template strings.
  2. Generating objects that support further expanding.
  3. Generating full pattern objects (ie, that support matching).
  4. Generating string representations in the actual pattern type (ie, expand /:a/:b to /foo/:b).

Of these, 2 would probably be easiest to implement (since it's just a proxy) and can be combined with any of the other, 1 is likely what you want. 3 should be feasible, 4 might be too much work for a feature people will rarely if ever use.

The most complex pattern type to implement this for would be URI templates itself (at least if level 4 expansion is the goal), it would share quite some logic with the full expansion, which also has some broken edge cases right now (see #4 and #5).

I could also imagine a partial expander to use the same logic as the full expander, but this might come at high memory cost (though I'm not 100% sure that's true, since for patterns with a reasonable number of variables, keeping the AST around would probably use more memory - the expander currently only needs the AST when generating expansion rules).

@plexus
Copy link
Author

plexus commented Dec 17, 2014

Links in Yaks have the option to only expand none, all, or some of the placeholders

link :self, '/api/posts/{id}'
link "/rel/comment", '/api/posts/{id}/comments/{comment_id}', expand: [:id]
link "/rel/search", '/api/search{?q}', expand: false

Which would render as (using HAL as an example)

"_links": {
  "self": {"href": "/api/posts/7"},
  "/rel/comment": {"href": "/api/posts/7/comments/{comment_id}", "template": true},
  "/rel/search": {"href": "/api/serach{?q}", "template": true},
}

So I guess that's 4?

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

No branches or pull requests

2 participants