slinky 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -4,3 +4,6 @@ Slinky is a static file server designed to make development of static
4
4
  web sites and applications simpler. Simply run slinky in the home
5
5
  directory of your app and it will serve while compiling things like
6
6
  SASS, HAML and CoffeeScript on the fly.
7
+
8
+ To get it, just `gem install slinky`. Note that this is unstable, not well
9
+ tested, and hardly feature-complete. It may, however, be useful.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -6,10 +6,11 @@ module Slinky
6
6
 
7
7
  # Creates a new CompiledFile, compiling the provided source file
8
8
  # with the provided compiler class.
9
- def initialize source, compiler
9
+ def initialize source, compiler, output_ext
10
10
  @source = source
11
11
  @compiler = compiler
12
12
  @last_compiled = Time.new(0)
13
+ @output_ext = output_ext
13
14
  end
14
15
 
15
16
  # Compiles the source file to a temporary location
@@ -45,12 +46,13 @@ module Slinky
45
46
  # Returns whether the source file has changed since it was last
46
47
  # compiled.
47
48
  def needs_update?
49
+ return true if @compiler.to_s.match "SassCompiler"
48
50
  File.new(source).mtime > @last_compiled
49
51
  end
50
52
 
51
53
  private
52
54
  def tmp_path
53
- Tempfile.new("slinky").path
55
+ Tempfile.new("slinky").path + "." + @output_ext
54
56
  end
55
57
  end
56
58
  end
data/lib/slinky/server.rb CHANGED
@@ -1,11 +1,18 @@
1
1
  module Slinky
2
+ CONTENT_TYPES = {
3
+ 'html' => 'text/html',
4
+ 'js' => 'application/x-javascript',
5
+ 'css' => 'text/css'
6
+ }
7
+
8
+ EXTENSION_REGEX = /(.+)\.(\w+)/
9
+
2
10
  class Server < EventMachine::Connection
3
11
  include EM::HttpServer
4
12
 
5
13
  @compilers = []
6
14
  @compilers_by_ext = {}
7
15
 
8
-
9
16
  @files = {}
10
17
 
11
18
  class << self
@@ -27,7 +34,6 @@ module Slinky
27
34
  self.class.instance_variable_get(:@files)
28
35
  end
29
36
 
30
- EXTENSION_REGEX = /(^[\w\d\:\/\.]*)\.(\w+)/
31
37
  def process_http_request
32
38
  @resp = EventMachine::DelegatedHttpResponse.new(self)
33
39
 
@@ -61,7 +67,7 @@ module Slinky
61
67
  compilers[extension].each do |c|
62
68
  c[:inputs].each do |i|
63
69
  if files_by_ext[i]
64
- cfile = CompiledFile.new files_by_ext[i], c[:klass]
70
+ cfile = CompiledFile.new files_by_ext[i], c[:klass], extension
65
71
  files[path] = cfile
66
72
  break
67
73
  end
@@ -93,17 +99,26 @@ module Slinky
93
99
  end
94
100
 
95
101
  def serve_file path
96
- if File.exists? path
97
- size = File.size? path
98
- if true || size < EventMachine::FileStreamer::MappingThreshold
99
- s = File.open(path).read
100
- @resp.content = s
101
- @resp.send_response
102
- else
103
- stream_file_data path do
104
- @resp.send_headers
105
- @resp.send_trailer
102
+ if File.exists?(path) && size = File.size?(path)
103
+ _, _, extension = path.match(EXTENSION_REGEX).to_a
104
+ @resp.content_type CONTENT_TYPES[extension]
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
120
  end
121
+ @resp.send_trailer
107
122
  end
108
123
  else
109
124
  @resp.status = 404
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.0"
8
+ s.version = "0.1.1"
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-11}
12
+ s.date = %q{2011-03-28}
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}
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slinky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
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-11 00:00:00 -05:00
13
+ date: 2011-03-28 00:00:00 -04:00
14
14
  default_executable: slinky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -133,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
- hash: -191776360948002665
136
+ hash: -1454064815511573175
137
137
  segments:
138
138
  - 0
139
139
  version: "0"