Sha256: f3b5f9e98e3d6be8b3c9e1f6f5a01989506f934b8f7d3d89745f93d7c1c796c4

Contents?: true

Size: 812 Bytes

Versions: 8

Compression:

Stored size: 812 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

8 entries across 8 versions & 1 rubygems

Version Path
garterbelt-0.0.9 lib/renderers/content_rendering.rb
garterbelt-0.0.8 lib/renderers/content_rendering.rb
garterbelt-0.0.7 lib/renderers/content_rendering.rb
garterbelt-0.0.6 lib/renderers/content_rendering.rb
garterbelt-0.0.5 lib/renderers/content_rendering.rb
garterbelt-0.0.4 lib/renderers/content_rendering.rb
garterbelt-0.0.3 lib/renderers/content_rendering.rb
garterbelt-0.0.2 lib/renderers/content_rendering.rb