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 +1 -0
- data/VERSION.yml +1 -1
- data/lib/staticmatic.rb +2 -1
- data/lib/staticmatic/server.rb +39 -57
- data/lib/staticmatic/template_error.rb +1 -1
- metadata +12 -2
data/Rakefile
CHANGED
data/VERSION.yml
CHANGED
data/lib/staticmatic.rb
CHANGED
data/lib/staticmatic/server.rb
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
module StaticMatic
|
2
|
-
class Server
|
3
|
-
|
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
|
7
|
+
|
8
|
+
def call(env)
|
11
9
|
@staticmatic.load_helpers
|
12
|
-
path_info =
|
13
|
-
|
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
|
-
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
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.
|
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-
|
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
|