slinky 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "eventmachine", ">= 0.12.0"
4
4
  gem "eventmachine_httpserver", ">= 0.2.0"
5
+ gem "rainbow", ">= 1.1.1"
6
+ gem "haml", ">= 3.0.0"
7
+ #gem "sass", ">= 4.0.0"
8
+ gem "coffee-script", ">= 2.2.0"
5
9
 
6
10
  group :development do
7
11
  gem "bacon", ">= 0"
@@ -10,4 +14,3 @@ group :development do
10
14
  gem "jeweler", "~> 1.5.2"
11
15
  gem "rcov", ">= 0"
12
16
  end
13
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
data/bin/slinky CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ root = File.expand_path(File.dirname(__FILE__))
4
+
5
+ #require "#{root}/../lib/slinky"
3
6
  require 'slinky'
4
7
 
5
8
  Slinky::Runner.run
@@ -16,23 +16,50 @@ module Slinky
16
16
  # Compiles the source file to a temporary location
17
17
  def compile &cb
18
18
  path = @path || tmp_path
19
+ @last_compiled = Time.now
20
+ if @compiler.respond_to? :compile
21
+ compiler_compile path, cb
22
+ else
23
+ compiler_command path, cb
24
+ end
25
+ end
19
26
 
20
- command = @compiler.command @source, path
27
+ def compiler_compile path, cb
28
+ begin
29
+ out = @compiler.compile @source
30
+ compile_succeeded
31
+ @path = path
32
+ File.open(path, "w+") do |f|
33
+ f.write out
34
+ end
35
+ rescue
36
+ compile_failed $!
37
+ end
38
+ cb.call @path, nil, nil, $!
39
+ end
21
40
 
22
- puts "Running command '#{command}'"
41
+ def command path, cb
42
+ command = @compiler.command @source, path
23
43
 
24
44
  EM.system3 command do |stdout, stderr, status|
25
- @last_compiled = Time.now
26
45
  if status.exitstatus != 0
27
- $stderr.write "Failed on #{@source}: #{stderr.strip}\n"
46
+ compile_failed stderr.strip
28
47
  else
29
- puts "Compiled #{@source}"
48
+ compile_succeeded
30
49
  @path = path
31
50
  end
32
51
  cb.call(@path, status, stdout, stderr)
33
52
  end
34
53
  end
35
54
 
55
+ def compile_succeeded
56
+ puts "Compiled #{@source}".foreground(:green)
57
+ end
58
+
59
+ def compile_failed e
60
+ $stderr.write "Failed on #{@source}: #{e}\n".foreground(:red)
61
+ end
62
+
36
63
  # Calls the supplied callback with the path of the compiled file,
37
64
  # compiling the source file first if necessary.
38
65
  def file &cb
@@ -1,12 +1,14 @@
1
+ require 'coffee-script'
2
+
1
3
  module Slinky
2
4
  module CoffeeCompiler
3
5
  Server.register_compiler self,
4
6
  :inputs => ["coffee"],
5
7
  :outputs => ["js"]
6
-
7
- def CoffeeCompiler::command from, to
8
- root = File.dirname(__FILE__)
9
- %Q?#{root}/coffee-helper "#{from}" "#{to}"?
8
+
9
+ def CoffeeCompiler::compile file
10
+ s = File.read(file)
11
+ CoffeeScript::compile(s)
10
12
  end
11
13
  end
12
14
  end
@@ -1,11 +1,15 @@
1
+ require 'haml'
2
+
1
3
  module Slinky
2
4
  module HamlCompiler
3
5
  Server.register_compiler self,
4
6
  :inputs => ["haml"],
5
7
  :outputs => ["html"]
6
-
7
- def HamlCompiler::command from, to
8
- %Q?haml "#{from}" "#{to}"?
9
- end
8
+
9
+ def HamlCompiler::compile file
10
+ s = File.read(file)
11
+ haml_engine = Haml::Engine.new(s)
12
+ haml_engine.render
13
+ end
10
14
  end
11
15
  end
@@ -1,11 +1,15 @@
1
+ require 'sass'
2
+
1
3
  module Slinky
2
4
  module SassCompiler
3
5
  Server.register_compiler self,
4
6
  :inputs => ["sass", "scss"],
5
7
  :outputs => ["css"]
6
-
7
- def SassCompiler::command from, to
8
- %Q?sass "#{from}:#{to}"?
8
+
9
+ def SassCompiler::compile file
10
+ s = File.read(file)
11
+ sass_engine = Sass::Engine.new(s, :load_paths => [File.dirname(file)])
12
+ sass_engine.render
9
13
  end
10
14
  end
11
15
  end
data/lib/slinky/server.rb CHANGED
@@ -103,23 +103,16 @@ module Slinky
103
103
  _, _, extension = path.match(EXTENSION_REGEX).to_a
104
104
  @resp.content_type CONTENT_TYPES[extension]
105
105
  # File reading code from rack/file.rb
106
- range = 0..size-1
107
- EM.defer do
108
- File.open path do |file|
109
- file.seek(range.begin)
110
- remaining_len = range.end-range.begin+1
111
- while remaining_len > 0
112
-
113
- part = file.read([8192, remaining_len].min)
114
- break unless part
115
- remaining_len -= part.length
116
-
117
- @resp.chunk part
118
- @resp.send_chunks
119
- end
106
+ File.open path do |file|
107
+ @resp.content = ""
108
+ while size > 0
109
+ part = file.read([8192, size].min)
110
+ break unless part
111
+ size -= part.length
112
+ @resp.content << part
120
113
  end
121
- @resp.send_trailer
122
114
  end
115
+ @resp.send_response
123
116
  else
124
117
  @resp.status = 404
125
118
  @resp.content = "File '#{path}' not found."
data/lib/slinky.rb CHANGED
@@ -4,6 +4,8 @@ require 'eventmachine'
4
4
  require 'evma_httpserver'
5
5
  require 'uri'
6
6
  require 'tempfile'
7
+ require 'rainbow'
8
+ require 'rbtrace'
7
9
 
8
10
  require "#{ROOT}/slinky/em-popen3"
9
11
  require "#{ROOT}/slinky/compiled_file"
data/slinky.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slinky}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mwylde"]
12
- s.date = %q{2011-03-28}
12
+ s.date = %q{2011-04-15}
13
13
  s.default_executable = %q{slinky}
14
14
  s.description = %q{A static file server for rich javascript apps that automatically compiles SASS, HAML, CoffeeScript and more}
15
15
  s.email = %q{mwylde@wesleyan.edu}
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
42
42
  s.homepage = %q{http://github.com/mwylde/slinky}
43
43
  s.licenses = ["MIT"]
44
44
  s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.5.2}
45
+ s.rubygems_version = %q{1.6.2}
46
46
  s.summary = %q{Static file server for javascript apps}
47
47
  s.test_files = [
48
48
  "spec/slinky_spec.rb",
@@ -55,6 +55,9 @@ Gem::Specification.new do |s|
55
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
56
  s.add_runtime_dependency(%q<eventmachine>, [">= 0.12.0"])
57
57
  s.add_runtime_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
58
+ s.add_runtime_dependency(%q<rainbow>, [">= 1.1.1"])
59
+ s.add_runtime_dependency(%q<haml>, [">= 3.0.0"])
60
+ s.add_runtime_dependency(%q<coffee-script>, [">= 2.2.0"])
58
61
  s.add_development_dependency(%q<bacon>, [">= 0"])
59
62
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
60
63
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -63,6 +66,9 @@ Gem::Specification.new do |s|
63
66
  else
64
67
  s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
65
68
  s.add_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
69
+ s.add_dependency(%q<rainbow>, [">= 1.1.1"])
70
+ s.add_dependency(%q<haml>, [">= 3.0.0"])
71
+ s.add_dependency(%q<coffee-script>, [">= 2.2.0"])
66
72
  s.add_dependency(%q<bacon>, [">= 0"])
67
73
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
68
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -72,6 +78,9 @@ Gem::Specification.new do |s|
72
78
  else
73
79
  s.add_dependency(%q<eventmachine>, [">= 0.12.0"])
74
80
  s.add_dependency(%q<eventmachine_httpserver>, [">= 0.2.0"])
81
+ s.add_dependency(%q<rainbow>, [">= 1.1.1"])
82
+ s.add_dependency(%q<haml>, [">= 3.0.0"])
83
+ s.add_dependency(%q<coffee-script>, [">= 2.2.0"])
75
84
  s.add_dependency(%q<bacon>, [">= 0"])
76
85
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
77
86
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slinky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - mwylde
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-28 00:00:00 -04:00
13
+ date: 2011-04-15 00:00:00 -04:00
14
14
  default_executable: slinky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -36,8 +36,41 @@ dependencies:
36
36
  prerelease: false
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
39
- name: bacon
39
+ name: rainbow
40
40
  requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.1
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: haml
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 3.0.0
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: coffee-script
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 2.2.0
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: bacon
73
+ requirement: &id006 !ruby/object:Gem::Requirement
41
74
  none: false
42
75
  requirements:
43
76
  - - ">="
@@ -45,10 +78,10 @@ dependencies:
45
78
  version: "0"
46
79
  type: :development
47
80
  prerelease: false
48
- version_requirements: *id003
81
+ version_requirements: *id006
49
82
  - !ruby/object:Gem::Dependency
50
83
  name: yard
51
- requirement: &id004 !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
52
85
  none: false
53
86
  requirements:
54
87
  - - ~>
@@ -56,10 +89,10 @@ dependencies:
56
89
  version: 0.6.0
57
90
  type: :development
58
91
  prerelease: false
59
- version_requirements: *id004
92
+ version_requirements: *id007
60
93
  - !ruby/object:Gem::Dependency
61
94
  name: bundler
62
- requirement: &id005 !ruby/object:Gem::Requirement
95
+ requirement: &id008 !ruby/object:Gem::Requirement
63
96
  none: false
64
97
  requirements:
65
98
  - - ~>
@@ -67,10 +100,10 @@ dependencies:
67
100
  version: 1.0.0
68
101
  type: :development
69
102
  prerelease: false
70
- version_requirements: *id005
103
+ version_requirements: *id008
71
104
  - !ruby/object:Gem::Dependency
72
105
  name: jeweler
73
- requirement: &id006 !ruby/object:Gem::Requirement
106
+ requirement: &id009 !ruby/object:Gem::Requirement
74
107
  none: false
75
108
  requirements:
76
109
  - - ~>
@@ -78,10 +111,10 @@ dependencies:
78
111
  version: 1.5.2
79
112
  type: :development
80
113
  prerelease: false
81
- version_requirements: *id006
114
+ version_requirements: *id009
82
115
  - !ruby/object:Gem::Dependency
83
116
  name: rcov
84
- requirement: &id007 !ruby/object:Gem::Requirement
117
+ requirement: &id010 !ruby/object:Gem::Requirement
85
118
  none: false
86
119
  requirements:
87
120
  - - ">="
@@ -89,7 +122,7 @@ dependencies:
89
122
  version: "0"
90
123
  type: :development
91
124
  prerelease: false
92
- version_requirements: *id007
125
+ version_requirements: *id010
93
126
  description: A static file server for rich javascript apps that automatically compiles SASS, HAML, CoffeeScript and more
94
127
  email: mwylde@wesleyan.edu
95
128
  executables:
@@ -133,7 +166,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
166
  requirements:
134
167
  - - ">="
135
168
  - !ruby/object:Gem::Version
136
- hash: -1454064815511573175
169
+ hash: 3806476896341792215
137
170
  segments:
138
171
  - 0
139
172
  version: "0"
@@ -146,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
179
  requirements: []
147
180
 
148
181
  rubyforge_project:
149
- rubygems_version: 1.5.2
182
+ rubygems_version: 1.6.2
150
183
  signing_key:
151
184
  specification_version: 3
152
185
  summary: Static file server for javascript apps