设置rake-pipeline与Google App Engine一起使用 [英] Setting up rake-pipeline for use with handlebars alongside Google App Engine

查看:109
本文介绍了设置rake-pipeline与Google App Engine一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这就是我想要做的。我正在构建一个ember.js应用程序,并在GAE上运行java后端。



我使用的是句柄,但我希望它们分成单独的文件,而不是只是全部粘贴到index.html中。



通过ember.js irc我打开了 rake-pipeline 以及 minispade



随着网页过滤器和自定义句柄过滤器我开始构建资产文件。我不知道Ruby或者gem文件等。

所以我试图找出能够编译我的coffeescript / handlebars文件的最佳方法飞,minispade他们,但保持单个文件访问时,在开发模式,所以我可以调试它们。造成这种困难的原因是耙式管道运行在与GAE不同的端口上。所以我不确定如何处理这个问题。在开发过程中,我是否将GAE中的索引文件指向9292端口(rakep)上的单个文件,但在生产模式下是否指向完全级联版本?我不确定。



所以我试图在这里做: https://gist.github.com/1495740 只有一个部分是由'build'标志触发的。甚至不知道这是否有效。



我知道这里有很多混乱。道歉,就像我说过的,我甚至不太熟悉Ruby风格的做事。

Rake :: Pipeline.build 是评估 Assetfile 的方法。你可以想象你的整个 Assetfile 包装在一个 Rake :: Pipeline.build {} 块中;您不需要在 Assetfile 中写入一个。



文档中的某些过滤器是假设的,大多数这些文档都是在有任何过滤器之前编写的。不过,最近新增了一个CoffeeScript编译器。



至于你的主要问题,我不确定是否有一种干净的方法来处理当前的 rakep 执行。然而,一个 Assetfile 只是Ruby,所以有可能一起破解应该工作的东西。以下是我的写法:

  requirejson
需要rake-pipeline-web-filters
需要rake-pipeline-web-filters / helpers

class HandlebarsFilter< Rake :: Pipeline :: Filter
def初始化(&block)
block || = proc {| input | input.sub(/\.handlebars$/,'.js')}
super(&block)
end

def generate_output(输入,输出)
inputs.each do | input |
output.writereturn Ember.Handlebars.compile(#{input.read.to_json})
end
end
end

#process应用程序/资产中的所有js,css和html文件
输入assets

#处理的文件应输出到public
输出public

#处理所有咖啡文件
匹配** / *。coffeedo
#编译所有CoffeeScript文件。用于编译的输出文件
#应该是输入名称
#,并将.coffee扩展名替换为.js
coffee_script

#coffee_script助手完全等效to:
#filter Rake :: Pipeline :: Web :: Filters :: CoffeeScriptCompiler
end

match** / *。jsdo
minispade
如果ENV ['RAKEP_ENV'] ==生产
concatapplication.js
else
concat
end
end

match** / *。handlebarsdo
filter HandlebarsFilter
minispade
concattemplates.js
end

如果ENV ['RAKEP_ENV'] 位读取环境变量以决定是否连接JS添加到单个文件中。

因此,现在您可以针对连接构建运行 RAKEP_ENV =productionrakep build ,或者只是 rakep build 开发版本。


So here's what I'm attempting to do. I'm building an ember.js application, with a java backend running on GAE.

I'm using handlebars, but I want them divided up into separate files, not just all pasted into the index.html.

Via the ember.js irc I was turned on to rake-pipeline along with minispade

Along with the web filters and a custom handlebars filter I started building the assetfile. I don't know Ruby, or gem files, etc.

So I'm trying to figure out the best way to be able to compile my coffeescript/handlebars files on the fly, minispade them, but keep the individual files accessible while in dev mode so I can debug them. What makes that hard is that the rake pipeline is running on a different port than GAE. So I'm not sure exactly how to handle this. Do I make my index file in GAE point to individual files at the 9292 port (rakep) during development, but in production mode point to the fully concatenated version? I'm not sure.

So I was attempting to do that here: https://gist.github.com/1495740 by having only one section that was triggered by the 'build' flag. Not even sure if that works that way.

I know there's a lot of confusion here. Apologies, like I said I'm not even remotely familiar with the Ruby style of doing things.

解决方案

Rake::Pipeline.build is the method that evaluates an Assetfile. You can imagine that your entire Assetfile is wrapped inside a Rake::Pipeline.build {} block; you shouldn't ever need to write one inside an Assetfile.

Some of the filters in the docs are hypothetical, most of those docs were written before there were any filters at all. A CoffeeScript compiler has been recently added, though.

As to your main question, I'm not sure there's a clean way to do it with the current rakep implementation. An Assetfile is just Ruby, though, so it's possible to hack something together that should work. Here's how I would write yours:

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

The if ENV['RAKEP_ENV'] bit reads an environment variable to decide whether to concatenate your JS to a single file.

So now you can run RAKEP_ENV="production" rakep build for a concatenated build, or just rakep build for a development build.

这篇关于设置rake-pipeline与Google App Engine一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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