0

Per this question: Setting up rake-pipeline for use with handlebars alongside Google App Engine

I'm using a MinispadeFilter as my dependency management system via rake-pipeline.

The weird thing I'm seeing is the coffeescript and handlebars files have their minispade identifier set to a tmp directory (I'm assuming, where the work is being done). screencast.com/t/wIXmREcreW

Is there a way to set that to a root path such that it is normalized? Likewise my js files, while not pointing to a tmp path, are pointing to the original assets path instead of the public path. I know its just an identifier, but should I expect them to reference the public path? screencast.com/t/k9kZNcPo

Community
  • 1
  • 1
Bob Spryn
  • 17,742
  • 12
  • 68
  • 91

1 Answers1

3

The MinispadeFilter is pretty dumb about generating module identifiers by default. It just names them after the path of the input files. You're seeing the tmp dirs in there from handlebars and coffeescript because the minispade filter is getting the module id from the place where the pipeline turns them into javascript. The filter takes a :module_id_generator option which allows you to customize the generation of module ids. If you're not familiar with Ruby, this may be a little heavy for you, so bear with me. The module_id_generator option takes a Ruby proc, which is like an anonymous function in JS. The filter then takes this proc that you pass in and executes it for each input file, passing your proc a FileWrapper object representing the input file, and your proc should return a string that will be used as the module id for that file.

Here's a match block from one of my projects:

match "**/*.js" do
  minispade :module_id_generator => proc { |input| input.path.sub(/lib\//, 'timelog/').sub(/\.js$/, '') }
  concat "js/app.js"
end

The :module_id_generator is a proc which takes a FileWrapper named input and turns it into the module id I want. The input file's path is available as the path method on input. In this case, my JS files are in a lib/ directory, so I use Ruby's sub method to replace the beginning lib/ part of the path with timelog (the name of the project) then again to remove the .js extension. So a js file named lib/models.js would get a module id of timelog/models.

dudleyf
  • 353
  • 2
  • 6