使用此HAML部分
!!!
%html
%head
%title=document_title
= favicon_link_tag 'logo16.png'
%meta{content: form_authenticity_token, name: "csrf-token"}= ''
...
我收到错误
SyntaxError: [stdin]:68:1: unexpected indentation
所以我玩了一些错误的身份;然后我得到其他但正确的错误
Inconsistent indentation: "\t\t " used for indentation, but the rest of the document was indented using 1 tab.
Inconsistent indentation: "\t " used for indentation, but the rest of the document was indented using 1 tab.
Illegal nesting: content can't be both given on the same line as %title and nested within it.
和堆栈跟踪看起来像
app/views/layouts/page_print.html.haml:5
haml (4.0.7) lib/haml/parser.rb:174:in `block in tabs'
但是unexpected Indentation
我得到了一个有趣的堆栈 - 那里的coffee_script是什么?:
compile (C:\Users\halfbit\AppData\Local\Temp\execjs20161121-7752-txwa8bjs:6692:19)
eval (<anonymous>:1:10)
C:\Users\halfbit\AppData\Local\Temp\execjs20161121-7752-txwa8bjs:6703:8
C:\Users\halfbit\AppData\Local\Temp\execjs20161121-7752-txwa8bjs:6709:14
require./helpers.exports (C:\Users\halfbit\AppData\Local\Temp\execjs20161121-7752-txwa8bjs:1:102)
Object.<anonymous> (C:\Users\halfbit\AppData\Local\Temp\execjs20161121-7752-txwa8bjs:1:120)
Module._compile (module.js:409:26)
Object.Module._extensions..js (module.js:416:10)
Module.load (module.js:343:32)
Function.Module._load (module.js:300:12)
Function.Module.runMain (module.js:441:10)
startup (node.js:139:18)
node.js:968:3
execjs (2.7.0) lib/execjs/external_runtime.rb:39:in `exec'
execjs (2.7.0) lib/execjs/external_runtime.rb:21:in `eval'
execjs (2.7.0) lib/execjs/external_runtime.rb:46:in `call'
coffee-script (2.4.1) lib/coffee_script.rb:78:in `compile'
sprockets (3.7.0) lib/sprockets/coffee_script_processor.rb:21:in `block in call'
sprockets (3.7.0) lib/sprockets/cache.rb:85:in `fetch'
sprockets (3.7.0) lib/sprockets/coffee_script_processor.rb:20:in `call'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.7.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.7.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.7.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
sprockets (3.7.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.7.0) lib/sprockets/bundle.rb:23:in `block in call'
sprockets (3.7.0) lib/sprockets/utils.rb:196:in `dfs'
sprockets (3.7.0) lib/sprockets/bundle.rb:24:in `call'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `reverse_each'
sprockets (3.7.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
sprockets (3.7.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
sprockets (3.7.0) lib/sprockets/loader.rb:60:in `block in load'
sprockets (3.7.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
sprockets (3.7.0) lib/sprockets/loader.rb:44:in `load'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
sprockets (3.7.0) lib/sprockets/cached_environment.rb:47:in `load'
sprockets (3.7.0) lib/sprockets/base.rb:66:in `find_asset'
sprockets (3.7.0) lib/sprockets/base.rb:73:in `find_all_linked_assets'
sprockets (3.7.0) lib/sprockets/manifest.rb:142:in `block in find'
sprockets (3.7.0) lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
sprockets (3.7.0) lib/sprockets/path_utils.rb:228:in `block in stat_tree'
sprockets (3.7.0) lib/sprockets/path_utils.rb:212:in `block in stat_directory'
sprockets (3.7.0) lib/sprockets/path_utils.rb:209:in `each'
sprockets (3.7.0) lib/sprockets/path_utils.rb:209:in `stat_directory'
sprockets (3.7.0) lib/sprockets/path_utils.rb:227:in `stat_tree'
sprockets (3.7.0) lib/sprockets/legacy.rb:105:in `each'
sprockets (3.7.0) lib/sprockets/legacy.rb:105:in `block in logical_paths'
sprockets (3.7.0) lib/sprockets/legacy.rb:104:in `each'
sprockets (3.7.0) lib/sprockets/legacy.rb:104:in `logical_paths'
sprockets (3.7.0) lib/sprockets/manifest.rb:140:in `find'
sprockets-rails (3.2.0) lib/sprockets/railtie.rb:50:in `each'
sprockets-rails (3.2.0) lib/sprockets/railtie.rb:50:in `map'
sprockets-rails (3.2.0) lib/sprockets/railtie.rb:50:in `precompiled_assets'
sprockets-rails (3.2.0) lib/sprockets/railtie.rb:35:in `asset_precompiled?'
sprockets-rails (3.2.0) lib/sprockets/railtie.rb:251:in `block (3 levels) in <class:Railtie>'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:359:in `precompiled?'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:363:in `raise_unless_precompiled_asset'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:337:in `digest_path'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:325:in `asset_path'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:102:in `block in resolve_asset_path'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:242:in `block in resolve_asset'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:241:in `each'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:241:in `detect'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:241:in `resolve_asset'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:101:in `resolve_asset_path'
sprockets-rails (3.2.0) lib/sprockets/rails/helper.rb:79:in `compute_asset_path'
actionview (5.0.0.1) lib/action_view/helpers/asset_url_helper.rb:144:in `asset_path'
actionview (5.0.0.1) lib/action_view/helpers/asset_url_helper.rb:311:in `image_path'
actionview (5.0.0.1) lib/action_view/helpers/asset_tag_helper.rb:176:in `favicon_link_tag'
app/views/layouts/page_print.html.haml:5:in `_app_views_layouts_page_print_html_haml___1809589845_126062940'
评论
#= favicon_link_tag 'logo16.png'
没有错误
任何想法?
答案 0 :(得分:1)
我做到了,我再次调试了Rails - 我讨厌这样做。
解决方案的“解决方案”或更好:
1.) Sprockets behaves completely different in Rails 5.0 that in Rails 3.2
2.) Sprockets reads and caches the whole assets path with first touch (favicon in this case)
3.) As far as I can see Sprockets tries to (coffee-) compile manifest.js (?)
4.) Any compile error is catched (rescued) to late (I would say in HAML in this case)
5.) Its therefor extremely misleading to get a - coffeescript indentation error pointing to .HAML or .RB file
我做了什么?
在Sprockes::path_utlis
我更改/添加了开始/救援:
# Public: Stat all the files under a directory.
#
# dir - A String directory
#
# Returns an Enumerator of [path, stat].
def stat_directory(dir)
return to_enum(__method__, dir) unless block_given?
self.entries(dir).each do |entry|
path = File.join(dir, entry)
# puts path.to_s
begin
if stat = self.stat(path)
yield path, stat
end
rescue => e
puts "error #{e} in: "+path
end
end
我得到的输出:
error SyntaxError: [stdin]:68:1: unexpected indentation in: C:/rbstart/app/assets/javascripts/application.js
error Undefined variable: "$std_width". in: C:/rbstart/app/assets/stylesheets/application.css
由于缓存,错误并不总是重现。