annyong 0.1.2 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.mkd +1 -1
- data/assets/css/annyong.css +6 -0
- data/assets/rack/config.ru +1 -2
- data/lib/annyong.rb +2 -2
- data/lib/annyong/directory.rb +35 -0
- metadata +4 -5
- data/lib/annyong/middleware.rb +0 -31
data/README.mkd
CHANGED
@@ -17,4 +17,4 @@ Annyong starts a public static Web server in the current directory, allowing peo
|
|
17
17
|
|
18
18
|
## Thanks
|
19
19
|
|
20
|
-
* Doug McInnes (to prevent injecting annyong’s code into public HTML files)
|
20
|
+
* [Doug McInnes](https://github.com/dmcinnes) (to prevent injecting annyong’s code into public HTML files)
|
data/assets/css/annyong.css
CHANGED
data/assets/rack/config.ru
CHANGED
data/lib/annyong.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Annyong
|
2
|
+
class Directory < Rack::Directory
|
3
|
+
DIR_FILE = "<tr><td class='name'><a href='%s'>%s</a></td><td class='size'>%s</td><td class='type'>%s</td><td class='mtime'>%s</td></tr>"
|
4
|
+
DIR_PAGE = <<-PAGE
|
5
|
+
<!doctype html>
|
6
|
+
<html><head>
|
7
|
+
<title>%s</title>
|
8
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
9
|
+
<style type="text/css">
|
10
|
+
#{File.read(File.join(File.dirname(__FILE__), "../../assets/css/annyong.css")).gsub(/%/, "%%")}
|
11
|
+
</style>
|
12
|
+
</head><body>
|
13
|
+
<h1>%s</h1>
|
14
|
+
<table>
|
15
|
+
<tr>
|
16
|
+
<th class='name'>Name</th>
|
17
|
+
<th class='size'>Size</th>
|
18
|
+
<th class='type'>Type</th>
|
19
|
+
<th class='mtime'>Last Modified</th>
|
20
|
+
</tr>
|
21
|
+
%s
|
22
|
+
</table>
|
23
|
+
<footer><code>#{`pwd`.chomp}</code>, <a target='_blank' title='Powered by annyong' href='https://github.com/remiprev/annyong'>annyong</a>!</footer></body
|
24
|
+
</body></html>
|
25
|
+
PAGE
|
26
|
+
|
27
|
+
def each
|
28
|
+
show_path = @path.sub(/^#{@root}/,'')
|
29
|
+
files = @files.map{|f| DIR_FILE % f }*"\n"
|
30
|
+
page = DIR_PAGE % [ show_path, show_path , files ]
|
31
|
+
page.each_line{|l| yield l }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: annyong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
version: 0.
|
9
|
+
version: "0.2"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- "R\xC3\xA9mi Pr\xC3\xA9vost"
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-06 00:00:00 -04:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +42,7 @@ extensions: []
|
|
43
42
|
extra_rdoc_files: []
|
44
43
|
|
45
44
|
files:
|
46
|
-
- lib/annyong/
|
45
|
+
- lib/annyong/directory.rb
|
47
46
|
- lib/annyong.rb
|
48
47
|
- README.mkd
|
49
48
|
- LICENSE
|
data/lib/annyong/middleware.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Annyong
|
2
|
-
class Middleware
|
3
|
-
|
4
|
-
attr_reader :styles
|
5
|
-
|
6
|
-
def initialize(app) # {{{
|
7
|
-
@app = app
|
8
|
-
@styles = File.read(File.join(File.dirname(__FILE__), "../../assets/css/annyong.css"))
|
9
|
-
end # }}}
|
10
|
-
|
11
|
-
def inject(body) # {{{
|
12
|
-
body = body.sub(/<html>/, "<!doctype html>\n<html>")
|
13
|
-
body = body.sub(/<\/head>/, "<style type='text/css'>#{@styles}</style>")
|
14
|
-
body = body.sub(/<\/body>/, "<footer><code>#{`pwd`.chomp}</code>, <a target='_blank' title='Powered by annyong' href='https://github.com/remiprev/annyong'>annyong</a>!</footer></body")
|
15
|
-
body
|
16
|
-
end # }}}
|
17
|
-
|
18
|
-
def call(env) # {{{
|
19
|
-
status, headers, response = @app.call(env)
|
20
|
-
|
21
|
-
response_body = ""
|
22
|
-
response.each { |part| response_body += part }
|
23
|
-
response_body = inject(response_body) unless env['REQUEST_URI'] =~ /\.html?$/
|
24
|
-
|
25
|
-
headers["Content-Length"] = response_body.length.to_s
|
26
|
-
|
27
|
-
[status, headers, response_body]
|
28
|
-
end # }}}
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|