Permalink
Browse files

Doing horrible horrible things to get haml to render

  • Loading branch information...
1 parent 712b0a1 commit 323a7336726e14058c1c9da7b3bac3ae9ab5e033 Philip (flip) Kromer committed Sep 7, 2010
Showing with 20 additions and 3 deletions.
  1. +5 −2 _plugins/haml_converter.rb
  2. +15 −1 _plugins/monkeypatches.rb
View
7 _plugins/haml_converter.rb
@@ -20,14 +20,17 @@ def convert(content)
begin
context = ClosedStruct.new(
:site => ClosedStruct.new($conv_payload["site"]),
- :page => ClosedStruct.new($conv_payload["page"]))
+ :page => ClosedStruct.new($conv_payload["page"]),
+ :content => $conv_payload["content"]
+ )
+
context.extend(HamlHelpers)
context.extend(::Helpers) if defined?(::Helpers)
engine = Haml::Engine.new(content, :attr_wrapper => %{\"})
engine.render(context)
rescue StandardError => e
- puts "!!! HAML Error: " + e.message
+ puts "!!! HAML Error: " + e.message, e.backtrace
end
end
end
View
16 _plugins/monkeypatches.rb
@@ -29,11 +29,24 @@ def pluralized_array(singular_key, plural_key)
end
Post.class_eval do
+ def read_yaml *args
+ super *args
+ data.reverse_merge!(site.config['post_defaults']) if site.config['post_defaults']
+ end
+
def title
data['title']
end
end
+ Layout.class_eval do
+ def transform *args
+ @base_content = content if not @transformed
+ @transformed = true
+ self.content = converter.convert(@base_content)
+ end
+ end
+
module Convertible
# Add any necessary layouts to this convertible document
# +layouts+ is a Hash of {"name" => "layout"}
@@ -57,8 +70,9 @@ def do_layout(payload, layouts)
layout = layouts[self.data["layout"]]
while layout
payload = payload.deep_merge({"content" => self.output, "page" => layout.data})
+ $conv_payload = payload
+ layout.transform if layout.ext == '.haml'
self.output = Liquid::Template.parse(layout.content).render(payload, info)
-
layout = layouts[layout.data["layout"]]
end
end

0 comments on commit 323a733

Please sign in to comment.