Sha256: ad89423bdee120e3b12ac154b719c45c16f582d9acae33cf118c5d08a0debbad

Contents?: true

Size: 837 Bytes

Versions: 2

Compression:

Stored size: 837 Bytes

Contents

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

require 'cgi'
require 'tempfile'
require 'rbconfig'

module Webgen::Tag

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

    include Webgen::Tag::Base

    BIT_BUCKET = (Config::CONFIG['host_os'] =~ /mswin|mingw/ ?  "nul" : "/dev/null")

    # Execute the command and return the standard output.
    def call(tag, body, context)
      command = param('tag.executecommand.command')
      output = `#{command} 2> #{BIT_BUCKET}`
      if $?.exitstatus != 0
        raise "Command '#{command}' in <#{context.ref_node.alcn}> 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

2 entries across 2 versions & 1 rubygems

Version Path
gettalong-webgen-0.5.9.20090620 lib/webgen/tag/executecommand.rb
gettalong-webgen-0.5.9.20090626 lib/webgen/tag/executecommand.rb