httpit 0.1.2 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/httpit +71 -10
- data/example/images/bird.jpg +0 -0
- data/example/index.haml +29 -0
- data/example/main.sass +24 -0
- data/example/readme.md +9 -0
- data/httpit.gemspec +6 -3
- metadata +24 -4
data/bin/httpit
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'rubygems'
|
4
4
|
require 'sinatra'
|
5
5
|
require 'haml'
|
6
|
+
require 'redcloth'
|
6
7
|
|
7
8
|
ROOT = Dir.pwd
|
8
9
|
|
@@ -10,6 +11,8 @@ set :views, ROOT
|
|
10
11
|
set :public, ROOT
|
11
12
|
set :app_file, $0
|
12
13
|
|
14
|
+
set :static, false
|
15
|
+
|
13
16
|
# only one parametr - port number
|
14
17
|
if ARGV.size > 0
|
15
18
|
set :port, ARGV.first.to_i
|
@@ -19,7 +22,7 @@ end
|
|
19
22
|
# build array of contents and theris type for specified folder
|
20
23
|
def get_content folder = nil
|
21
24
|
# building absolute path
|
22
|
-
abs_path = folder ?
|
25
|
+
abs_path = folder ? File.join(ROOT, folder) : ROOT
|
23
26
|
|
24
27
|
# build array if pairs: [filename, :type]
|
25
28
|
Dir.entries(abs_path).map do |obj|
|
@@ -37,8 +40,10 @@ end
|
|
37
40
|
|
38
41
|
# shows index.html or folder contents if index.html does not exists
|
39
42
|
get '/' do
|
40
|
-
if File.file?
|
43
|
+
if File.file?('./index.html')
|
41
44
|
File.open('./index.html') {|f| f.read }
|
45
|
+
elsif File.file?('./index.haml')
|
46
|
+
haml :index
|
42
47
|
else
|
43
48
|
@folder = ''
|
44
49
|
@files = get_content.select {|f| f[0] != '.' && f[0] != '..' }
|
@@ -46,12 +51,49 @@ get '/' do
|
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
54
|
+
get '/__img_preview' do
|
55
|
+
params[:file] = params[:file].gsub ' ', '\ '
|
56
|
+
tmppath = "/tmp/httpit_preview_#{Time.now.to_i}.jpeg"
|
57
|
+
`convert #{File.join ROOT, params[:file]} -resize 1024 -quality 100% #{tmppath}`
|
58
|
+
content_type "image/jpeg"
|
59
|
+
content = File.open(tmppath, 'rb') { |f| f.read }
|
60
|
+
File.delete(tmppath)
|
61
|
+
content
|
62
|
+
end
|
63
|
+
|
49
64
|
# shows folder contents
|
50
65
|
get %r{.+} do
|
51
|
-
return nil if request.
|
52
|
-
@
|
53
|
-
|
54
|
-
|
66
|
+
return nil if request.path == '/favicon.ico'
|
67
|
+
@path = request.path
|
68
|
+
|
69
|
+
abs_path = File.join(ROOT, @path)
|
70
|
+
|
71
|
+
# *.sass.css suport
|
72
|
+
if @path =~ /.+\.sass\.css/
|
73
|
+
content_type :css
|
74
|
+
sass @path.sub('.sass.css', '').to_sym
|
75
|
+
|
76
|
+
elsif !File.file?(abs_path) && !File.directory?(abs_path)
|
77
|
+
# shows 404 if file not found
|
78
|
+
halt 404
|
79
|
+
|
80
|
+
elsif @path =~ /.+\.md/
|
81
|
+
# render markdown template
|
82
|
+
content_type :html
|
83
|
+
content = File.open(abs_path) {|f| f.read }
|
84
|
+
return RedCloth.new(content).to_html
|
85
|
+
|
86
|
+
elsif File.file?(abs_path)
|
87
|
+
send_file(abs_path)
|
88
|
+
else
|
89
|
+
@files = get_content(@path)
|
90
|
+
haml :listing
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
error 404 do
|
95
|
+
@path = request.path
|
96
|
+
haml :not_found
|
55
97
|
end
|
56
98
|
|
57
99
|
__END__
|
@@ -68,13 +110,17 @@ __END__
|
|
68
110
|
|
69
111
|
ul, li
|
70
112
|
:list-style-type none
|
113
|
+
|
114
|
+
.preview_link
|
115
|
+
:color #55a075
|
116
|
+
:margin-left 20px
|
71
117
|
</style>
|
72
118
|
#wrap
|
73
119
|
%h1
|
74
120
|
%span Folder:
|
75
|
-
= @
|
76
|
-
- if @
|
77
|
-
%a{:href => "#{@
|
121
|
+
= @path == '' ? '/' : @path
|
122
|
+
- if @path != ''
|
123
|
+
%a{:href => "#{@path}/.."} ←
|
78
124
|
|
79
125
|
%ul
|
80
126
|
- for file in @files
|
@@ -86,4 +132,19 @@ __END__
|
|
86
132
|
- elsif file[1] == :link
|
87
133
|
%span= "→"
|
88
134
|
|
89
|
-
%a{:href => "#{@
|
135
|
+
%a{:href => "#{@path}/#{file[0]}"}= file[0]
|
136
|
+
|
137
|
+
- if %w{.jpg .jpeg .png .gif}.include?(File.extname(file[0]).downcase)
|
138
|
+
%a{:href => "/__img_preview?file=#{@path}/#{file[0]}", :class => "preview_link"} #1024
|
139
|
+
|
140
|
+
@@ not_found
|
141
|
+
<style type="text/css">
|
142
|
+
:sass
|
143
|
+
#wrap
|
144
|
+
:width 800px
|
145
|
+
:margin 50 auto
|
146
|
+
</style>
|
147
|
+
#wrap
|
148
|
+
%h1 File not found
|
149
|
+
|
150
|
+
%h3= "You requested <i>#{@path}</i>"
|
Binary file
|
data/example/index.haml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
!!! 5
|
2
|
+
%html{:lang => "en"}
|
3
|
+
%head
|
4
|
+
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/
|
5
|
+
|
6
|
+
%title HttpIt !!!
|
7
|
+
|
8
|
+
%link{ :rel => "stylesheet", :type => "text/css", :href => "/main.sass.css" }
|
9
|
+
|
10
|
+
%body
|
11
|
+
#wrap
|
12
|
+
%h1 HttpIt is awesome
|
13
|
+
|
14
|
+
%pre.code.usage
|
15
|
+
:preserve
|
16
|
+
$ sudo gem install httpit
|
17
|
+
$ cd /folder/for/server
|
18
|
+
$ httpit
|
19
|
+
# or you can set port
|
20
|
+
$ httpit <port number>
|
21
|
+
|
22
|
+
%p
|
23
|
+
%a{ :href => "/images/bird.jpg" } Static file
|
24
|
+
|
25
|
+
%p
|
26
|
+
%a{ :href => "/readme.md" } MarkDown example
|
27
|
+
|
28
|
+
%p
|
29
|
+
%a{ :href => "/images" } Gallery folder
|
data/example/main.sass
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
body
|
2
|
+
background-color: #D3E3CE
|
3
|
+
|
4
|
+
a
|
5
|
+
cursor: pointer
|
6
|
+
padding: 4px 10px
|
7
|
+
border-radius: 5px
|
8
|
+
|
9
|
+
|
10
|
+
#wrap
|
11
|
+
:width 700px
|
12
|
+
:height 500px
|
13
|
+
:margin 20px auto
|
14
|
+
:background-color #fff
|
15
|
+
:text-align center
|
16
|
+
:overflow hidden
|
17
|
+
|
18
|
+
.code
|
19
|
+
:margin 40px 100px
|
20
|
+
:text-align left
|
21
|
+
:background-color #444
|
22
|
+
:color #fff
|
23
|
+
:border-radius 5px
|
24
|
+
:padding 8px 10px
|
data/example/readme.md
ADDED
data/httpit.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "httpit"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.3.2"
|
4
4
|
s.summary = "Web server for static files"
|
5
5
|
s.description = "Just go to folder and run `httpit`"
|
6
6
|
s.author = "Pavel Evstigneev"
|
7
7
|
s.email = "pavel.evst@gmail.com"
|
8
8
|
s.homepage = "http://github.com/Paxa/httpit"
|
9
9
|
s.has_rdoc = false
|
10
|
-
s.executables
|
10
|
+
s.executables = ["httpit"]
|
11
11
|
s.rubyforge_project = "httpit"
|
12
|
-
s.files = [ "bin/httpit", "README.md", "httpit.gemspec", "lib"]
|
12
|
+
s.files = [ "bin/httpit", "README.md", "httpit.gemspec", "lib", "example", "example/index.haml", "example/main.sass", "example/readme.md", "example/images/bird.jpg"]
|
13
13
|
|
14
14
|
if s.respond_to? :specification_version then
|
15
15
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -18,13 +18,16 @@ Gem::Specification.new do |s|
|
|
18
18
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
19
19
|
s.add_runtime_dependency(%q<sinatra>, [">= 1.0"])
|
20
20
|
s.add_runtime_dependency(%q<haml>, [">= 3.0.10"])
|
21
|
+
s.add_runtime_dependency(%q<RedCloth>, [">= 4.2.3"])
|
21
22
|
|
22
23
|
else
|
23
24
|
s.add_dependency(%q<sinatra>, [">= 1.0"])
|
24
25
|
s.add_dependency(%q<haml>, [">= 3.0.10"])
|
26
|
+
s.add_dependency(%q<RedCloth>, [">= 4.2.3"])
|
25
27
|
end
|
26
28
|
else
|
27
29
|
s.add_dependency(%q<sinatra>, [">= 1.0"])
|
28
30
|
s.add_dependency(%q<haml>, [">= 3.0.10"])
|
31
|
+
s.add_dependency(%q<RedCloth>, [">= 4.2.3"])
|
29
32
|
end
|
30
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 2
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pavel Evstigneev
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-12 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -49,6 +49,22 @@ dependencies:
|
|
49
49
|
version: 3.0.10
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: RedCloth
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 49
|
61
|
+
segments:
|
62
|
+
- 4
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
version: 4.2.3
|
66
|
+
type: :runtime
|
67
|
+
version_requirements: *id003
|
52
68
|
description: Just go to folder and run `httpit`
|
53
69
|
email: pavel.evst@gmail.com
|
54
70
|
executables:
|
@@ -61,6 +77,10 @@ files:
|
|
61
77
|
- bin/httpit
|
62
78
|
- README.md
|
63
79
|
- httpit.gemspec
|
80
|
+
- example/index.haml
|
81
|
+
- example/main.sass
|
82
|
+
- example/readme.md
|
83
|
+
- example/images/bird.jpg
|
64
84
|
has_rdoc: true
|
65
85
|
homepage: http://github.com/Paxa/httpit
|
66
86
|
licenses: []
|