1
0
Fork 0
mirror of https://github.com/middleman/middleman.git synced 2022-11-09 12:20:27 -05:00
middleman--middleman/lib/middleman/features/markaby.rb
2009-09-29 10:10:47 -07:00

43 lines
No EOL
1 KiB
Ruby

begin
require 'markaby'
rescue LoadError
puts "Markaby not available. Install it with: gem install markaby"
end
module Middleman
module Markaby
def self.included(base)
base.supported_formats << "mab"
end
def render_path(path)
if template_exists?(path, :mab)
markaby path.to_sym
else
super
end
end
def markaby(template=nil, options={}, locals = {}, &block)
options, template = template, nil if template.is_a?(Hash)
template = lambda { block } if template.nil?
render :mab, template, options, locals
end
protected
def render_mab(template, data, options, locals, &block)
filename = options.delete(:filename) || '<MARKABY>'
line = options.delete(:line) || 1
mab = ::Markaby::Builder.new(locals)
if data.respond_to?(:to_str)
eval(data.to_str, binding, filename, line)
elsif data.kind_of?(Proc)
data.call(mab)
end
end
end
class Base
include Middleman::Markaby
end
end