Bob*_*ryn 8 ruby handlebars.js
所以这就是我想要做的.我正在构建一个ember.js应用程序,在GAE上运行java后端.
我正在使用把手,但我希望它们分成单独的文件,而不是全部粘贴到index.html中.
通过ember.js irc,我和minispade一起打开了rake-pipeline
随着Web过滤器和自定义手柄过滤器,我开始构建资产文件.我不知道Ruby,或者gem文件等.
因此,我正在尝试找出能够动态编译我的coffeescript/handlebars文件的最佳方法,minispade,但在开发模式下保持单个文件可访问,以便我可以调试它们.令人困难的是,rake管道运行在与GAE不同的端口上.所以我不确定如何处理这个问题.在开发期间,我是否将GAE中的索引文件指向9292端口(rakep)中的单个文件,但在生产模式下是否指向完全连接的版本?我不确定.
所以我试图在这里做到这一点:https://gist.github.com/1495740 只有一个由'build'标志触发的部分.甚至不确定这是否有效.
我知道这里有很多混乱.道歉,就像我说的那样,我甚至不熟悉Ruby的做事方式.
Yeh*_*atz 16
由于您不是Ruby人员,因此以下是使用rake管道设置库存OSX环境的最可靠步骤:
# on OSX, using built-in Ruby
$ sudo gem install bundler --pre
Run Code Online (Sandbox Code Playgroud)
# inside your app directory
$ bundle init
# will create a file named Gemfile in the root
Run Code Online (Sandbox Code Playgroud)
# inside the Gemfile
gem "rake-pipeline-web-filters"
Run Code Online (Sandbox Code Playgroud)
$ bundle install --binstubs
Run Code Online (Sandbox Code Playgroud)
不过你已经在做了......
# to run the preview server
$ bin/rakep
# to build your assets
$ bin/rakep build
Run Code Online (Sandbox Code Playgroud)
小智 9
Rake::Pipeline.build是评估一个的方法Assetfile.你可以想象你的整个Assetfile被包裹在一个Rake::Pipeline.build {}街区内; 你不应该在里面写一个Assetfile.
文档中的一些过滤器是假设的,大多数文档都是在有任何过滤器之前编写的.不过,最近添加了CoffeeScript编译器.
至于你的主要问题,我不确定当前的rakep实现是否有一个干净的方法.一个Assetfile就是红宝石,虽然如此,有可能破解的东西在一起,应该工作.这是我写你的方式:
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
Run Code Online (Sandbox Code Playgroud)
该if ENV['RAKEP_ENV']位读取环境变量以决定是否将JS连接到单个文件.
所以现在你可以运行RAKEP_ENV="production" rakep build连接的构建,或仅rakep build用于开发构建.
| 归档时间: |
|
| 查看次数: |
3960 次 |
| 最近记录: |