hstatic 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/TODO +6 -0
- data/lib/hstatic/app.rb +57 -26
- data/lib/hstatic/version.rb +1 -1
- data/lib/hstatic.rb +1 -1
- data/views/index.haml +10 -12
- metadata +3 -3
- data/res/index.haml +0 -80
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ceb2c67d46e93fb54834d25cf1e4faba3cb3bb1
|
4
|
+
data.tar.gz: 2c02f31626be0e0fca914a030a07316d6aafc23a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 818f4124e1601f6364c6f31172b17ed7b08c2aa83a685d5cfbec5a20c9bb10ca6322bdedcceb37770b9fdd4e12d4c2a048688c393d6246907ec25b817bfe1497
|
7
|
+
data.tar.gz: 225992a148f120eee14e60a08ebafe331d49920b924696ec789ad06395e79c6da8559eecb52f06f122b7c1af760b438acd9dcafc0e57f60589cbd87ef5791431
|
data/TODO
ADDED
data/lib/hstatic/app.rb
CHANGED
@@ -2,67 +2,98 @@ require 'sinatra/base'
|
|
2
2
|
require 'haml'
|
3
3
|
|
4
4
|
module Hstatic
|
5
|
-
BASEDIR = File.dirname(__FILE__)
|
5
|
+
BASEDIR = File.join(File.dirname(__FILE__), '..', '..')
|
6
6
|
|
7
7
|
class App < Sinatra::Base
|
8
8
|
configure do
|
9
|
-
set :views, BASEDIR
|
9
|
+
set :views, File.join(BASEDIR, 'views')
|
10
|
+
set :environment, :production
|
10
11
|
end
|
11
12
|
|
12
13
|
helpers do
|
13
14
|
def dynamic_size(size)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
case
|
16
|
+
when size > Math.ldexp(1, 40)
|
17
|
+
sprintf("%5.2f", size / Math.ldexp(1, 40)) << ' GB'
|
18
|
+
when (size / Math.ldexp(1, 20)) > 0.1
|
19
|
+
sprintf("%5.2f", size / Math.ldexp(1, 20)).to_s << ' MB'
|
18
20
|
else
|
19
|
-
sprintf("%5.2f", size / Math.ldexp(1, 10)).to_s
|
21
|
+
sprintf("%5.2f", size / Math.ldexp(1, 10)).to_s << ' kB'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# For now just render [:haml, :erb]
|
27
|
+
helpers do
|
28
|
+
def render_file(path)
|
29
|
+
case File.extname(path)
|
30
|
+
when /haml$|erb$/
|
31
|
+
method = self.method(Regexp.last_match(0))
|
32
|
+
basename = File.basename(path, File.extname(path)).to_sym
|
33
|
+
|
34
|
+
method.call(basename, { :views => File.dirname(path) })
|
35
|
+
else
|
36
|
+
send_file path
|
20
37
|
end
|
21
38
|
end
|
22
39
|
end
|
23
40
|
|
24
41
|
# Going around bootstrap
|
25
42
|
get '/.res/bootstrap.min.css' do
|
26
|
-
send_file
|
43
|
+
send_file(File.join(BASEDIR, 'res/bootstrap.min.css'))
|
27
44
|
end
|
45
|
+
|
28
46
|
get '/.res/style.css' do
|
29
|
-
send_file
|
47
|
+
send_file(File.join(BASEDIR, 'res/style.css'))
|
30
48
|
end
|
49
|
+
|
31
50
|
get '/.res/jquery.min.js' do
|
32
|
-
send_file
|
51
|
+
send_file(File.join(BASEDIR, 'res/jquery.min.js'))
|
33
52
|
end
|
53
|
+
|
34
54
|
get '/fonts/glyphicons-halflings-regular.woff' do
|
35
|
-
send_file
|
55
|
+
send_file(File.join(BASEDIR, 'res/glyphicons-halflings-regular.woff'))
|
36
56
|
end
|
57
|
+
|
37
58
|
get '/fonts/glyphicons-halflings-regular.ttf' do
|
38
|
-
send_file
|
59
|
+
send_file(File.join(BASEDIR, 'res/glyphicons-halflings-regular.ttf'))
|
39
60
|
end
|
61
|
+
|
40
62
|
get '/fonts/glyphicons-halflings-regular.svg' do
|
41
|
-
send_file
|
63
|
+
send_file(File.join(BASEDIR, 'res/glyphicons-halflings-regular.svg'))
|
42
64
|
end
|
43
65
|
|
66
|
+
# Catch all route
|
44
67
|
get '*' do
|
45
|
-
path = File.expand_path(Dir.pwd
|
68
|
+
path = File.expand_path(File.join(Dir.pwd, unescape(request.path_info)))
|
69
|
+
|
46
70
|
if File.file? path
|
47
|
-
|
48
|
-
elsif File.exists?
|
49
|
-
redirect
|
71
|
+
render_file path
|
72
|
+
elsif File.exists?(File.expand_path(File.join(path, 'index.html')))
|
73
|
+
redirect(File.join(request.path_info, 'index.html'))
|
50
74
|
elsif File.directory? path
|
75
|
+
# Building data
|
51
76
|
@folders = Array.new
|
52
77
|
@files = Array.new
|
53
|
-
@parent = File.dirname
|
78
|
+
@parent = File.dirname(request.path_info)
|
79
|
+
|
54
80
|
Dir.foreach(path) do |entry|
|
55
|
-
next if entry ==
|
56
|
-
|
57
|
-
url_base =
|
58
|
-
|
59
|
-
|
81
|
+
next if entry == "." || entry == ".."
|
82
|
+
|
83
|
+
url_base = File.join("/", request.path_info)
|
84
|
+
link = File.join(url_base, entry)
|
85
|
+
filename = File.expand_path(File.join(path, entry))
|
86
|
+
|
87
|
+
if File.directory? filename
|
88
|
+
@folders << { name: entry, href: link }
|
60
89
|
else
|
61
|
-
@files << {name: unescape(entry),
|
62
|
-
|
63
|
-
|
90
|
+
@files << { name: unescape(entry),
|
91
|
+
size: dynamic_size(File.size(filename)),
|
92
|
+
href: link }
|
64
93
|
end
|
65
94
|
end
|
95
|
+
|
96
|
+
# Render view
|
66
97
|
haml :index
|
67
98
|
else
|
68
99
|
'not found'
|
data/lib/hstatic/version.rb
CHANGED
data/lib/hstatic.rb
CHANGED
@@ -8,7 +8,7 @@ module Hstatic
|
|
8
8
|
require 'optparse'
|
9
9
|
OptionParser.new { |op|
|
10
10
|
op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
|
11
|
-
op.on('-e env', 'set the environment (default is
|
11
|
+
op.on('-e env', 'set the environment (default is production)') { |val| set :environment, val.to_sym }
|
12
12
|
op.on('-s server', 'specify rack server/handler (default is thin)') { |val| set :server, val }
|
13
13
|
op.on('-x', 'turn on the mutex lock (default is off)') { set :lock, true }
|
14
14
|
}.parse!(ARGV.dup)
|
data/views/index.haml
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
%div.container-fluid
|
14
14
|
%div.row
|
15
15
|
%div.col-md-4.col-md-offset-4
|
16
|
-
%input.form-control(type="text" placeholder="Search")
|
16
|
+
%input.form-control(type="text" placeholder="Search" autofocus)
|
17
17
|
%div.row
|
18
18
|
%div.col-lg-3.col-md-3.col-sm-3
|
19
19
|
%div.panel.panel-default
|
@@ -47,27 +47,25 @@
|
|
47
47
|
|
48
48
|
:javascript
|
49
49
|
$(document).ready(function () {
|
50
|
-
$('input').focus();
|
51
50
|
var re = new RegExp;
|
52
51
|
/* filtering */
|
53
52
|
$('input').on('input', function () {
|
54
53
|
value = $(this).val();
|
55
|
-
$('a.list-group-item').show();
|
56
|
-
$('tr:has(a)').show();
|
54
|
+
$('a.list-group-item, tr:has(a)').show();
|
57
55
|
if (value == "") {
|
58
56
|
return false;
|
59
57
|
}
|
60
58
|
re.compile(value, "i");
|
61
|
-
|
62
|
-
|
59
|
+
$.each($('a.list-group-item'), function(i, e){
|
60
|
+
if (! re.test(e.innerHTML)) {
|
61
|
+
$(e).hide();
|
62
|
+
}
|
63
63
|
});
|
64
|
-
|
65
|
-
|
64
|
+
$.each($('tr:has(a)'), function(i, e){
|
65
|
+
if (! re.test($('a', e).html())) {
|
66
|
+
$(e).hide();
|
67
|
+
}
|
66
68
|
});
|
67
|
-
arr = arr1.concat(arr2);
|
68
|
-
for (i in arr) {
|
69
|
-
$(arr[i]).hide();
|
70
|
-
}
|
71
69
|
});
|
72
70
|
$('input').on('keyup', function (event) {
|
73
71
|
if (event.which == 27) {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hstatic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erick Pérez Castellanos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
|
+
- TODO
|
85
86
|
- bin/hstatic
|
86
87
|
- hstatic.gemspec
|
87
88
|
- lib/hstatic.rb
|
@@ -92,7 +93,6 @@ files:
|
|
92
93
|
- res/glyphicons-halflings-regular.svg
|
93
94
|
- res/glyphicons-halflings-regular.ttf
|
94
95
|
- res/glyphicons-halflings-regular.woff
|
95
|
-
- res/index.haml
|
96
96
|
- res/jquery.min.js
|
97
97
|
- res/style.css
|
98
98
|
- views/index.haml
|
data/res/index.haml
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
-# UTF-8:
|
2
|
-
|
3
|
-
!!! 5
|
4
|
-
%html
|
5
|
-
%head
|
6
|
-
%meta(name="viewport" content="width=device-width, initial-scale=1.0")
|
7
|
-
|
8
|
-
/ Bootstrap
|
9
|
-
%link(href="/.res/bootstrap.min.css" rel="stylesheet")
|
10
|
-
%link(href="/.res/style.css" rel="stylesheet")
|
11
|
-
%script(src="/.res/jquery.min.js" type="text/javascript")
|
12
|
-
%body
|
13
|
-
%div.container-fluid
|
14
|
-
%div.row
|
15
|
-
%div.col-md-4.col-md-offset-4
|
16
|
-
%input.form-control(type="text" placeholder="Search")
|
17
|
-
%div.row
|
18
|
-
%div.col-lg-3.col-md-3.col-sm-3
|
19
|
-
%div.panel.panel-default
|
20
|
-
%div.panel-heading
|
21
|
-
Folders
|
22
|
-
%a.pull-right(href="#{@parent}")
|
23
|
-
%span.glyphicon.glyphicon-arrow-up
|
24
|
-
Up
|
25
|
-
%div.list-group
|
26
|
-
- @folders.each do |folder|
|
27
|
-
%a.list-group-item(href="#{folder[:href]}") #{folder[:name]}
|
28
|
-
|
29
|
-
%div.col-lg-9.col-md-9.col-sm-9
|
30
|
-
%div.panel.panel-default
|
31
|
-
%div.panel-heading Files
|
32
|
-
%table.table.table-hover
|
33
|
-
%thead
|
34
|
-
%tr
|
35
|
-
%th #
|
36
|
-
%th Name
|
37
|
-
%th Size
|
38
|
-
%tbody
|
39
|
-
- i = 1
|
40
|
-
- @files.each do |file|
|
41
|
-
%tr
|
42
|
-
%td= i
|
43
|
-
%td
|
44
|
-
%a(href="#{file[:href]}") #{file[:name]}
|
45
|
-
%td= file[:size]
|
46
|
-
- i += 1
|
47
|
-
|
48
|
-
:javascript
|
49
|
-
$(document).ready(function () {
|
50
|
-
$('input').focus();
|
51
|
-
var re = new RegExp;
|
52
|
-
/* filtering */
|
53
|
-
$('input').on('input', function () {
|
54
|
-
value = $(this).val();
|
55
|
-
$('a.list-group-item').show();
|
56
|
-
$('tr:has(a)').show();
|
57
|
-
if (value == "") {
|
58
|
-
return false;
|
59
|
-
}
|
60
|
-
re.compile(value, "i");
|
61
|
-
arr1 = $.grep($('a.list-group-item'), function(e, i){
|
62
|
-
return ! re.test(e.innerHTML);
|
63
|
-
});
|
64
|
-
arr2 = $.grep($('tr:has(a)'), function(e, i){
|
65
|
-
return ! re.test($('a', e).html());
|
66
|
-
});
|
67
|
-
arr = arr1.concat(arr2);
|
68
|
-
for (i in arr) {
|
69
|
-
$(arr[i]).hide();
|
70
|
-
}
|
71
|
-
});
|
72
|
-
$('input').on('keyup', function (event) {
|
73
|
-
if (event.which == 27) {
|
74
|
-
$('input').val("");
|
75
|
-
$('input').trigger('input');
|
76
|
-
}
|
77
|
-
});
|
78
|
-
});
|
79
|
-
|
80
|
-
|