Sha256: 9d7e093d9e2553f5ffec016000b7111fdcad11416bf7db2c6eb2193b47863ec9
Contents?: true
Size: 1.18 KB
Versions: 4
Compression:
Stored size: 1.18 KB
Contents
require 'cgi' module Webgen::Tag # Includes a file verbatim and optionally escapes all special HTML characters and processes webgen # tags in it. class IncludeFile include Webgen::Tag::Base include Webgen::WebsiteAccess def initialize #:nodoc: website.blackboard.add_listener(:node_changed?, method(:node_changed?)) end # Include the specified file verbatim in the output, optionally escaping special HTML characters # and processing tags in it. 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 ####### private ####### def node_changed?(node) if filenames = node.node_info[:tag_includefile_filenames] node.flag(:dirty) if filenames.any? {|f, mtime| File.mtime(f) > mtime} end end end end
Version data entries
4 entries across 4 versions & 2 rubygems