module Middleman::Weinre

Attributes

app[R]

Public Class Methods

included(app, options_hash={}, &block)
Alias for: registered
options() click to toggle source
# File lib/middleman-weinre.rb, line 12
def options
  @@options
end
registered(app, options_hash={}, &block) click to toggle source
# File lib/middleman-weinre.rb, line 16
def registered(app, options_hash={}, &block)
  defaults = {
    :port => 8080,
    :hostname => nil,
    :bin => '/usr/locale/bin/weinre'
  }
  @@options = defaults.merge(options_hash)
  app.ready do
    if :environment != :build
      require 'socket'
      hostname = @@options[:hostname] || UDPSocket.open {|s| s.connect("64.233.187.99", 1); s.addr.last}
      if !@@options[:bin].blank?
        wnr = fork do
          exec "#{$WEINRE_BIN} --httpPort #{@@options[:port]} --boundHost #{hostname} &>/dev/null"
        end
        Process.detach(wnr)
        puts "== Weinre is running at http://#{hostname}:#{@@options[:port]}"
        # puts "== Weinre remote debugging is at http://#{hostname}:#{@@options[:port]}/client/#anonymous"
      else
        puts "== Winre was not found on your system. Could not auto-start it for you. :("
        puts "==   Type 'weinre' in a separate terminal to start the server"
      end
      # app.set :weinre_hostname, hostname
      # app.set :weinre_port, options_hash[:port]
      # app.set :weinre_bin, options_hash[:bin]
    else
      # Nothing
    end
  end
  app.send :include, Helpers
end
Also aliased as: included