seaweed 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/required_files.rb +13 -9
- data/server/server.rb +24 -1
- metadata +3 -4
- data/lib/spec.rb +0 -42
data/lib/required_files.rb
CHANGED
@@ -10,12 +10,13 @@ class RequiredFiles < Hash
|
|
10
10
|
def add name
|
11
11
|
file_name = full_path name
|
12
12
|
if file_name && !self[name.to_sym]
|
13
|
-
|
13
|
+
directives = parse_directives file_name
|
14
14
|
self[name.to_sym] = {
|
15
15
|
:file_name => file_name,
|
16
|
-
:requires =>
|
16
|
+
:requires => directives['require']
|
17
17
|
}
|
18
|
-
|
18
|
+
requested = (directives['require'] | directives['request'])
|
19
|
+
requested.each{ |file| add file }
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -33,21 +34,24 @@ class RequiredFiles < Hash
|
|
33
34
|
file_path && "#{file_path}/#{name}.coffee"
|
34
35
|
end
|
35
36
|
|
36
|
-
# Scans a coffeescript file for
|
37
|
+
# Scans a coffeescript file for #require and #request directives.
|
37
38
|
#
|
38
39
|
# Example requirement directives:
|
39
40
|
# #require ST
|
40
41
|
# #require ST/Model/Index
|
41
|
-
def
|
42
|
-
|
42
|
+
def parse_directives name
|
43
|
+
directives = {
|
44
|
+
'require' => [],
|
45
|
+
'request' => []
|
46
|
+
}
|
43
47
|
File.open name do |file|
|
44
48
|
file.each do |line|
|
45
|
-
if line.match /^#require\s+(\S+)\s*$/
|
46
|
-
|
49
|
+
if line.match /^#(require|request)\s+(\S+)\s*$/
|
50
|
+
directives[$1] << $2
|
47
51
|
end
|
48
52
|
end
|
49
53
|
end
|
50
|
-
|
54
|
+
directives
|
51
55
|
end
|
52
56
|
|
53
57
|
# Callback functions for tsort
|
data/server/server.rb
CHANGED
@@ -3,6 +3,7 @@ require 'sinatra'
|
|
3
3
|
require 'slim'
|
4
4
|
require 'coffee-script'
|
5
5
|
|
6
|
+
# Patch in Sinatra support for Slim
|
6
7
|
module Sinatra
|
7
8
|
module Templates
|
8
9
|
def slim(template, options={}, locals={})
|
@@ -11,23 +12,38 @@ module Sinatra
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
15
|
+
# Configure slim for prettier code formatting
|
14
16
|
Slim::Engine.set_default_options :pretty => true
|
15
17
|
|
18
|
+
# Hide redundant log messages
|
19
|
+
disable :logging
|
20
|
+
|
21
|
+
# Dynamically compiles coffeescript, first checking to see if it has changed
|
16
22
|
def compile source, target
|
17
23
|
begin
|
24
|
+
# Get modified time of source file
|
18
25
|
mtime = File.mtime source
|
19
|
-
|
26
|
+
|
27
|
+
# If compled JavaScript file already exists and is up to date, return the
|
28
|
+
# existing file instead of compiling again
|
20
29
|
return File.read target if File.exists?(target) && File.mtime(target) == mtime
|
21
30
|
|
31
|
+
# Create base dir for compiled file
|
22
32
|
dir = target.sub /\/[^\/]+$/, ''
|
23
33
|
Dir.mkdir dir unless File.exists? dir
|
34
|
+
|
35
|
+
# Compile CoffeeScript to JavaScript file
|
24
36
|
File.open target, 'w' do |f|
|
25
37
|
f.write CoffeeScript.compile(File.read source)
|
26
38
|
end
|
39
|
+
|
40
|
+
# Mark compiled file with same modified date as source
|
27
41
|
File.utime mtime, mtime, target
|
28
42
|
|
43
|
+
# Return our newly compiled JavaScript
|
29
44
|
File.read target
|
30
45
|
rescue CoffeeScript::CompilationError => e
|
46
|
+
# Display CoffeeScript compilation error in a prettier format
|
31
47
|
message = if e.message.match /^SyntaxError: (.*) on line (\d+)\D*$/
|
32
48
|
"#{source}:#{$2}".ljust(40) + " #{$1}"
|
33
49
|
elsif e.message.match /^Parse error on line (\d+): (.*)$/
|
@@ -36,24 +52,31 @@ def compile source, target
|
|
36
52
|
"#{source} - #{e.message}"
|
37
53
|
end
|
38
54
|
puts "\e[31m#{message}\e[0m"
|
55
|
+
|
56
|
+
# Generate JS to display compilation error on HTML page
|
39
57
|
html = "<pre class=\"failed\">#{message}</pre>"
|
40
58
|
"$(function(){$(document.body).prepend(#{html.to_json});});"
|
41
59
|
end
|
42
60
|
end
|
43
61
|
|
62
|
+
# Processes request for seaweed Spec library
|
44
63
|
get "/Spec.js" do
|
45
64
|
compile File.expand_path('../../lib/Spec.coffee', __FILE__), "compiled/spec.js"
|
46
65
|
end
|
47
66
|
|
67
|
+
# Processes request for project lib files
|
48
68
|
get %r{^/lib/(.+)\.js$} do |file|
|
49
69
|
compile "lib/#{file}.coffee", "compiled/#{file}.js"
|
50
70
|
end
|
51
71
|
|
72
|
+
# Processes request for project spec files
|
52
73
|
get %r{^/spec/(.+)\.js$} do |file|
|
53
74
|
compile "spec/#{file}.coffee", "compiled/#{file}.js"
|
54
75
|
end
|
55
76
|
|
77
|
+
# Processes request for page index
|
56
78
|
get "/" do
|
79
|
+
# Build ordered list of required files to run all specs
|
57
80
|
requirements = RequiredFiles.new
|
58
81
|
requirements.paths = ['spec', 'lib']
|
59
82
|
Dir['spec/**/*.spec.coffee'].each do |file|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seaweed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tobias Cohen
|
@@ -118,7 +118,6 @@ files:
|
|
118
118
|
- server/views/index.slim
|
119
119
|
- lib/required_files.rb
|
120
120
|
- lib/Spec.coffee
|
121
|
-
- lib/spec.rb
|
122
121
|
has_rdoc: true
|
123
122
|
homepage: https://github.com/tobico/seaweed
|
124
123
|
licenses:
|
data/lib/spec.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/usr/bin/env jruby
|
2
|
-
require "rubygems"
|
3
|
-
require "bundler/setup"
|
4
|
-
require "coffee-script"
|
5
|
-
require "celerity"
|
6
|
-
|
7
|
-
Dir.mkdir 'compiled' unless File.exists? 'compiled'
|
8
|
-
raise "Can't create compile directory" unless File.directory? 'compiled'
|
9
|
-
|
10
|
-
# Compile coffee scripts
|
11
|
-
files = Dir['lib/**/*.coffee', 'spec/**/*.coffee']
|
12
|
-
longest_name = files.map(&:length).max
|
13
|
-
for file in files
|
14
|
-
begin
|
15
|
-
mtime = File.mtime file
|
16
|
-
|
17
|
-
outfile = file.sub /^(lib|spec)/, 'compiled'
|
18
|
-
outfile = outfile.sub /\.coffee$/, '.js'
|
19
|
-
|
20
|
-
next if File.exists?(outfile) && File.mtime(outfile) == mtime
|
21
|
-
|
22
|
-
dir = outfile.sub /\/[^\/]+$/, ''
|
23
|
-
Dir.mkdir dir unless File.exists? dir
|
24
|
-
File.open outfile, 'w' do |f|
|
25
|
-
f.write CoffeeScript.compile(File.read(file))
|
26
|
-
end
|
27
|
-
File.utime mtime, mtime, outfile
|
28
|
-
puts outfile
|
29
|
-
rescue CoffeeScript::CompilationError => e
|
30
|
-
if e.message.match /^SyntaxError: (.*) on line (\d+)\D*$/
|
31
|
-
puts "\e[31m#{file}:#{$2}".ljust(longest_name + 6) + " #{$1}\e[0m"
|
32
|
-
elsif e.message.match /^Parse error on line (\d+): (.*)$/
|
33
|
-
puts "\e[31m#{file}:#{$1}".ljust(longest_name + 6) + " #{$2}\e[0m"
|
34
|
-
else
|
35
|
-
puts "#{file} - #{e.message}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
browser = Celerity::Browser.new
|
41
|
-
browser.goto 'http://localhost/~tobico/SeaTurtle/spec/spec.html#terminal'
|
42
|
-
puts browser.text
|