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

Modifying the path #55

Closed
willsoto opened this issue Nov 28, 2014 · 8 comments
Closed

Modifying the path #55

willsoto opened this issue Nov 28, 2014 · 8 comments

Comments

@willsoto
Copy link

Currently, any path that contains .. or . will be rewritten to omit those because path.join() and path.normalize() do this.

This is inconvenient when using RequireJS's require.toUrl() as it will prepend ./ to the generated URLs (since require has to know where the file is). These are effectively the keys that are then used to look up the appropriate template by angular, hence the need to keep this path the way it is.

Do you have any suggestions for how to handle this? I have attempted using both the base and root options, but both of these get normalized.

If I were to submit a PR for this, I would probably add a hook to modify the url one last time before it is actually added to the template file, thereby avoiding the whole normalization problem. But I am not sure whether or not this is the path you'd like to take.

@miickel
Copy link
Owner

miickel commented Dec 13, 2014

Not sure I understand your problem fully. Perhaps you can provide a small example of what you are trying to achieve?

Can't see how this plugin would work differently if you were to use React together with Angular. You can't use relative root urls starting with /? E.g. /some/fancy/template.html

@willsoto
Copy link
Author

So, in Require (not React), there is a function toUrl() which will automatically generate the path to a given file.

When given a string like require.toUrl('./foo/bar/_baz.html'), require will begin looking for _baz.html starting from the current directory.

This means that the url generated - and the url angular uses in the template cache - begins with ./

The problem I was having with this task is that . and .. are stripped out of the url, meaning angular will never find the template in the cache since it begins with a .

All I need is a hook to prepend something to the url after it has been normalized. My PR adds urlPrefix. I have been using this locally for the last week and it has worked fine.

Does this clarify the issue a bit?

@miickel
Copy link
Owner

miickel commented Dec 13, 2014

Thanks for the explanation! This sounds like an edge case to me, so we'll close for now but re-open if more users are requesting something similar. thx

@miickel miickel closed this as completed Dec 13, 2014
@TomNeyland
Copy link

This sounds like an edge case to me

@miickel Quite the opposite actually.

@Paradox41 is describing a requirejs + angular best-practice. Using require.toUrl gives you all of the benefits of module relative pathing (critical for larger, multi-person projects) while avoiding the headaches involved in using absolute paths.

Refactoring a large project that uses absolute path references for partials is a very special type of hell.

I'd be interested in seeing this reopened, or really any solution that allows continued usage of require.toUrl.

@TomNeyland
Copy link

Also, fwiw, the grunt cousin to this library plays nicely with require.toUrl generated paths.

@SebastianSchirmer
Copy link

I am having the same issue as paradox41.

However not using requirejs but the new angular router.
Need the ./ in the beginning but the join() method removes them.

Therefore requesting reopening this issue.

@willsoto
Copy link
Author

willsoto commented May 5, 2015

I have a fork available with my fix that I have been using successfully for
quite some time. Feel free to check it out.

Sent from my Moto X
On May 5, 2015 12:48 PM, "Sebastian Schirmer" notifications@github.com
wrote:

I am having the same issue as paradox41.

However not using requirejs but the new angular router.
Need the ./ in the beginning but the join() method removes them.

Therefore requesting reopening this issue.


Reply to this email directly or view it on GitHub
#55 (comment)
.

@SebastianSchirmer
Copy link

@Paradox41 Thank you, checked it out and this will work!

@miickel This should be added to this repo as well. By the way, thanks for this great module :-)

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

No branches or pull requests

4 participants