Sha256: 1efe4fdfe511c742b0bcb1164eafca6b16fdbc029757122ef1a5dfc0a246ec93

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

require 'haml'

module Waves
  
  module Renderers

    module Haml
      
      Extension = :haml
      
      # extend Waves::Renderers::Mixin
      
      def self.included(app)
        Waves::Views.renderers << self
        Waves::Views::Base.send(:include, self::ViewMethods)
      end
      
      module ViewMethods
        
        def haml(string, assigns={})
          engine = ::Haml::Engine.new( string )
          scope = Scope.new
          helper = Waves.main::Helpers[self.class.basename]
          scope.meta_eval { include( helper ) }
          scope.instance_eval do
            assigns.each { |key,val| instance_variable_set("@#{key}",val) unless key == :request }
          end
          engine.render(scope, assigns)
        end
        
      end
      
      # def self.render( path, assigns )
      #   engine = ::Haml::Engine.new( template( path ) )
      #   scope = Scope.new
      #   helper = helper( path )
      #   scope.meta_eval { include( helper ) }
      #   scope.instance_eval do
      #     assigns.each { |key,val| instance_variable_set("@#{key}",val) unless key == :request }
      #   end
      #   engine.render(scope, assigns)
      # end
      
      class Scope
        include Waves::Helpers::DocType
        include Waves::Helpers::Layouts
        include Waves::Helpers::Model
        include Waves::Helpers::View

        def <<(s)
          eval("@haml_buffer", @binding).push_text s # add to rendered output
        end

        def capture(&block)
          capture_haml(nil, &block)
        end

      end

    end
  
  end

end



Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
waves-edge-2009.03.10.13.14 lib/layers/renderers/haml.rb