Sha256: f274b652bec8be905a58028d08a492c5d5c46ed384c04e2ce2deead940ae4b4c

Contents?: true

Size: 835 Bytes

Versions: 6

Compression:

Stored size: 835 Bytes

Contents

require 'webgen/tag'
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['arch'].include?('mswin32') ?  "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 ($? >> 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

6 entries across 6 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.4.20080929 lib/webgen/tag/executecommand.rb
gettalong-webgen-0.5.5.20081001 lib/webgen/tag/executecommand.rb
webgen-0.5.3 lib/webgen/tag/executecommand.rb
webgen-0.5.2 lib/webgen/tag/executecommand.rb
webgen-0.5.4 lib/webgen/tag/executecommand.rb
webgen-0.5.5 lib/webgen/tag/executecommand.rb