Sha256: 84a829842e5e33bb3ab17ec4c3686b0945f7e48b76bf2879cf0313942afbc676

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

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

require 'cgi'

module Webgen
  class Tag

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

      # Include the specified file verbatim in the output, optionally escaping special HTML characters
      # and/or processing tags in it.
      def self.call(tag, _body, context)
        filename = context[:config]['tag.include_file.filename']
        filename = File.join(context.website.directory, filename) unless filename =~ /^(\/|\w:)/
        if !File.exist?(filename)
          raise Webgen::RenderError.new("File '#{filename}' cannot be included because it does not exist",
                                        "tag.#{tag}", context.dest_node, context.ref_node)
        end

        content = File.read(filename)
        content = CGI::escapeHTML(content) if context[:config]['tag.include_file.escape_html']
        context.website.ext.item_tracker.add(context.dest_node, :file, filename)

        [content, context[:config]['tag.include_file.process_output']]
      end

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/tag/include_file.rb
webgen-1.7.2 lib/webgen/tag/include_file.rb
webgen-1.7.1 lib/webgen/tag/include_file.rb
webgen-1.7.0 lib/webgen/tag/include_file.rb
webgen-1.6.0 lib/webgen/tag/include_file.rb
webgen-1.5.2 lib/webgen/tag/include_file.rb
webgen-1.5.1 lib/webgen/tag/include_file.rb
webgen-1.5.0 lib/webgen/tag/include_file.rb
webgen-1.4.1 lib/webgen/tag/include_file.rb