staticmatic 0.10.6 → 0.10.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,6 +18,7 @@ begin
18
18
  gem.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
19
19
 
20
20
  gem.add_dependency("haml", ">=2.0.0")
21
+ gem.add_dependency("rack", ">=1.0")
21
22
  gem.add_dependency("mongrel", ">=1.1.5")
22
23
  end
23
24
  rescue LoadError
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 10
4
- :patch: 6
4
+ :patch: 7
data/lib/staticmatic.rb CHANGED
@@ -2,7 +2,8 @@ require 'rubygems'
2
2
  require 'haml'
3
3
  require 'sass'
4
4
  require 'sass/plugin'
5
- require 'mongrel'
5
+ require 'rack'
6
+ require 'rack/handler/mongrel'
6
7
  require 'fileutils'
7
8
 
8
9
  module StaticMatic
@@ -1,17 +1,14 @@
1
1
  module StaticMatic
2
- class Server < Mongrel::HttpHandler
3
- @@file_only_methods = ["GET","HEAD"]
4
-
5
- def initialize(staticmatic)
6
- @files = Mongrel::DirHandler.new(staticmatic.site_dir, false)
2
+ class Server
3
+ def initialize(staticmatic, default = nil)
4
+ @files = default || Rack::File.new(staticmatic.site_dir)
7
5
  @staticmatic = staticmatic
8
6
  end
9
-
10
- def process(request, response)
7
+
8
+ def call(env)
11
9
  @staticmatic.load_helpers
12
- path_info = request.params[Mongrel::Const::PATH_INFO]
13
- get_or_head = @@file_only_methods.include? request.params[Mongrel::Const::REQUEST_METHOD]
14
-
10
+ path_info = env["PATH_INFO"]
11
+
15
12
  file_dir, file_name, file_ext = expand_path(path_info)
16
13
 
17
14
  # remove stylesheets/ directory if applicable
@@ -19,40 +16,44 @@ module StaticMatic
19
16
 
20
17
  file_dir = CGI::unescape(file_dir)
21
18
  file_name = CGI::unescape(file_name)
22
-
23
- if file_ext && file_ext.match(/html|css/)
24
- response.start(200) do |head, out|
25
- head["Content-Type"] = "text/#{file_ext}"
26
- output = ""
27
19
 
28
- if @staticmatic.template_exists?(file_name, file_dir) && !(File.basename(file_name) =~ /^\_/)
20
+ unless file_ext && ["html", "css"].include?(file_ext) &&
21
+ @staticmatic.template_exists?(file_name, file_dir) &&
22
+ File.basename(file_name) !~ /^\_/
23
+ return @files.call(env)
24
+ end
29
25
 
30
- begin
31
- if file_ext == "css"
32
- output = @staticmatic.generate_css(file_name, file_dir)
33
- else
34
- output = @staticmatic.generate_html_with_layout(file_name, file_dir)
35
- end
36
- rescue StaticMatic::Error => e
37
- output = e.message
38
- end
39
- else
40
- if @files.can_serve(path_info)
41
- @files.process(request,response)
42
- else
43
- output = "File not Found"
44
- end
45
- end
46
- out.write output
47
- end
48
- else
49
- # try to serve static file from site dir
50
- if @files.can_serve(path_info)
51
- @files.process(request,response)
26
+ res = Rack::Response.new
27
+ res.header["Content-Type"] = "text/#{file_ext}"
28
+
29
+ begin
30
+ if file_ext == "css"
31
+ res.write @staticmatic.generate_css(file_name, file_dir)
32
+ else
33
+ res.write @staticmatic.generate_html_with_layout(file_name, file_dir)
52
34
  end
35
+ rescue StaticMatic::Error => e
36
+ res.write e.message
53
37
  end
38
+
39
+ res.finish
54
40
  end
55
41
 
42
+ # Starts the StaticMatic preview server
43
+ def self.start(staticmatic)
44
+ port = staticmatic.configuration.preview_server_port || 3000
45
+
46
+ host = staticmatic.configuration.preview_server_host || ""
47
+
48
+ app = Rack::Builder.new do
49
+ use Rack::ShowExceptions
50
+ run StaticMatic::Server.new(staticmatic)
51
+ end
52
+ Rack::Handler::Mongrel.run(app, :Port => port, :Host => host)
53
+ end
54
+
55
+ private
56
+
56
57
  def expand_path(path_info)
57
58
  dirname, basename = File.split(path_info)
58
59
 
@@ -71,24 +72,5 @@ module StaticMatic
71
72
 
72
73
  [ dirname, filename, extname ]
73
74
  end
74
-
75
- class << self
76
- # Starts the StaticMatic preview server
77
- def start(staticmatic)
78
- port = staticmatic.configuration.preview_server_port || 3000
79
-
80
- host = staticmatic.configuration.preview_server_host || ""
81
-
82
- config = Mongrel::Configurator.new :host => host do
83
- puts "Running Preview of #{staticmatic.base_dir} on #{host}:#{port}"
84
- listener :port => port do
85
- uri "/", :handler => Server.new(staticmatic)
86
- end
87
- trap("INT") { stop }
88
- run
89
- end
90
- config.join
91
- end
92
- end
93
75
  end
94
76
  end
@@ -20,7 +20,7 @@ class StaticMatic::TemplateError < StandardError
20
20
  end
21
21
 
22
22
  def source_extract(indentation = 0)
23
- return unless num = line_number
23
+ return "" unless num = line_number
24
24
  num = num.to_i
25
25
 
26
26
  source_code = @source.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staticmatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Bartholomew
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-08 00:00:00 +01:00
12
+ date: 2009-11-23 00:00:00 +00:00
13
13
  default_executable: staticmatic
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,6 +22,16 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 2.0.0
24
24
  version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "1.0"
34
+ version:
25
35
  - !ruby/object:Gem::Dependency
26
36
  name: mongrel
27
37
  type: :runtime