Class: Nagoro::Pipe::Include

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

Overview

Include is used to include the contents of another file. The file will not be changed or interpreted in any way by this pipe.

If the tag contains anything the contents will be put after the included contents.

Syntax:

<include href="some_file.xhtml" />
<include src="some_file.xhtml" />

Constant Summary

Constants inherited from Base

Base::EMPTY_TAG

Instance Method Summary collapse

Methods inherited from Base

#append, #doctype, #initialize, #instruction, #result, #tag_with, #text

Constructor Details

This class inherits a constructor from Nagoro::Pipe::Base

Instance Method Details

#contents(file) ⇒ Object



24
25
26
27
28
29
# File 'lib/nagoro/pipe/include.rb', line 24

def contents(file)
  open(file){|o| o.read.strip }
rescue Errno::ENOENT, Errno::EISDIR => ex
  warn ex.message
  "<!-- #{ex} -->"
end

#tag_end(tag) ⇒ Object



31
32
33
# File 'lib/nagoro/pipe/include.rb', line 31

def tag_end(tag)
  super unless tag == 'include'
end

#tag_start(tag, original_attrs, value_attrs) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/nagoro/pipe/include.rb', line 15

def tag_start(tag, original_attrs, value_attrs)
  if tag == 'include'
    filename = value_attrs['href'] || value_attrs.fetch('src')
    append contents(filename)
  else
    super
  end
end