有没有一种方法可以显示Opal生成的javascript中的Ruby行号 [英] Is there a way to show the Ruby line numbers in javascript generated by Opal

查看:80
本文介绍了有没有一种方法可以显示Opal生成的javascript中的Ruby行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于调试目的,我希望在Opal生成的javascript文件中看到相应的Ruby Source位置.

For debugging purposes I would like to see the corresponding Ruby Source position in the javascript file generated by Opal.

有没有一种简单的方法可以实现这一目标?我尝试过

Is there a simple way to achive this? I tried

# config.ru
require 'bundler'
Bundler.require

run Opal::Server.new { |s|

  s.append_path 'public'
  s.append_path 'src'
  s.debug = true
  s.source_map = true

  s.main = 'application'

  s.index_path = 'index_opal.html'
}

这是我的申请文件

需要数学" 需要蛋白石" 需要'opal-jquery'

require 'math' require 'opal' require 'opal-jquery'

require 'consolelogger'
require 'harpnotes'
require 'abc_to_harpnotes'
require 'opal-raphael'
require 'opal-jspdf'
require 'opal-jszip'
require 'opal-abcjs'
require 'opal-musicaljs'
require 'raphael_engine'
require 'pdf_engine'
require 'controller'
require 'harpnote_player'
require 'text_pane'

puts "now starting zupfnoter"
puts "zupfnoter

我只能在源映射中看到此文件,但不能在"require"中看到该文件.

I can only see this file in the source maps, but not the ones included by 'require'

我什至可以在结尾处为卖权声明设置断点,但除此之外没有其他地方.

I can even set breakpints to the puts statments at the end but nowhere else.

推荐答案

下面是一个示例,说明如何设置可正确提供源地图的机架

Here's an example on how to setup a rack up that serves source maps correctly

https://github.com/opal/opal/tree/0-6-stable/examples/rack (Opal v0.6.x)

https://github.com/opal/opal/tree/0-6-stable/examples/rack (Opal v0.6.x)

更新:问题似乎在于您未处于调试模式.

UPDATE: The problem seems to be that you're not in debug mode.

说明::当前的源地图实现不适用于级联资产,并且Sprockets本身不支持源地图,因此在级联期间不会保留它们.

Explanation: Current sourcemaps implementation doesn't work with concatenated assets and Sprockets doesn't support sourcemaps natively so it doesn't preserve them during concatenation.

要启用调试模式,您需要添加debug = true并在Opal :: Server中使用Erb index.html:

To enable debug mode you need to add debug = true and use an Erb index.html in Opal::Server:

# config.ru

run Opal::Server.new do |s|
  s.append_path 'src'
  s.source_map = true
  s.main = 'application'
  s.index_path = 'index.html.erb'
  s.debug = true
end

然后在您的index.html.erb中,您需要使用助手而不是硬编码的脚本标记:

then in your index.html.erb you need to use the helper instead of a hardcoded script tag:

<%# index.html.erb %>
…
<%= javascript_include_tag 'application' %>
…

这篇关于有没有一种方法可以显示Opal生成的javascript中的Ruby行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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