Class: Wee::Brush::Page

Inherits:
Wee::Brush show all
Defined in:
lib/wee/html_brushes.rb

Constant Summary collapse

HTML_HTML =
'html'.freeze
HTML_HEAD =
'head'.freeze
HTML_TITLE =
'title'.freeze
HTML_BODY =
'body'.freeze

Instance Attribute Summary

Attributes inherited from Wee::Brush

#canvas, #document

Instance Method Summary collapse

Methods inherited from Wee::Brush

#close, nesting?, #setup

Instance Method Details

#head(&block) ⇒ Object

Raises:

  • (ArgumentError)


787
788
789
790
791
# File 'lib/wee/html_brushes.rb', line 787

def head(&block)
  raise ArgumentError unless block
  @head = block
  self
end

#title(t) ⇒ Object



782
783
784
785
# File 'lib/wee/html_brushes.rb', line 782

def title(t)
  @title = t
  self
end

#with(text = nil, &block) ⇒ Object



752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
# File 'lib/wee/html_brushes.rb', line 752

def with(text=nil, &block)
  @document.start_tag(HTML_HTML)
  @document.start_tag(HTML_HEAD)

  if @title
    @document.start_tag(HTML_TITLE)
    @document.text(@title)
    @document.end_tag(HTML_TITLE)
  end

  if @head
    @canvas.nest(&@head)
  end

  @document.end_tag(HTML_HEAD)
  @document.start_tag(HTML_BODY)

  if text
    raise ArgumentError if block
    @document.text(text)
  else
    @canvas.nest(&block) if block 
  end

  @document.end_tag(HTML_BODY)
  @document.end_tag(HTML_HTML)

  @document = @canvas = nil
end