Sha256: db65fac1cfe5a71882ed15218a41cb00f1586ebc94bde48dd069d44b99b5ad4f

Contents?: true

Size: 990 Bytes

Versions: 16

Compression:

Stored size: 990 Bytes

Contents

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

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

module Webgen
  class Tag

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

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

      # Execute the command and return the standard output.
      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

    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
webgen-1.7.3 lib/webgen/tag/execute_command.rb
webgen-1.7.2 lib/webgen/tag/execute_command.rb
webgen-1.7.1 lib/webgen/tag/execute_command.rb
webgen-1.7.0 lib/webgen/tag/execute_command.rb
webgen-1.6.0 lib/webgen/tag/execute_command.rb
webgen-1.5.2 lib/webgen/tag/execute_command.rb
webgen-1.5.1 lib/webgen/tag/execute_command.rb
webgen-1.5.0 lib/webgen/tag/execute_command.rb
webgen-1.4.1 lib/webgen/tag/execute_command.rb
webgen-1.4.0 lib/webgen/tag/execute_command.rb
webgen-1.3.0 lib/webgen/tag/execute_command.rb
webgen-1.2.1 lib/webgen/tag/execute_command.rb
webgen-1.2.0 lib/webgen/tag/execute_command.rb
webgen-1.1.0 lib/webgen/tag/execute_command.rb
webgen-1.0.0 lib/webgen/tag/execute_command.rb
webgen-1.0.0.beta3 lib/webgen/tag/execute_command.rb