module Blade

Constants

CONFIG_DEFAULTS
CONFIG_FILENAMES
VERSION

Attributes

config[R]

Public Instance Methods

build() click to toggle source
# File lib/blade.rb, line 91
def build
  initialize!
  Assets.build
end
clean_tmp_path() click to toggle source
# File lib/blade.rb, line 112
def clean_tmp_path
  tmp_path.rmtree if tmp_path.exist?
end
ensure_tmp_path() click to toggle source
# File lib/blade.rb, line 108
def ensure_tmp_path
  tmp_path.mkpath
end
initialize!(options = {}) click to toggle source
# File lib/blade.rb, line 69
def initialize!(options = {})
  return if @initialized
  @initialized = true

  options = CONFIG_DEFAULTS.deep_merge(blade_file_options).deep_merge(options)
  @config = Blade::Config.new options

  config.load_paths = Array(config.load_paths)
  config.logical_paths = Array(config.logical_paths)

  if config.build?
    config.build.logical_paths = Array(config.build.logical_paths)
    config.build.path ||= "."
  end

  config.plugins ||= {}

  load_requires
  load_plugins
  load_adapter
end
register_component(component) click to toggle source
# File lib/blade.rb, line 23
def register_component(component)
  @components << component
end
root_path() click to toggle source
# File lib/blade.rb, line 100
def root_path
  Pathname.new(File.dirname(__FILE__)).join("../")
end
running?() click to toggle source
# File lib/blade.rb, line 65
def running?
  @running
end
start(options = {}) click to toggle source
# File lib/blade.rb, line 42
def start(options = {})
  return if running?
  ensure_tmp_path

  initialize!(options)
  load_interface

  handle_exit

  EM.run do
    @components.each { |c| c.try(:start) }
    @running = true
  end
end
stop() click to toggle source
# File lib/blade.rb, line 57
def stop
  return if @stopping
  @stopping = true
  @components.each { |c| c.try(:stop) }
  EM.stop if EM.reactor_running?
  @running = false
end
tmp_path() click to toggle source
# File lib/blade.rb, line 104
def tmp_path
  Pathname.new(".").join("tmp/blade")
end
url(path = "/") click to toggle source
# File lib/blade.rb, line 96
def url(path = "/")
  "http://#{Server.host}:#{config.port}#{path}"
end

Private Instance Methods

blade_file_options() click to toggle source
# File lib/blade.rb, line 128
def blade_file_options
  if filename = CONFIG_FILENAMES.detect { |name| File.exist?(name) }
    YAML.load_file(filename)
  else
    {}
  end
end
handle_exit() click to toggle source
# File lib/blade.rb, line 117
def handle_exit
  at_exit do
    stop
    exit $!.status if $!.is_a?(SystemExit)
  end

  %w( INT ).each do |signal|
    trap(signal) { exit(1) }
  end
end
load_adapter() click to toggle source
# File lib/blade.rb, line 140
def load_adapter
  require "blade/#{config.framework}_adapter"
end
load_interface() click to toggle source
# File lib/blade.rb, line 136
def load_interface
  require "blade/interface/#{config.interface}"
end
load_plugins() click to toggle source
# File lib/blade.rb, line 150
def load_plugins
  config.plugins.keys.each do |name|
    require "blade/#{name}_plugin"
  end
end
load_requires() click to toggle source
# File lib/blade.rb, line 144
def load_requires
  Array(config.require).each do |path|
    require path
  end
end