Sha256: 7bc5d4d3767b3d8af53b6532ddd341dc35b15600876354c34c967cedb7c58dfb

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

class Middleman::Extensions::ExternalPipeline < ::Middleman::Extension
  self.supports_multiple_instances = true

  option :name, nil, 'The name of the pipeline', required: true
  option :command, nil, 'The command to initialize', required: true
  option :source, nil, 'Path to merge into sitemap', required: true
  option :latency, 0.25, 'Latency between refreshes of source'

  def initialize(app, config={}, &block)
    super

    require 'thread'

    app.files.watch :source,
                    path: File.expand_path(options[:source], app.root),
                    latency: options[:latency]
  end

  def ready
    if app.build?
      logger.info "== Executing: `#{options[:command]}`"
      watch_command!
    else
      logger.debug "== Executing: `#{options[:command]}`"
      ::Thread.new { watch_command! }
    end
  end

  def watch_command!
    ::IO.popen(options[:command], 'r') do |pipe|
      while buf = pipe.gets
        without_newline = buf.sub(/\n$/, '')
        logger.info "== External: #{without_newline}" if without_newline.length > 0
      end
    end
  rescue ::Errno::ENOENT => e
    logger.error "== External: Command failed with message: #{e.message}"
    exit(1)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
middleman-core-4.0.0.rc.2 lib/middleman-core/extensions/external_pipeline.rb
middleman-core-4.0.0.rc.1 lib/middleman-core/extensions/external_pipeline.rb