slinky 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,7 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "eventmachine", ">= 0.12.0"
4
4
  gem "eventmachine_httpserver", ">= 0.2.0"
5
+ gem "em-proxy", ">= 0.1.5"
5
6
  gem "rainbow", ">= 1.1.1"
6
7
  gem "haml", ">= 3.0.0"
7
8
  gem "sass", ">= 3.1.1"
data/bin/slinky CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  root = File.expand_path(File.dirname(__FILE__))
4
4
 
5
- #require "#{root}/../lib/slinky"
6
- require 'slinky'
5
+ require "#{root}/../lib/slinky"
6
+ #require 'slinky'
7
7
 
8
8
  Slinky::Runner.new(ARGV).run
@@ -4,9 +4,9 @@ require 'pathname'
4
4
  module Slinky
5
5
  # extensions of files that can contain build directives
6
6
  DIRECTIVE_FILES = %w{js css html haml sass scss coffee}
7
- REQUIRE_DIRECTIVE = /^\W*(slinky_require)\((".*"|'.+'|)\)\W*$/
8
- SCRIPTS_DIRECTIVE = /^\W*(slinky_scripts)\W*$/
9
- STYLES_DIRECTIVE = /^\W*(slinky_styles)\W*$/
7
+ REQUIRE_DIRECTIVE = /^[^\n\w]*(slinky_require)\((".*"|'.+'|)\)[^\n\w]*$/
8
+ SCRIPTS_DIRECTIVE = /^[^\n\w]*(slinky_scripts)[^\n\w]*$/
9
+ STYLES_DIRECTIVE = /^[^\n\w]*(slinky_styles)[^\n\w]*$/
10
10
  BUILD_DIRECTIVES = Regexp.union(REQUIRE_DIRECTIVE, SCRIPTS_DIRECTIVE, STYLES_DIRECTIVE)
11
11
  CSS_URL_MATCHER = /url\(['"]?([^'"\/][^\s)]+\.[a-z]+)(\?\d+)?['"]?\)/
12
12
 
@@ -57,7 +57,7 @@ module Slinky
57
57
  %Q\<script type="text/javascript" src="#{d.relative_output_path}"></script>\
58
58
  }.join("")
59
59
  else
60
- '<script type="text/javscript" src="/scripts.js"></script>'
60
+ '<script type="text/javascript" src="/scripts.js"></script>'
61
61
  end
62
62
  end
63
63
 
@@ -68,9 +68,9 @@ module Slinky
68
68
  f = File.open(s.build_to.to_s, 'rb'){|f| f.read}
69
69
  (block_given?) ? (yield s, f) : f
70
70
  }.join("\n")
71
-
71
+
72
72
  File.open(output, "w+"){|f|
73
- f.write(compressor.compress(s))
73
+ f.write(compressor.compress(s))
74
74
  }
75
75
  scripts.collect{|s| FileUtils.rm(s.build_to)}
76
76
  end
data/lib/slinky/runner.rb CHANGED
@@ -13,6 +13,9 @@ module Slinky
13
13
  parser.parse! @argv
14
14
  @command = @argv.shift
15
15
  @arguments = @argv
16
+
17
+ config_path = "#{@options[:src_dir]}/slinky.yaml"
18
+ @config = ConfigReader.from_file(config_path) if File.exist?(config_path)
16
19
  end
17
20
 
18
21
  def version
@@ -30,6 +33,7 @@ module Slinky
30
33
  opts.on("-o DIR", "--build-dir DIR", "Directory to which the site will be built.", "Use in conjunction with the 'build' command."){|dir| @options[:build_dir] = File.expand_path(dir)}
31
34
  opts.on("-p PORT", "--port PORT", "Port to run on (default: #{@options[:port]})"){|p| @options[:port] = p.to_i}
32
35
  opts.on("-s DIR", "--src-dir DIR", "Directory containing project source"){|p| @options[:src_dir] = p}
36
+ opts.on("-n", "--no-proxy", "Don't set up proxy server"){ @options[:no_proxy] = true }
33
37
  end
34
38
  end
35
39
 
@@ -49,7 +53,12 @@ module Slinky
49
53
 
50
54
  EM::run {
51
55
  Slinky::Server.dir = @options[:src_dir]
52
- EM::start_server "0.0.0.0", @options[:port], Slinky::Server
56
+ if @config && @config.proxies && !@options[:no_proxy]
57
+ server = EM::start_server "127.0.0.1", 5324, Slinky::Server
58
+ ProxyServer.run(@config.proxies, @options[:port], 5324)
59
+ else
60
+ EM::start_server "0.0.0.0", @options[:port], Slinky::Server
61
+ end
53
62
  puts "Started static file server on port #{@options[:port]}"
54
63
  }
55
64
  end
data/lib/slinky/server.rb CHANGED
@@ -34,7 +34,6 @@ module Slinky
34
34
  if File.exists?(path) && !File.directory?(path)
35
35
  size = File.size(path)
36
36
  _, _, extension = path.match(EXTENSION_REGEX).to_a
37
- resp.content_type MIME::Types.type_for(path).first
38
37
  # File reading code from rack/file.rb
39
38
  File.open path do |file|
40
39
  resp.content = ""
@@ -50,7 +49,7 @@ module Slinky
50
49
  end
51
50
  end
52
51
 
53
- # Returns the proper responce for files that do not exist
52
+ # Returns the proper response for files that do not exist
54
53
  def self.not_found resp
55
54
  resp.status = 404
56
55
  resp.content = "File not found"
@@ -66,6 +65,7 @@ module Slinky
66
65
  if file.is_a? ManifestDir
67
66
  file = @manifest.find_by_path(path+"/index.html")
68
67
  end
68
+ resp.content_type MIME::Types.type_for(path).first
69
69
  Server.handle_file(resp, file).send_response
70
70
  end
71
71
  end
data/lib/slinky.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  ROOT = File.expand_path(File.dirname(__FILE__))
2
2
 
3
+ require 'uri'
4
+ require 'yaml'
3
5
  require 'eventmachine'
6
+ require 'em-proxy'
4
7
  require 'evma_httpserver'
5
8
  require 'uri'
6
9
  require 'tempfile'
@@ -11,8 +14,10 @@ require 'yui/compressor'
11
14
 
12
15
  require "#{ROOT}/slinky/em-popen3"
13
16
  require "#{ROOT}/slinky/compilers"
17
+ require "#{ROOT}/slinky/config_reader"
14
18
  require "#{ROOT}/slinky/manifest"
15
19
  require "#{ROOT}/slinky/compiled_file"
20
+ require "#{ROOT}/slinky/proxy_server"
16
21
  require "#{ROOT}/slinky/server"
17
22
  require "#{ROOT}/slinky/runner"
18
23
  require "#{ROOT}/slinky/builder"
@@ -27,3 +32,11 @@ Dir.glob("#{ROOT}/slinky/compilers/*.rb").each{|compiler|
27
32
  puts "Failed to load #{compiler}: syntax error"
28
33
  end
29
34
  }
35
+
36
+ # Without this monkeypatch data uris in CSS cause compression to fail
37
+ class YUI::Compressor
38
+ def command
39
+ @command.insert 1, "-Xss8m"
40
+ @command.map { |word| Shellwords.escape(word) }.join(" ")
41
+ end
42
+ end
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.4.0"
8
+ s.version = "0.4.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-08-09}
12
+ s.date = %q{2011-08-19}
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}
data/spec/slinky_spec.rb CHANGED
@@ -46,7 +46,7 @@ describe "Slinky" do
46
46
  end
47
47
 
48
48
  it "should produce the correct scripts string for production" do
49
- @mprod.scripts_string.should == '<script type="text/javscript" src="/scripts.js"></script>'
49
+ @mprod.scripts_string.should == '<script type="text/javascript" src="/scripts.js"></script>'
50
50
  end
51
51
 
52
52
  it "should produce the correct scripts string for devel" do
@@ -239,7 +239,6 @@ describe "Slinky" do
239
239
  end
240
240
 
241
241
  it "should serve files" do
242
- @resp.should_receive(:content_type).with(MIME::Types.type_for("/src/l1/test.js").first)
243
242
  Slinky::Server.serve_file @resp, "/src/l1/test.js"
244
243
  @resp.content.should == File.read("/src/l1/test.js")
245
244
  end
@@ -252,14 +251,12 @@ describe "Slinky" do
252
251
 
253
252
  it "should handle static files" do
254
253
  mf = Slinky::ManifestFile.new("/src/l1/l2/test.txt", nil, @mdevel)
255
- @resp.should_receive(:content_type).with(MIME::Types.type_for("/src/l1/le/test.txt").first)
256
254
  Slinky::Server.handle_file @resp, mf
257
255
  @resp.content.should == File.read("/src/l1/l2/test.txt")
258
256
  end
259
257
 
260
258
  it "should handle compiled files" do
261
259
  mf = Slinky::ManifestFile.new("/src/l1/test.sass", nil, @mdevel)
262
- @resp.should_receive(:content_type).with(MIME::Types.type_for("test.css").first)
263
260
  $stdout.should_receive(:puts).with("Compiled /src/l1/test.sass".foreground(:green))
264
261
  Slinky::Server.handle_file @resp, mf
265
262
  @resp.content.should == Slinky::SassCompiler::compile(File.read("/src/l1/test.sass"), "")
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: slinky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.4.0
5
+ version: 0.4.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-08-09 00:00:00 -07:00
13
+ date: 2011-08-19 00:00:00 -07:00
14
14
  default_executable: slinky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - ">="
227
227
  - !ruby/object:Gem::Version
228
- hash: 501156153539470276
228
+ hash: 1095209777694119011
229
229
  segments:
230
230
  - 0
231
231
  version: "0"