Class: Nagoro::Pipe::Include
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" />
Instance Method Summary collapse
- #contents(file) ⇒ Object
- #tag(tag, original_attrs, value_attrs) ⇒ Object
- #tag_end(tag) ⇒ Object
- #tag_start(tag, original_attrs, value_attrs) ⇒ Object
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
33 34 35 36 37 38 |
# File 'lib/nagoro/pipe/include.rb', line 33 def contents(file) open(file){|o| o.read.strip } rescue Errno::ENOENT, Errno::EISDIR => ex warn ex. "<!-- #{ex} -->" end |
#tag(tag, original_attrs, value_attrs) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/nagoro/pipe/include.rb', line 15 def tag(tag, original_attrs, value_attrs) if tag == 'include' filename = value_attrs['href'] || value_attrs.fetch('src') append contents(filename) else super end end |
#tag_end(tag) ⇒ Object
40 41 42 |
# File 'lib/nagoro/pipe/include.rb', line 40 def tag_end(tag) super unless tag == 'include' end |
#tag_start(tag, original_attrs, value_attrs) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/nagoro/pipe/include.rb', line 24 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 |