所以这就是我正在尝试做的事情.我正在构建一个ember.js应用程序,在GAE上运行
java后端.
我正在使用把手,但我希望它们分成单独的文件,而不是全部粘贴到index.html中.
通过ember.js irc,我和minispade一起打开了rake-pipeline
随着web filters和自定义handlebars filter,我开始构建资产文件.我不知道Ruby,或者gem文件等.
因此,我试图找出能够动态编译我的coffeescript / handlebars文件的最佳方法,minispade它们,但在开发模式下保持各个文件可访问,以便我可以调试它们.令人困难的是,rake管道运行在与GAE不同的端口上.所以我不确定如何处理这个问题.在开发期间,我是否将GAE中的索引文件指向9292端口(rakep)中的单个文件,但是在生产模式下是否指向完全连接的版本?我不确定.
所以我试图在这里做到这一点:https://gist.github.com/1495740只有一个由’build’标志触发的部分.甚至不确定这是否有效.
我知道这里有很多混乱.道歉,就像我说的那样,我甚至不熟悉Ruby的做事方式.
解决方法
Rake :: Pipeline.build是评估Assetfile的方法.您可以想象整个Assetfile都包含在Rake :: Pipeline.build {}块中;你不应该在Assetfile中写一个.
文档中的一些过滤器是假设的,大多数文档都是在有任何过滤器之前编写的.不过最近添加了CoffeeScript编译器.
至于你的主要问题,我不确定用当前的rakep实现做一个干净的方法.但是,Assetfile只是Ruby,所以可以将一些应该起作用的东西放在一起.这是我写你的方式:
- require "json"
- require "rake-pipeline-web-filters"
- require "rake-pipeline-web-filters/helpers"
- class HandlebarsFilter < Rake::Pipeline::Filter
- def initialize(&block)
- block ||= proc { |input| input.sub(/\.handlebars$/,'.js') }
- super(&block)
- end
- def generate_output(inputs,output)
- inputs.each do |input|
- output.write "return Ember.Handlebars.compile(#{input.read.to_json})"
- end
- end
- end
- # process all js,css and html files in app/assets
- input "assets"
- # processed files should be outputted to public
- output "public"
- # process all coffee files
- match "**/*.coffee" do
- # compile all CoffeeScript files. the output file
- # for the compilation should be the input name
- # with the .coffee extension replaced with .js
- coffee_script
- # The coffee_script helper is exactly equivalent to:
- # filter Rake::Pipeline::Web::Filters::CoffeeScriptCompiler
- end
- match "**/*.js" do
- minispade
- if ENV['RAKEP_ENV'] == "production"
- concat "application.js"
- else
- concat
- end
- end
- match "**/*.handlebars" do
- filter HandlebarsFilter
- minispade
- concat "templates.js"
- end
if ENV [‘RAKEP_ENV’]位读取环境变量以决定是否将JS连接到单个文件.
所以现在你可以为连接版本运行RAKEP_ENV =“production”rakep构建,或者只为开发构建运行rakep构建.