httpit 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 98c43fc1129be5731066b38bb0fe2f30dd0b1a67
4
+ data.tar.gz: fc6cf57c5eec0b74e4e294900fcaa31ad23adfe6
5
+ SHA512:
6
+ metadata.gz: 75a9b1f86921ca2dce0394b4b3990e51541c42659de70ad5cffcf664d6e20c0cae9c51451d5de754b6d15dfa675156d17f77f6c1e5a641af6a7174748753bc57
7
+ data.tar.gz: 0040ad430f5f5adf7d331326c35031014e1dcfefb888df53cf9c51f1903941063c269a7824832cc14fed1e8af388bd57aa6c635a5f5a0bac39385d6a80e89007
data/README.md CHANGED
@@ -12,6 +12,8 @@ httpit
12
12
  httpit 9081
13
13
  ```
14
14
 
15
+ ![screen shot 2013-12-25 at 10 39 44 am](https://f.cloud.github.com/assets/26019/1807805/598cf174-6d16-11e3-9553-494ff5a8f337.png)
16
+
15
17
  ## Features
16
18
 
17
19
  * Haml support
data/bin/httpit CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require "rubygems"
3
4
 
4
5
  require "fileutils"
5
6
  require "pathname"
7
+ require 'shellwords'
6
8
 
7
9
  GEM_ROOT = Pathname.new(__FILE__).dirname.join("..").expand_path
8
10
  ENV['BUNDLE_GEMFILE'] ||= GEM_ROOT.join("Gemfile").to_s
@@ -11,6 +13,7 @@ require "bundler/setup"
11
13
  require 'sinatra/base'
12
14
  require 'haml'
13
15
  require 'sass'
16
+ require 'sass/plugin'
14
17
  require 'redcloth'
15
18
 
16
19
  ROOT = Pathname.pwd
@@ -18,6 +21,13 @@ ROOT = Pathname.pwd
18
21
  TMP_DIR = File.expand_path("#{Dir.tmpdir}/#{Time.now.to_i}#{rand(1000)}/")
19
22
  FileUtils.mkdir_p(TMP_DIR)
20
23
 
24
+ class Tilt::SassTemplate
25
+ alias_method :sass_options_original, :sass_options
26
+ def sass_options
27
+ sass_options_original.merge(:cache_location => File.join(TMP_DIR, 'sass-cache'))
28
+ end
29
+ end
30
+
21
31
  # this hack allow
22
32
  # /some/folder/with/content + /subfolder => /some/folder/with/content/subfolder
23
33
  class << ROOT
@@ -40,7 +50,7 @@ class HttpIt < Sinatra::Base
40
50
  set :public_folder, ROOT
41
51
  set :app_file, $0
42
52
  set :static, false
43
- set :sass, :cache => true, :cache_location => File.join(TMP_DIR, 'sass-cache')
53
+ set :sass, :cache => false, :cache_location => File.join(TMP_DIR, 'sass-cache')
44
54
 
45
55
  helpers do
46
56
  def with_layout(template, &block)
@@ -52,12 +62,18 @@ class HttpIt < Sinatra::Base
52
62
  end
53
63
  end
54
64
 
55
- def file_url(path, file)
65
+ def file_url(path, file, type = nil)
56
66
  path = "#{path}/#{file}"
57
- path.split("/").map {|p| CGI::escape(p) }.join('/')
67
+ path.split("/").map {|p| CGI::escape(p) }.join('/') + (type == :dir ? '/' : '')
58
68
  end
59
69
  end
60
70
 
71
+ def list_files(path, sorter)
72
+ cmd = %{cd "#{path.to_s.shellescape}" && ls -A #{sorter}}
73
+ result = `#{cmd}`.force_encoding(Encoding::UTF_8)
74
+ result.split("\n")
75
+ end
76
+
61
77
  # build array of contents and theris type for specified folder
62
78
  def get_content(folder = nil, sort = nil)
63
79
  abs_path = folder ? ROOT + folder : ROOT
@@ -71,15 +87,15 @@ class HttpIt < Sinatra::Base
71
87
  else ''
72
88
  end
73
89
 
74
- `cd "#{abs_path.to_s.gsub(?", '\"')}" && ls -A #{sorter}`.split("\n").map do |obj|
90
+ list_files(abs_path, sorter).map do |obj|
75
91
  file_path = abs_path + obj
76
92
  [obj,
77
93
  if file_path.file?; :file
78
94
  elsif file_path.directory?; :dir
79
95
  elsif file_path.symlink?; :link
80
96
  end,
81
-
82
- !!`file "#{file_path.to_s.gsub(?", '\"')}"`.sub(file_path.to_s, '').index(/text/i)
97
+
98
+ !!`file "#{file_path.to_s.shellescape}"`.force_encoding(Encoding::UTF_8).sub(file_path.to_s, '').index(/text/i)
83
99
  ]
84
100
  end
85
101
  end
@@ -110,7 +126,7 @@ class HttpIt < Sinatra::Base
110
126
  end
111
127
 
112
128
  get '/__img_preview' do
113
- params[:file] = params[:file].gsub(' ', '\ ')
129
+ params[:file] = params[:file].shellescape
114
130
  tmppath = "/tmp/httpit_preview_#{Time.now.to_i}.jpeg"
115
131
  `convert #{ROOT + params[:file]} -resize 1024 -quality 100% #{tmppath}`
116
132
  content_type "image/jpeg"
@@ -119,6 +135,20 @@ class HttpIt < Sinatra::Base
119
135
  content
120
136
  end
121
137
 
138
+ get '/__view' do
139
+ params[:file] = params[:file].shellescape.sub(/^.\//, '/')
140
+ begin
141
+ @content = File.open(ROOT + params[:file], 'r:utf-8', &:read)
142
+ haml view(:view)
143
+ rescue Errno::ENOENT => e
144
+ if e.message =~ /No such file or directory/
145
+ halt 404
146
+ else
147
+ raise e
148
+ end
149
+ end
150
+ end
151
+
122
152
  # shows folder contents
123
153
  get %r{.+} do
124
154
  return nil if request.path == '/favicon.ico'
@@ -160,7 +190,7 @@ class HttpIt < Sinatra::Base
160
190
  end
161
191
 
162
192
  error 404 do
163
- @path = request.path
193
+ @path = params[:file] || request.path
164
194
  haml view(:not_found)
165
195
  end
166
196
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "httpit"
3
- s.version = "0.4.6"
3
+ s.version = "0.4.7"
4
4
  s.summary = "Web server for static files"
5
5
  s.description = "Just go to folder and run `httpit` to make it avaliable as web-server"
6
6
  s.author = "Pavel Evstigneev"
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.has_rdoc = false
10
10
  s.executables = ["httpit"]
11
11
  s.rubyforge_project = "httpit"
12
- s.files = `git ls-files`.split("\n")
12
+ s.files = File.read(__FILE__).match(/__#{'END'}__(.+)\z/m)[1].strip.split("\n")
13
13
  s.licenses = ['MIT', 'GPL-2']
14
14
 
15
15
  s.add_runtime_dependency 'sinatra', "~> 1.4.2"
@@ -17,3 +17,24 @@ Gem::Specification.new do |s|
17
17
  s.add_runtime_dependency 'RedCloth', "~> 4.2.9"
18
18
  s.add_runtime_dependency 'sass', "~> 3.2.8"
19
19
  end
20
+
21
+ # git ls-files
22
+ __END__
23
+ .gitignore
24
+ Gemfile
25
+ Gemfile.lock
26
+ LICENSE
27
+ README.md
28
+ bin/httpit
29
+ example/images/bird.jpg
30
+ example/index.haml
31
+ example/main.sass
32
+ example/readme.md
33
+ example/testing_design/_header.haml
34
+ example/testing_design/index.haml
35
+ example/testing_design/layout.sass
36
+ httpit.gemspec
37
+ views/listing.haml
38
+ views/not_found.haml
39
+ views/utils.js
40
+ views/view.haml
@@ -7,6 +7,11 @@
7
7
  :width 800px
8
8
  :margin 30 auto 50px
9
9
 
10
+ a
11
+ :color #1777E0
12
+ &:hover
13
+ :color #006db2
14
+
10
15
  span
11
16
  :color #777
12
17
 
@@ -52,11 +57,11 @@
52
57
  - elsif file[1] == :link
53
58
  %span= "&rarr;"
54
59
 
55
- %a{:href => file_url(@path, file[0])}= file[0]
60
+ %a{:href => file_url(@path, file[0], file[1])}= file[0]
56
61
 
57
62
  - if %w{.jpg .jpeg .png .gif}.include?(File.extname(file[0]).downcase)
58
63
  %a{:href => "/__img_preview?file=#{file_url(@path, file[0])}", :class => "preview_link"} #1024
59
64
  - if file[2]
60
- %a{:href => "/__view?file=#{file_url(@path, file[0])}", :class => "preview_link"} view
65
+ %a{:href => "/__view?file=.#{file_url(@path, file[0])}", :class => "preview_link"} view
61
66
 
62
67
  %script{:type => "text/javascript"}= GEM_ROOT.join('views/utils.js').read
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
5
- prerelease:
4
+ version: 0.4.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pavel Evstigneev
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-12-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: sinatra
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: haml
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: RedCloth
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: sass
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ~>
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ~>
76
67
  - !ruby/object:Gem::Version
@@ -104,26 +95,26 @@ homepage: http://github.com/Paxa/httpit
104
95
  licenses:
105
96
  - MIT
106
97
  - GPL-2
98
+ metadata: {}
107
99
  post_install_message:
108
100
  rdoc_options: []
109
101
  require_paths:
110
102
  - lib
111
103
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
- - - ! '>='
105
+ - - '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
109
  requirements:
120
- - - ! '>='
110
+ - - '>='
121
111
  - !ruby/object:Gem::Version
122
112
  version: '0'
123
113
  requirements: []
124
114
  rubyforge_project: httpit
125
- rubygems_version: 1.8.25
115
+ rubygems_version: 2.0.6
126
116
  signing_key:
127
- specification_version: 3
117
+ specification_version: 4
128
118
  summary: Web server for static files
129
119
  test_files: []
120
+ has_rdoc: false