Module: Seaweed
- Defined in:
- lib/seaweed.rb,
lib/seaweed/runner.rb,
lib/seaweed/server.rb,
lib/seaweed/version.rb
Defined Under Namespace
Constant Summary collapse
- ROOT =
File. File.join(File.dirname(__FILE__), '..')
- PROJECT_ROOT =
File. "."
- CONFIG_PATHS =
[ File.join(PROJECT_ROOT, 'seaweed.yml'), File.join(PROJECT_ROOT, 'config', 'seaweed.yml') ]
- VERSION =
"0.1.2"
Class Method Summary collapse
- .all_paths ⇒ Object
- .libs ⇒ Object
- .load_configuration ⇒ Object
- .port ⇒ Object
- .port=(value) ⇒ Object
- .root_url ⇒ Object
- .run_suite ⇒ Object
- .spawn_server ⇒ Object
- .specs ⇒ Object
-
.sprockets_environment ⇒ Object
Prepares a Sprockets::Environment object to serve coffeescript assets.
- .start_server ⇒ Object
- .watch_for_changes ⇒ Object
Class Method Details
.all_paths ⇒ Object
56 57 58 |
# File 'lib/seaweed.rb', line 56 def self.all_paths libs + specs end |
.libs ⇒ Object
48 49 50 |
# File 'lib/seaweed.rb', line 48 def self.libs @configuration['libs'] end |
.load_configuration ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/seaweed.rb', line 21 def self.load_configuration # Set configuration defaults @configuration['port'] = 4567 @configuration['libs'] = ['lib'] @configuration['specs'] = ['spec'] # Load custom configuration file CONFIG_PATHS.each do |path| if File.exists? path @configuration.merge! YAML.load(File.read(path)) puts "Loaded configuration from “#{path}”" end end end |
.port ⇒ Object
36 37 38 |
# File 'lib/seaweed.rb', line 36 def self.port @configuration['port'] end |
.port=(value) ⇒ Object
40 41 42 |
# File 'lib/seaweed.rb', line 40 def self.port= value @configuration['port'] = value end |
.root_url ⇒ Object
44 45 46 |
# File 'lib/seaweed.rb', line 44 def self.root_url "http://localhost:#{port}/" end |
.run_suite ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/seaweed.rb', line 96 def self.run_suite require 'celerity' if @browser @browser.refresh else @browser = Celerity::Browser.new @browser.goto "#{root_url}#terminal" end puts @browser.text end |
.spawn_server ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/seaweed.rb', line 83 def self.spawn_server # Start server in its own thread Thread.new &start_server # Keep trying to connect to server until we succeed begin page = Net::HTTP.get URI.parse(root_url) rescue Errno::ECONNREFUSED sleep 1 retry end end |
.specs ⇒ Object
52 53 54 |
# File 'lib/seaweed.rb', line 52 def self.specs @configuration['specs'] end |
.sprockets_environment ⇒ Object
Prepares a Sprockets::Environment object to serve coffeescript assets
61 62 63 64 65 66 67 68 |
# File 'lib/seaweed.rb', line 61 def self.sprockets_environment @environment ||= Sprockets::Environment.new.tap do |environment| environment.append_path File.join(Seaweed::ROOT, 'lib') all_paths.each do |path| environment.append_path path end end end |
.start_server ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/seaweed.rb', line 70 def self.start_server app = Rack::Builder.app do map '/assets' do run Seaweed.sprockets_environment end map '/' do run Seaweed::Server end end Rack::Handler.default.run app, :Port => port end |
.watch_for_changes ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/seaweed.rb', line 108 def self.watch_for_changes require 'watchr' # Build a regexp to match .coffee files in any project paths path_matcher = Regexp.new('^(' + all_paths.map{ |s| Regexp.escape s}.join('|') + ')\/.*\.coffee$') script = Watchr::Script.new script.watch(path_matcher) { run_suite } controller = Watchr::Controller.new(script, Watchr.handler.new) controller.run end |