module Webgen::Tag::IncludeFile

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

Public Class Methods

call(tag, _body, context) click to toggle source

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

   # File lib/webgen/tag/include_file.rb
13 def self.call(tag, _body, context)
14   filename = context[:config]['tag.include_file.filename']
15   filename = File.join(context.website.directory, filename) unless filename =~ /^(\/|\w:)/
16   if !File.exist?(filename)
17     raise Webgen::RenderError.new("File '#{filename}' cannot be included because it does not exist",
18                                   "tag.#{tag}", context.dest_node, context.ref_node)
19   end
20 
21   content = File.read(filename)
22   content = CGI::escapeHTML(content) if context[:config]['tag.include_file.escape_html']
23   context.website.ext.item_tracker.add(context.dest_node, :file, filename)
24 
25   [content, context[:config]['tag.include_file.process_output']]
26 end