Sha256: ad733eadda78bc3dc4ce235cec4379c0973d7a68b539a98eeea47e0e27de1a7a

Contents?: true

Size: 835 Bytes

Versions: 1

Compression:

Stored size: 835 Bytes

Contents

require 'wee/html_writer'

module Wee

  #
  # Represents a complete HTML document.
  #
  class HtmlDocument < HtmlWriter
    def initialize
      super([])
    end

    def set
      @set ||= {}
    end

    def has_divert?(tag)
      @divert and @divert[tag]
    end

    def define_divert(tag)
      raise ArgumentError if has_divert?(tag)
      @divert ||= {}
      @port << (@divert[tag] = [])
    end

    def divert(tag, txt=nil, &block)
      raise ArgumentError unless has_divert?(tag)
      raise ArgumentError if txt and block

      divert = @divert[tag]

      if txt
        divert << txt
      end

      if block
        old_port = @port
        begin
          @port = divert
          block.call
        ensure
          @port = old_port
        end
      end
    end

    def to_s
      @port.join
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mullen-wee-2.2.0 lib/wee/html_document.rb