Sha256: bf945ced529f4aea801c6b8f153249a3efd3294ed896f4b2d583d61c49f202c5

Contents?: true

Size: 936 Bytes

Versions: 12

Compression:

Stored size: 936 Bytes

Contents

# encoding: utf-8
require_relative 'previewer/web_app'
require_relative 'previewer/web_server'
require_relative 'previewer/file_listener'

module Devcenter::Previewer

  extend self

  def preview(slug, md_path, host, port)
    server = WebServer.new(host, port, WebApp)
    file_listener_callback = Proc.new do |modified, added, removed|
      modified.each{ |f| Devcenter::Logger.log "File modified: #{f}" }
      WebApp.send_server_event
    end

    listener = FileListener.new(md_path, file_listener_callback)

    [:INT, :TERM].each do |signal|
      trap(signal) do
        listener.stop
        server.stop
        say "\nPreview finished."
        exit
      end
    end
    listener.start
    url = "http://#{host}:#{port}/#{slug}"
    say "\nLive preview for #{slug} available in #{url}"
    say "It will refresh when you save #{md_path}"
    say "Press Ctrl+C to exit...\n"
    Launchy.open(url)
    server.start
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
devcenter-1.1.0 lib/devcenter/previewer.rb
devcenter-1.1.0rc2 lib/devcenter/previewer.rb
devcenter-1.1.0rc1 lib/devcenter/previewer.rb
devcenter-1.0.7 lib/devcenter/previewer.rb
devcenter-1.0.6 lib/devcenter/previewer.rb
devcenter-1.0.4 lib/devcenter/previewer.rb
devcenter-1.0.3 lib/devcenter/previewer.rb
devcenter-1.0.1 lib/devcenter/previewer.rb
devcenter-1.0.0 lib/devcenter/previewer.rb
devcenter-0.0.14 lib/devcenter/previewer.rb
devcenter-0.0.13 lib/devcenter/previewer.rb
devcenter-0.0.12 lib/devcenter/previewer.rb