Sha256: 4615fc0f0f22ca0daed4c136950db55df1ffe2cc70e0c0b37b54e3c8cbdbf5c1

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

module Garterbelt
  module ContentRendering
    def self.included(base)
      base.class_eval <<-RUBY
        attr_accessor :content
        
        include InstanceMethods
      RUBY
    end
    
    module InstanceMethods
      def render
        head
        render_content
        foot
        output
      end

      def head
        view._level += 1
      end

      def foot
        view._level -= 1
      end

      def render_content
        if content.is_a?(Proc)
          content.call
        else
          view._buffer << Text.new(:view => view, :content => content) if content
        end
        view.render_buffer
      end
      
      def raise_unless_block_content
        raise ArgumentError, "Block content required" unless self.content && self.content.is_a?(Proc)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
garterbelt-0.1.0 lib/renderers/content_rendering.rb