Class: Webgen::Tag::IncludeFile

Inherits:
Object
  • Object
show all
Includes:
Base, WebsiteAccess
Defined in:
lib/webgen/tag/includefile.rb

Overview

Includes a file verbatim and optionally escapes all special HTML characters and processes webgen tags in it.

Instance Method Summary collapse

Methods included from WebsiteAccess

included, website

Methods included from Base

#create_params_hash, #create_tag_params, #param, #set_params

Methods included from Loggable

#log, #puts

Constructor Details

#initializeIncludeFile

:nodoc:



14
15
16
# File 'lib/webgen/tag/includefile.rb', line 14

def initialize #:nodoc:
  website.blackboard.add_listener(:node_changed?, method(:node_changed?))
end

Instance Method Details

#call(tag, body, context) ⇒ Object

Include the specified file verbatim in the output, optionally escaping special HTML characters and processing tags in it.



20
21
22
23
24
25
26
27
28
# File 'lib/webgen/tag/includefile.rb', line 20

def call(tag, body, context)
  filename = param('tag.includefile.filename')
  filename = File.join(website.directory, filename) unless filename =~ /^(\/|\w:)/
  content = File.open(filename, 'rb') {|f| f.read}
  content = CGI::escapeHTML(content) if param('tag.includefile.escape_html')
  (context.dest_node.node_info[:tag_includefile_filenames] ||= []) << [filename, File.mtime(filename)]

  [content, param('tag.includefile.process_output')]
end