Sha256: b1dec88b41ccebbf09153538f93e1c1545d5993cd7595ea10ace7bfb7f775a78

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

# -*- encoding: utf-8 -*-

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

15 entries across 15 versions & 3 rubygems

Version Path
gettalong-webgen-0.5.7.20090227 lib/webgen/tag/includefile.rb
gettalong-webgen-0.5.8.20090507 lib/webgen/tag/includefile.rb
gettalong-webgen-0.5.9.20090620 lib/webgen/tag/includefile.rb
gettalong-webgen-0.5.9.20090626 lib/webgen/tag/includefile.rb
thewoolleyman-webgen-0.5.8.20090419 lib/webgen/tag/includefile.rb
webgen-0.5.17 lib/webgen/tag/includefile.rb
webgen-0.5.15 lib/webgen/tag/includefile.rb
webgen-0.5.14 lib/webgen/tag/includefile.rb
webgen-0.5.13 lib/webgen/tag/includefile.rb
webgen-0.5.12 lib/webgen/tag/includefile.rb
webgen-0.5.11 lib/webgen/tag/includefile.rb
webgen-0.5.10 lib/webgen/tag/includefile.rb
webgen-0.5.9 lib/webgen/tag/includefile.rb
webgen-0.5.7 lib/webgen/tag/includefile.rb
webgen-0.5.8 lib/webgen/tag/includefile.rb