Sha256: da6163df306df4124fd98993459adf0f0949c51d6f8f5eb8d4297463067430a1

Contents?: true

Size: 726 Bytes

Versions: 1

Compression:

Stored size: 726 Bytes

Contents

require 'webgen/tag'
require 'cgi'
require "tempfile"

module Webgen::Tag

  # Executes the given command and returns the standard output. All special HTML characters are
  # escaped.
  class ExecuteCommand

    include Webgen::Tag::Base

    # Execute the command and return the standard output.
    def call(tag, body, context)
      command = param('tag.executecommand.command')
      output = `#{command} 2> /dev/null`
      if ($? >> 8) != 0
        raise "Command '#{command}' in <#{context.ref_node.absolute_lcn}> has return value != 0: #{output}"
      end
      output = CGI::escapeHTML(output) if param('tag.executecommand.escape_html')
      [output, param('tag.executecommand.process_output')]
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webgen-0.5.1 lib/webgen/tag/executecommand.rb