Max*_*kas 4 ruby-on-rails slim-lang
我Base64.encode64(val)用来将html转换为base64。例:
- val = link_to 'Link', link_path
= Base64.encode64(val)
Run Code Online (Sandbox Code Playgroud)
但是,如何使标记变细?像这样:
.class = link_to 'Link', link_path # <- this output with slim div
Run Code Online (Sandbox Code Playgroud)
甚至多行
div
span
.another_div
Run Code Online (Sandbox Code Playgroud)
有一种方法可以将苗条代码放入部分代码中并执行以下操作:
- var = render 'partial'
= Base64.encode64(var) # Convert into base64
Run Code Online (Sandbox Code Playgroud)
如何做到不偏不倚?
Slim 通过Tilt接口公开其模板,如下所示:
# Render a template file:
Slim::Template.new("template.slim", options).render(scope)
# Render a string:
Slim::Template.new(options) { "b slim markup" }.render(scope)
Run Code Online (Sandbox Code Playgroud)
当选项是可选的哈希选项为纤薄的范围是在其中执行模板代码的对象。
因此,以下内容:
slim_markup = <<-SLIM
div
span
.another_div
SLIM
# The options hash and scope have been omitted for the sake of simplicity
html_output = Slim::Template.new { slim_markup }.render
Run Code Online (Sandbox Code Playgroud)
将值设置html_output为:
<div></div>
<span></span>
<div class="another_div"></div>
Run Code Online (Sandbox Code Playgroud)
但是,对于您使用url helper link_path的示例,您必须提供苗条的范围,在其中可以使用url helper,例如控制器。
| 归档时间: |
|
| 查看次数: |
1269 次 |
| 最近记录: |