Class: Nanoc::External::Filter
- Inherits:
-
Filter
- Object
- Filter
- Nanoc::External::Filter
- Defined in:
- lib/nanoc/external/filter.rb
Overview
Pipes content through an external process.
For this filter to work, the external program must be able to receive input from standard input and it must write its output to standard output.
Instance Method Summary collapse
-
#run(content, params = {}) ⇒ String
Executes this filter.
Instance Method Details
#run(content, params = {}) ⇒ String
Executes this filter. Parameters passed to this filter through ‘:options` will be passed to the specified command.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nanoc/external/filter.rb', line 29 def run(content, params = {}) debug = params.fetch(:debug, false) cmd = params.fetch(:exec, nil) opts = params.fetch(:options, []) if cmd.nil? raise Nanoc::Errors::GenericTrivial.new("nanoc-external: missing :exec argument") end cmd_with_opts = [ cmd ] + opts odebug(cmd_with_opts.join(' ')) if debug out = StringIO.new piper = Nanoc::Extra::Piper.new(:stdout => out, :stderr => $stderr) piper.run(cmd_with_opts, content) odebug(out.string) if debug out.string end |