httpit 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +11 -0
  2. data/bin/httpit +88 -0
  3. data/httpit.gemspec +30 -0
  4. metadata +98 -0
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Make static web server from any folder
2
+
3
+ Build on sinatra, useful for developing JS applications and doing "psd => xhtml" works
4
+
5
+ ## Usage
6
+
7
+ $ sudo gem install httpit
8
+ $ cd /folder/for/server
9
+ $ httpit
10
+ # or you can set port
11
+ $ httpit <port number>
data/bin/httpit ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'sinatra'
5
+ require 'haml'
6
+
7
+ ROOT = Dir.pwd
8
+
9
+ set :views, ROOT
10
+ set :public, ROOT
11
+
12
+ # only one parametr - port number
13
+ if ARGV.size > 0
14
+ set :port, ARGV.first.to_i
15
+ end
16
+
17
+
18
+ # build array of contents and theris type for specified folder
19
+ def get_content folder = nil
20
+ # building absolute path
21
+ abs_path = folder ? (File.join ROOT, folder) : ROOT
22
+
23
+ # build array if pairs: [filename, :type]
24
+ Dir.entries(abs_path).map do |obj|
25
+ [obj,
26
+ if File.file? File.join(abs_path, obj)
27
+ :file
28
+ elsif File.directory? File.join(abs_path, obj)
29
+ :dir
30
+ elsif File.symlink? File.join(abs_path, obj)
31
+ :link
32
+ end
33
+ ]
34
+ end
35
+ end
36
+
37
+ # shows index.html or folder contents if index.html does not exists
38
+ get '/' do
39
+ if File.file? './index.html'
40
+ File.open('./index.html') {|f| f.read }
41
+ else
42
+ @folder = ''
43
+ @files = get_content.select {|f| f[0] != '.' && f[0] != '..' }
44
+ haml :listing
45
+ end
46
+ end
47
+
48
+ # shows folder contents
49
+ get %r{.+} do
50
+ return nil if request.env['PATH_INFO'] == '/favicon.ico'
51
+ @folder = request.env['PATH_INFO']
52
+ @files = get_content(@folder)
53
+ haml :listing
54
+ end
55
+
56
+ __END__
57
+
58
+ @@ listing
59
+ <style type="text/css">
60
+ :sass
61
+ #wrap
62
+ :width 800px
63
+ :margin 50 auto
64
+
65
+ span
66
+ :color #777
67
+
68
+ ul, li
69
+ :list-style-type none
70
+ </style>
71
+ #wrap
72
+ %h1
73
+ %span Folder:
74
+ = @folder == '' ? '/' : @folder
75
+ - if @folder != ''
76
+ %a{:href => "#{@folder}/.."} &larr;
77
+
78
+ %ul
79
+ - for file in @files
80
+ %li
81
+ - if file[1] == :file
82
+ %span= "&ndash;"
83
+ - elsif file[1] == :dir
84
+ %span= "+"
85
+ - elsif file[1] == :link
86
+ %span= "&rarr;"
87
+
88
+ %a{:href => "#{@folder}/#{file[0]}"}= file[0]
data/httpit.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "httpit"
3
+ s.version = "0.1"
4
+ s.summary = "Web server for static files"
5
+ s.description = "Just go to folder and run `httpit`"
6
+ s.author = "Pavel Evstigneev"
7
+ s.email = "pavel.evst@gmail.com"
8
+ s.homepage = "http://github.com/Paxa/httpit"
9
+ s.has_rdoc = false
10
+ s.executables = ["httpit"]
11
+ s.rubyforge_project = "httpit"
12
+ s.files = [ "bin/httpit", "README.md", "httpit.gemspec", "lib"]
13
+
14
+ if s.respond_to? :specification_version then
15
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
16
+ s.specification_version = 3
17
+
18
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
19
+ s.add_runtime_dependency(%q<sinatra>, [">= 1.0"])
20
+ s.add_runtime_dependency(%q<haml>, [">= 3.0.10"])
21
+
22
+ else
23
+ s.add_dependency(%q<sinatra>, [">= 1.0"])
24
+ s.add_dependency(%q<haml>, [">= 3.0.10"])
25
+ end
26
+ else
27
+ s.add_dependency(%q<sinatra>, [">= 1.0"])
28
+ s.add_dependency(%q<haml>, [">= 3.0.10"])
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httpit
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Pavel Evstigneev
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-18 00:00:00 +04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: haml
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 19
44
+ segments:
45
+ - 3
46
+ - 0
47
+ - 10
48
+ version: 3.0.10
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: Just go to folder and run `httpit`
52
+ email: pavel.evst@gmail.com
53
+ executables:
54
+ - httpit
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - bin/httpit
61
+ - README.md
62
+ - httpit.gemspec
63
+ has_rdoc: true
64
+ homepage: http://github.com/Paxa/httpit
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project: httpit
93
+ rubygems_version: 1.3.7
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Web server for static files
97
+ test_files: []
98
+