Sha256: fc49c55dc29085b2c4601833e0ee3e5c0d76fa3fd69925e5ea88979997d5b4f7
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
begin require 'haml/engine' rescue LoadError puts "you must install the haml gem to use .haml templates" end module ActionView # stub, in case the requires for that active_* stuff of Haml doesn't fail # but we are not running Rails ;) class Base # stub def concat end # stub def form_tag end end end module Merb module Template module Haml # Custom HAML-options to be merged. trait :haml_options => { :locals => {} } ::Merb::Controller.register_engine self, %w[ haml ] class << self @@hamls ||= {} @@mtimes ||= {} def exempt_from_layout? false end def transform(options = {}) opts, file, view_context = options.values_at(:opts, :file, :view_context) opts = ancestral_trait[:haml_options].merge(opts) if precompiled = get_precompiled(file) opts[:precompiled] ||= precompiled haml = ::Haml::Engine.new("", opts) else haml = ::Haml::Engine.new(IO.read(file), opts) set_precompiled(file, haml.precompiled) end haml.to_html(view_context) end private def get_precompiled(path, opts={}) if @@hamls[path] && !cache_template?(path) return @@hamls[path] end end def set_precompiled(path, precompiled) @@hamls[path], @@mtimes[path] = precompiled, Time.now end def cache_template?(path) return false unless ::Merb::Server.config[:cache_templates] return true unless @@hamls[path] @@mtimes[path] < File.mtime(path) || (File.symlink?(path) && (@@mtimes[path] < File.lstat(path).mtime)) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
merb-0.2.0 | lib/merb/template/haml.rb |