Class: Nagoro::Pipe::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/nagoro/pipe/base.rb

Direct Known Subclasses

Compile, Element, Include, Instruction, Morph, Tidy

Constant Summary collapse

EMPTY_TAG =
%w[ area base basefont br col frame hr
img input isindex link meta param ]

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/nagoro/pipe/base.rb', line 7

def initialize(io)
  @body, @stack = [], []
  @scanner = Scanner.new(io, self)
end

Instance Method Details

#append(string) ⇒ Object



38
39
40
# File 'lib/nagoro/pipe/base.rb', line 38

def append(string)
  @body << string
end

#doctype(string) ⇒ Object



50
51
52
53
# File 'lib/nagoro/pipe/base.rb', line 50

def doctype(string)
  string.strip!
  append "<!DOCTYPE #{string}>"
end

#instruction(name, instruction) ⇒ Object



42
43
44
# File 'lib/nagoro/pipe/base.rb', line 42

def instruction(name, instruction)
  append "<?#{name} #{instruction.to_s.strip} ?>"
end

#resultObject



12
13
14
15
# File 'lib/nagoro/pipe/base.rb', line 12

def result
  @scanner.stream
  @body.join
end

#tag_end(tag) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/nagoro/pipe/base.rb', line 26

def tag_end(tag)
  case tag
  when *EMPTY_TAG
  else
    append "</#{tag}>"
  end
end

#tag_start(tag, original_attrs, value_attrs) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/nagoro/pipe/base.rb', line 17

def tag_start(tag, original_attrs, value_attrs)
  case tag
  when *EMPTY_TAG
    append "#{tag_with(tag, original_attrs)} />"
  else
    append "#{tag_with(tag, original_attrs)}>"
  end
end

#tag_with(tag, hash) ⇒ Object



46
47
48
# File 'lib/nagoro/pipe/base.rb', line 46

def tag_with(tag, hash)
  "<#{tag}#{hash.map{|k,v| %( #{k}=#{v}) }.join}"
end

#text(string) ⇒ Object



34
35
36
# File 'lib/nagoro/pipe/base.rb', line 34

def text(string)
  append(string)
end