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

Directives don't work in files that need pre-processing #28

Open
eric1234 opened this issue Mar 5, 2014 · 2 comments
Open

Directives don't work in files that need pre-processing #28

eric1234 opened this issue Mar 5, 2014 · 2 comments

Comments

@eric1234
Copy link
Collaborator

eric1234 commented Mar 5, 2014

If a file requires pre-processing (example CoffeeScript) I can't put processing directives in the file. This occurs because the file is first run through the filters, then checks for processing directives. But the filters usually remove comments and therefore remove processing directives.

I don't currently have a pull request as I need to focus on my project and I have a workaround. But I wanted to note the problem in case someone else wanted to tackle it.

I believe the solution is to extract the processing directives to come up with a list of files to run filters on. The file containing the processing directive is simply added to that list at the end. Then we process the list of files through the filters and concatenate the result together.

This might be an ideal time to add support for the "require_self" directive. Rather than sticking the the file that contains the processing directives at the end of the list we stick it in whatever position the "require_self" directive is located.

Currently I am working around this by having any files that contain processing directives be pure JS (so the comments aren't stripped). If I want to have some extra CoffeeScript on that file I just create a new file and include that. It works but creates more files than are necessary using the Rails asset pipeline.

@vendethiel
Copy link
Owner

This is a known problem and is something I wondered how to tackle because, simply because Coffee etc doesn't have the right syntax for that. Sprockets hacks around it by allowing #= too (IIRC), which I'm not okay with.

We have several possibilities :

  • Don't add them.
    This is what we currently have, and I'd really want to stick with it, considering how many times I've seen people ask "why am I getting duplicated deps?" when they require jQuery twice.
    This is not commonjs/AMD (though you can very well use Sprockets with that), and should not be taken as such. I'm fine with application.js, usually.
  • Add regexps for each preprocessors so that they return array("processed code", array("directives"))
    This is probably the worst we can do (mostly code-wise)
  • Allow /* *= */ and //= style comments everywhere
    This has the the downside of looking terribly bad in preprocessors. Let's imagine we get support for a lisp dialect, I'd feel bad writing
/**
 *= require wisp/core
 */

(.log console "hai")

Thoughts ?

@vendethiel
Copy link
Owner

Also, seems like Rails only uses require_self to move the file content before the end of the file.

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

2 participants