Module: Webgen::Tag::ExecuteCommand

Defined in:
lib/webgen/tag/execute_command.rb

Overview

Executes the given command and returns the standard output. All special HTML characters are optionally escaped.

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.call(tag, body, context) ⇒ Object

Execute the command and return the standard output.



17
18
19
20
21
22
23
24
25
26
# File 'lib/webgen/tag/execute_command.rb', line 17

def self.call(tag, body, context)
  command = context[:config]['tag.execute_command.command']
  output = `#{command} 2> #{BIT_BUCKET}`
  if $?.exitstatus != 0
    raise Webgen::RenderError.new("Command '#{command}' has return value != 0: #{output}",
                                  "tag.#{tag}", context.dest_node, context.ref_node)
  end
  output = CGI::escapeHTML(output) if context[:config]['tag.execute_command.escape_html']
  [output, context[:config]['tag.execute_command.process_output']]
end