Sha256: f02f9df73d234c910ba230dfeae93bffdb00a5f4dc9bb083d77961c5c97ccf74

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Garterbelt
  class ContentTag < ClosedTag
    include ContentRendering
    
    def initialize(opts, &block)
      super
      if block_given?
        self.content = block
      else
        self.content = opts[:content]
      end
    end
    
    def id(identifier, &block)
      super(identifier)
      self.content = block if block_given?
      self
    end
    
    def c(*classes, &block)
      super(*classes)
      self.content = block if block_given?
      self
    end
    
    def head_template
      if style == :text 
        ''
      else 
        head_end = style == :compact ? '' : line_end
        "#{indent}<#{type}#{rendered_attributes}>#{head_end}"
      end
    end
    
    def head
      self.output << head_template
      super
    end
    
    def foot_template
      if style == :text 
        [:p, :ul, :ol, :li].include?(type) ? "\n" : '' 
      else
        foot_dent = style == :compact ? '' : indent
        "#{foot_dent}</#{type}>#{line_end}"
      end
    end
    
    def foot
      super
      self.output << foot_template
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
garterbelt-0.1.1 lib/renderers/content_tag.rb