Sha256: 48c2fc45a848903333b1e7254e7ec5dc0f8ecb740ad750b5ed96e567b598faf6

Contents?: true

Size: 924 Bytes

Versions: 8

Compression:

Stored size: 924 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 Webgen::RenderError.new("Command '#{command}' has return value != 0: #{output}",
                                      self.class.name, context.dest_node, context.ref_node)
      end
      output = CGI::escapeHTML(output) if param('tag.executecommand.escape_html')
      [output, param('tag.executecommand.process_output')]
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
webgen-0.5.17 lib/webgen/tag/executecommand.rb
webgen-0.5.15 lib/webgen/tag/executecommand.rb
webgen-0.5.14 lib/webgen/tag/executecommand.rb
webgen-0.5.13 lib/webgen/tag/executecommand.rb
webgen-0.5.12 lib/webgen/tag/executecommand.rb
webgen-0.5.11 lib/webgen/tag/executecommand.rb
webgen-0.5.10 lib/webgen/tag/executecommand.rb
webgen-0.5.9 lib/webgen/tag/executecommand.rb