Class: Middleman::Extensions::ExternalPipeline

Inherits:
Middleman::Extension show all
Defined in:
lib/middleman-core/extensions/external_pipeline.rb

Constant Summary

Constants included from Contracts

Contracts::PATH_MATCHER

Instance Attribute Summary

Attributes inherited from Middleman::Extension

#app, #options

Instance Method Summary collapse

Methods inherited from Middleman::Extension

activated_extension, #add_exposed_to_context, #after_build, #after_configuration, #after_extension_activated, after_extension_activated, #before_build, #before_configuration, clear_after_extension_callbacks, config, define_setting, expose_to_application, expose_to_config, expose_to_template, global_config, helpers, #manipulate_resource_list, option, #ready, resources

Methods included from Contracts

#Contract

Constructor Details

#initialize(app, config = {}, &block) ⇒ ExternalPipeline

Returns a new instance of ExternalPipeline.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/middleman-core/extensions/external_pipeline.rb', line 10

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

  require 'thread'

  @watcher = app.files.watch :source,
                             path: File.expand_path(options[:source], app.root),
                             latency: options[:latency],
                             frontmatter: false

  logger.info "== Executing: `#{options[:command]}`"

  if app.build? || options[:disable_background_execution]
    watch_command!
  else
    ::Thread.new { watch_command! }
  end
end

Instance Method Details

#watch_command!Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/middleman-core/extensions/external_pipeline.rb', line 29

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

  @watcher.poll_once!
rescue ::Errno::ENOENT => e
  logger.error "== External: Command failed with message: #{e.message}"
  exit(1)
end