- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我在从默认 layout.erb
文件切换到 Middleman 中等效的 layout.haml
文件时遇到了问题。我想将 HAML 用于我的布局,因为我正在尝试熟悉它,所以我决定用 HAML 版本替换默认布局。不幸的是,当我将 layout.erb
替换为 layout.haml
时,出现此错误:
NoMethodError at /
undefined method `force_encoding' for nil:NilClass
Ruby /Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in ensure in binary, line 289
Web GET localhost/
Traceback (innermost first)
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in ensure in binary
string.force_encoding(original_encoding)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in binary
string.force_encoding(original_encoding)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in extract_magic_comment
binary script do...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in extract_encoding
extract_magic_comment(script) || script.encoding...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in precompiled
template_encoding = extract_encoding(template)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/erb.rb: in precompiled
source, offset = super...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/erb.rb: in precompiled
source, offset = super...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in compile_template_method
source, offset = precompiled(locals)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in compiled_method
compile_template_method(locals_keys)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in evaluate
method = compiled_method(locals.keys)...
/Library/Ruby/Gems/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb: in render
evaluate scope, locals || {}, &block...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/rendering.rb: in render_individual_file
content = template.render(context, locs, &block)...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/rendering.rb: in render_template
content = render_individual_file(layout_path, locs, opts, context) { content }...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/sitemap/resource.rb: in block in render
app.render_template(source_file, locs, opts, blocks)...
/Library/Ruby/Gems/2.0.0/gems/activesupport-4.1.4/lib/active_support/notifications.rb: in instrument
yield payload if block_given?...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/util.rb: in instrument
::ActiveSupport::Notifications.instrument(suffixed_name, payload, &block)...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/application.rb: in instrument
delegate :instrument, to: ::Middleman::Util...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/sitemap/resource.rb: in instrument
delegate :logger, :instrument, to: :app...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/sitemap/resource.rb: in render
instrument 'render.resource', path: relative_source, destination_path: destination_path do...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/request.rb: in process_request
output = resource.render do...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/request.rb: in block in call!
process_request(env, req, res)...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/request.rb: in catch
catch(:halt) do...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/request.rb: in call!
catch(:halt) do...
/Library/Ruby/Gems/2.0.0/gems/middleman-core-3.3.3/lib/middleman-core/core_extensions/request.rb: in call
dup.call!(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb: in call
to_app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in block in call
return app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in each
@mapping.each do |host, location, match, app|...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/urlmap.rb: in call
@mapping.each do |host, location, match, app|...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/showexceptions.rb: in call
@app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/head.rb: in call
status, headers, body = @app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb: in _call
status, headers, @body = @app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/lint.rb: in call
dup._call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb: in call
to_app.call(env)...
/Library/Ruby/Gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb: in service
status, headers, body = @app.call(env)...
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb: in service
si.service(req, res)...
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/httpserver.rb: in run
server.service(req, res)...
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/webrick/server.rb: in block in start_thread
block ? block.call(sock) : run(sock)
layout.erb
看起来像这样:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine or request Chrome Frame -->
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<!-- Use title if it's in the page YAML frontmatter -->
<title><%= current_page.data.title || "The Middleman" %></title>
<%= stylesheet_link_tag "normalize" %>
<!-- <%= stylesheet_link_tag "normalize", "all" %> -->
<%= javascript_include_tag "all" %>
</head>
<body class="<%= page_classes %>">
<%= partial "header" %>
<%= yield %>
<%= partial "footer" %>
</body>
</html>
layout.haml
与 layout.erb
的内容并不完全相同,但这似乎无关紧要,因为它无论如何都会中断:
!!!
%html
%head
%title
= current_page.data.title || "The Middleman"
= stylesheet_link_tag "normalize", "all"
= javascript_include_tag "all"
%body
= partial "header"
= yield
= partial "footer"
一开始我以为错误只是因为 HAML 本身被破坏了,但即使是一个非常简单的 HAML 文件,只定义了 doctype、html、head、title 和 body 标签也会破坏。然后我怀疑只有 ERb 文件被用作布局文件——我通过将 layout.haml
重命名为 layout.erb
来确认这一点,这并没有导致错误,只是而是显示原始 HAML 代码。即使保留 layout.erb
并制作子布局 article_layout.haml
也会在导航到博客文章时导致类似的错误,同时制作 article_layout.erb
工作正常。
因此,我怀疑 Middleman 不会接受除 ERb 之外的任何布局文件。不过,我在文档中找不到任何关于此的内容,而且我什至看到了所有示例都具有运行良好的 layout.haml
文件。只是我的不一样吗?为了使用 HAML 文件进行布局,是否需要使用 middleman init
设置标志?怎么回事?
最佳答案
正如@r.pazyaquian 在子评论中提到的,如果您更改布局文件类型,请确保重新启动服务器。
关于ruby - 无法将 HAML 布局与中间人一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25108471/
我想捕获我的计算机正在发送的数据包,修改它并发送它。我不能使用嗅探,因为它给了我数据包的副本。数据包本身被发送。我想停止发送数据包,更改它然后转发它 - MitM 攻击。 我怎样才能使用 scapy
如何使用来自标记的调用将自定义变量发送到局部变量。 "Title Goes here") %> /*trying to send a variable named title with "Title
当使用“middleman-blog”扩展在 Middleman 中生成一个简单的博客时,我得到一个布局文件,它只生成帖子的内容。 我想要的是获取当前帖子的标题并显示它。 我现在拥有的:
如何在中间人构建页面后运行自定义操作(例如,将文件复制到构建文件夹)? 我想将 Readme.md 文件从源代码放到构建目录。 最佳答案 您可以使用after_build Hook 。将以下代码添加到
这是堆栈跟踪, /Users/hadronsolutions/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_requir
我正在使用带 sprockets 的中间人将我的 js 和 css 文件打包到一个文件中。这很好用。但是我想知道是否可以在中间人中启用 sprockets 的指纹功能。 例如我的文件 all.js,其
这是堆栈跟踪, /Users/hadronsolutions/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_requir
我是 Middleman 的新手,在我的生活中,我似乎无法动态地为我在子目录和子目录上的导航设置事件类。 我有以下助手集,它适用于子目录(例如:/about/),但它不适用于子目录(例如:/about
尝试开始使用 Middleman 构建站点,我正在按照教程进行操作,但是当我启动服务器时,我总是得到“未知扩展名:livereload” 我已经有了 group :development do g
您好,想知道在模板中是否有一种简单的方法来访问当前翻译的语言字符串。 最佳答案 您可以通过 I18n.locale 访问它. 所以在 ERB 内部... ...在 HAML 中: = I18n.lo
我刚刚在 Azure 上注册了一个试用帐户,看看它是否对我来说是一个长期可行的平台。 使用具有各种 CMD 和启动脚本的网络 worker 角色,我成功地让 ruby 在云上工作 - 一条简单的“
你好想知道在模板中是否有一种简单的方法来访问当前翻译的 lang 字符串。 最佳答案 您可以使用 I18n.locale 访问它. 所以在 ERB 中...... ...在 HAML 中: = I1
我的计算机上有一些虚拟机,它们通过主机专用网络相互通信。 我想模拟这些机器之间的中间人攻击。我发现的所有运行 MITM 的工具都只是监视数据包,但我没有找到任何可以真正重放或更改它们的工具。 我发现了
所以我有一个关于图标,上面有一个链接。 "about" %> 这将产生这个: 在我添加任何样式之前,...图像链接出现问题。 但是一旦我添加了一些位置/尺寸样式 #about
我想记录 firefox 发送到服务器的所有内容,精确到每个字节,以便我可以在 python 客户端中重现它。所以我的想法是做一个快速而肮脏的黑客: 运行一个openssl s_server, 通过在
任何具有 Ruby 知识的人都知道是否可以使用 'simple-navigation 的 Padrino 兼容版本吗? '带有 Middleman 3.0 的 gem ? 我想实现多级导航 + 面包屑
运行 middleman build 时命令,set :css_dir 中指定的所有样式表文件编译为 .css扩展名。 我的问题是:如何排除 .scss来自编译过程的文件(以便内容保持不变并且不会编译
对于我的 Middleman-built website I have stored links and other information about all pages in a data fil
我为你们准备了一个简单的。 我想要一个特色内容部分,其中排除了当前文章 所以这可以通过 delete_if 使用 Middleman Blog: 但是我使用的是中间人代理,所以我无法访问 c
我刚刚第一次安装 Ruby 和 Middleman,我无法通过第一个“$ middleman init my_new_project”步骤。我已尝试使用谷歌搜索来解决我的问题,但不幸的是我找不到任何看
我是一名优秀的程序员,十分优秀!