hchoroomi (owner)

Fork Of

Revisions

gist: 58417 Download_button fork
public
Public Clone URL: git://gist.github.com/58417.git
Embed All Files: show embed
haml_plus_liquid.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# haml + liquid example
#
# James MacAulay 2009
 
require 'rubygems'
require 'liquid'
require 'haml'
 
 
template = <<EOF
 
#title {{ title }}
#articles
{% for article in articles %}
.article
%h2.title article {{ forloop.index }}
.body
{{ article }}
{% endfor %}
 
EOF
 
 
engine = Haml::Engine.new(template, :suppress_eval => true)
haml_output = engine.render
 
# <div id='title'>{{ title }}</div>
# <div id='articles'>
# {% for article in articles %}
# <div class='article'>
# <h2 class='title'>article {{ forloop.index }}</h2>
# <div class='body'>
# {{ article }}
# </div>
# </div>
# {% endfor %}
# </div>
 
 
parsed_liquid = Liquid::Template.parse(haml_output)
assigns = {'title' => 'blah', 'articles' => ["<p>blah</p>\n<p>blah</p>\n<p>blah</p>", 'yadda yadda yadda']}
liquid_output = parsed_liquid.render(assigns)
 
# <div id='title'>blah</div>
# <div id='articles'>
#
# <div class='article'>
# <h2 class='title'>article 1</h2>
# <div class='body'>
# <p>blah</p>
# <p>blah</p>
# <p>blah</p>
# </div>
# </div>
#
# <div class='article'>
# <h2 class='title'>article 2</h2>
# <div class='body'>
# yadda yadda yadda
# </div>
# </div>
#
# </div>