如何自定义rake-pipeline中MinispadeFilter使用的标识符 [英] How do you customize the identifier used by MinispadeFilter in rake-pipeline

查看:52
本文介绍了如何自定义rake-pipeline中MinispadeFilter使用的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据这个问题:设置 rake-pipeline 以与 Google App Engine 一起使用把手

我通过 rake-pipeline 使用 MinispadeFilter 作为我的依赖管理系统.

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

我看到的奇怪的事情是 coffeescript 和 handlebars 文件将它们的 minispade 标识符设置为 tmp 目录(我假设工作正在完成的地方).screencast.com/t/wIXmREcreW

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

有没有办法将其设置为根路径以使其标准化?同样,我的 js 文件虽然不指向 tmp 路径,但指向原始资产路径而不是公共路径.我知道它只是一个标识符,但我应该期望他们引用公共路径吗?screencast.com/t/k9kZNcPo

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

推荐答案

MinispadeFilter 在默认情况下生成模块标识符非常愚蠢.它只是在输入文件的路径之后命名它们.您正在从把手和咖啡脚本中看到 tmp 目录,因为 minispade 过滤器正在从管道将它们转换为 javascript 的位置获取模块 ID.过滤器采用 :module_id_generator 选项,允许您自定义模块 id 的生成.如果你不熟悉 Ruby,这对你来说可能有点沉重,所以请耐心等待.module_id_generator 选项采用 Ruby proc,就像 JS 中的匿名函数.然后过滤器接受你传入的这个 proc 并为每个输入文件执行它,向你的 proc 传递一个表示输入文件的 FileWrapper 对象,并且你的 proc 应该返回一个将用作模块的字符串该文件的 ID.

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

:module_id_generator 是一个过程,它接受一个名为 inputFileWrapper 并将其转换为我想要的模块 ID.输入文件的路径可用作 input 上的 path 方法.在本例中,我的 JS 文件位于 lib/ 目录中,因此我使用 Ruby 的 sub 方法替换了开头的 lib/ 部分带有 timelog(项目名称)的路径,然后再次删除 .js 扩展名.因此,名为 lib/models.js 的 js 文件将获得 timelog/models 的模块 ID.

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.

这篇关于如何自定义rake-pipeline中MinispadeFilter使用的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆