sprockets duplicate file naming - ruby-on-rails

I have the following files, in my asset path:
javascripts/abc.js
templates/abc.js.mustache # this gets compiled to abc.js
naturally, they both would be requested as assets/abc.js.
Is there a fix? If not, what part of the Sprockets source would need to be modified?
My thinking is along the lines that if the engine can remove the extension, it can well enough add a suffix.

It may be too obvious, but isn't it better just rename files? I understand nature of your question, but it's hard to imagine ultimate requirements, which forces same filenames for those files. Hence this, you have foobar.js and foobar.js.mustache, which compiles to foobar.js. Why they have same names? They do same things? This is design flaw, if you ask me.

I have the same problem, and have not yet found a satisfying solution. My sites have many complex full-stack plugins (aka engines), and they have lots of css, js, and image files. Having to namespace, eg "styles.css" in each plugin kinda sucks. When upgrading to Rails 3, I assumed the file resolver would put engines/plugins in /styles, but no, they all get combined into one virtual path.
My current temporary solution is to build a rake task that I run that checks for duplicate filenames. I run it before committing code and on deployment. Hackity! If that helps, great, if not, perhaps someone out there has a more elegant solution...

Related

How can I change the default path to the `rails` script in my project, or remove that dependency?

In another question (Why does the Rails command force a help message for the new command?), I found that Rails needs the rails script to be in the script folder, in the root of my project, in order for it to be properly detected as an existing Rails projects, and allow me to use the various rails commands other then new.
I did this because I felt that the more popular moniker for including executable content in a repository to highlight available use cases is by using the name scripts. At least the pluralism in English should be appreciated!
Is there anyway to change which folder the main Rails executable looks for the project-included one?
I actually think it's a bit silly to include this rails executable in the project, and can be redundant. Maybe it's for customization, but I feel that could better be done in the configuration, environment, other .rb files. So also, could this just be removed somehow, and still have a functioning project through varied use of the main rails command.

Importing Node Modules in to Rails

I'm working with Jasmine. I spotted this handy looking library: https://github.com/JamieMason/Jasmine-Matchers and I thought its collection of customer matchers would help me a lot.
Problem is, it's loaded with files common to Node applications, such as JSHint, Grunt, travis.yml etc
The project I'm working on, that would love these matchers, is a Rails application. I've tried dropping them into my assets/javascripts and requiring in application.js, but obviously, life isn't that simple.
What is the correct way to install these files, and integrate them with Jasmine in a Rails context? Is Bower the tool for the job? If so, what's the right procedure to adding JS dependencies/integrating them off the bat?
Author of Jasmine-Matchers here, the only file you need to load into your test environment is this one https://github.com/JamieMason/Jasmine-Matchers/blob/master/dist/jasmine-matchers.js.
The other files are part of the development repo, I'll open an issue to have those excluded from npm/bower packages to save confusion.
You should be able to copy that file to your assets/javascripts directory, then embed it after Jasmine but before your tests.
Please comment if I've missed anything out here.
I was also trying to use Node modules inside my Rails application and the easiest way I found to achieve it was through browserify-rails gem.
The installation is pretty straightforward, just follow the getting started section and everything should be working. :-)

Pub serve all files

In terms of js/css/img type assets, is there a way to serve everything you have in "web" and "lib" regardless of whether or not you used it in your HTML?
Also, maybe put that small bit in bold in the documentation...It took me FOREVER to figure out pub serve only included files that were actually used in the HTML.
I tried the --all flag, but that didn't seem to work.
You may ask why? Because isn't it so awesome that Dart is so smart in that it only includes what you use? Well yea if it actually worked and was so simple that'd be great...But the problem is it while it parses the HTML and that's all well and good...Other JS files could themselves depend on assets. Pub serve doesn't go that deep. Plus, AJAX loading, etc. I just want all my assets. I put them there for a reason. I really dislike how Dart assumes certain things.
I suspect it has something to do with transformers and perhaps I could have my own...and I'm looking into that now, but is there something I'm missing?
Thanks!

Overriding backend assets in production environment

I am working on a project that needs to alter Refinery's WYMEditor behavior a bit. This is easily done by overriding jquery.refinery.wymeditor.js using rake refinery:override and editing it to my own needs, which works fine in development environment.
However, when it comes to production, overrides are ignored. That is, the compiled asset just contains jquery.refinery.wymeditor.js from bundle, and editing that file directly there may give the desired effect, but that's just not the way it should be done.
Strange thing is, that the problem apparently manifests itself only when trying to override backend-related assets.
It might be useful to know that I am using refinery-edge.
Any help appreciated.
So I have managed to beat it. First thing to mention is that it wouldn't be possible without poking into Refinery source code.
As I have already written in the comment, the problem was that I was trying to override an asset (wymeditor/jquery.refinery.wymeditor.js in my case) that wasn't included in a view directly, but was referenced in another asset, which was taken from the gem. And since sprockets knows nothing about Refinery's overrides, it took the referenced assets by the relative path, i.e. from the gem (and hence, unmodified), too. So, again, in my case the solution was to override the refinery/wymeditor.js, and everything worked as a charm.
Should you need to change any other backend script than WYMEditor, you will most likely have to override the refinery/refinery.js, which includes all other backend scripts, in addition to the very script you need to modify.
There is one big concern, though. With all these overrides, I have made any updates very error-prone, since some files will update, and some will not. It could have been avoided by overriding everything, but that effectively means no updates at all.
Try changing the name of the generated file and including that in your manifest instead of the original name. I suspect that it is preferring the original in the presence of two assets named the same thing.

rails + attachment_fu: issue with files in directories

I use attachment_fu for my rails app. It's great for me.
However, the designer who works with me complains about it because it saves files in different directory. She said that she can't handle those files efficiently with Photoshop as they are scattered.
I tried to persuade her with the following reasons.
We can avoid file name clash
It's faster than when they are in the same directory
But I couldn't convince her. How would you? Or are you with her? If so, why?
Sam
I think Adobe Photoshop has a built-in utility called 'Bridge' which allows easy asset management, might be worth having a look.

Resources