简体   繁体   English

在Sinatra上将opalrb与链轮集成在一起

[英]Integrate opalrb with sprockets on sinatra

I'm wanting to integrate Opal into my next project and decided to just move onto sprockets from sinatra-asset-pack, however I can't find anything on how to integrate opal into sprockets rather than just setting up sprockets and opal separately. 我想将Opal集成到我的下一个项目中,并决定只从sinatra-asset-pack转到链轮上,但是除了如何分别设置链轮和opal之外,我找不到如何将opal集成到链轮中的任何方法。

How do I set up sprockets and integrate Opal.rb with it? 如何设置链轮并将Opal.rb与之集成?

Bearing in mind I don't run it as a rackup file, this is due to our environment so it's just not viable, instead I bundle my app as a gem and run it via executable. 请记住,我不是将其作为机架文件运行,这是由于我们的环境所致,因此它不可行,而是将我的应用程序捆绑为gem并通过可执行文件运行。

Or perhaps just point me in the right-direction to do this if some resource on this already exists and I just wasn't able to find it, that would be fab as well. 或者,如果已经存在一些相关资源,而我却找不到它,那也许就是正确的方向。

I asked on the opal github page and they pointed me to a place in their own code where they do what I'm asking, I'll post a link and once I do it myself I'll post the code I've created. 我在蛋白石github页面上询问,他们将我指向他们自己的代码中的某个地方,他们可以按照我的要求进行操作,我将发布一个链接,一旦我自己做,便会发布我创建的代码。

Here's the link to the code on github , the highlighted section is the bit you want to read, be aware that it's rails specific, which to be honest is kind of throwing me. 这是github上代码的链接,突出显示的部分是您要阅读的部分,请注意,它是特定于rails的,说实话有点让我失望。

EDIT: 编辑:

Ok, so I've been able to make some progress and now I have sprockets running with opalrb, sort of. 好的,所以我已经取得了一些进步,现在我的链轮正在用opalrb运行。 The browser responds with 200 so it's found the file, the mime type is also correct... the problem is that the file it gets is blank, nothing has been rendered. 浏览器以200响应,因此找到了文件,mime类型也正确...问题是它获取的文件为空白,没有任何内容。 For any one interested in my progress, here's a gist with how far I've gotten. 对于任何对我的进步感兴趣的人,这里有我要走多远的要旨

EDIT: 编辑:

Ok, so I now have sprockets providing assets and opal rendering out java script files from ruby source code. 好的,现在我有了链轮,提供资产和蛋白石,从ruby源代码中渲染出Java脚本文件。 However none of the code I'm putting into the pre-compiled ruby file is actually doing anything le sigh . 但是,我放入预编译的ruby文件中的代码实际上并没有做任何令人遗憾的事情。

Still, Here's a link to the repo containing the code so far. 不过,这是到目前为止包含代码的仓库的链接

EDIT: 编辑:

Turns out, to get the the opal stuff to run you need to run a command to bootstrap the opal code; 事实证明,要运行蛋白石的东西,您需要运行命令来引导蛋白石代码; I Created a helper to do this for me: 我创建了一个帮手来为我做这件事:

def opal_boot_code_for(file)
    "<script>#{Opal::Processor.load_asset_code(settings.sprockets, file)}</script>"
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM