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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d7834ecbce603f220c558fdda4f3893c2b9fbba5
4
- data.tar.gz: e878fa6563792ec3ea74547bea2a9627af63c496
3
+ metadata.gz: 3ceb2c67d46e93fb54834d25cf1e4faba3cb3bb1
4
+ data.tar.gz: 2c02f31626be0e0fca914a030a07316d6aafc23a
5
5
  SHA512:
6
- metadata.gz: ad705addb8b763d24cc8294f3550161eefa54708bf2787913bfd1fc63209a8388d608f0110113907c881b4cdf1346c39e56c1d4d5190553fd7529302549c01c7
7
- data.tar.gz: abef92b7e0a9836715a8b0286afb4464303d92f4f9221a86ae67999d5c26b804c1780746f024b28c7b44e2b475ed8ebd1eca99bd3b65de2f091e9361d5a8c7ff
6
+ metadata.gz: 818f4124e1601f6364c6f31172b17ed7b08c2aa83a685d5cfbec5a20c9bb10ca6322bdedcceb37770b9fdd4e12d4c2a048688c393d6246907ec25b817bfe1497
7
+ data.tar.gz: 225992a148f120eee14e60a08ebafe331d49920b924696ec789ad06395e79c6da8559eecb52f06f122b7c1af760b438acd9dcafc0e57f60589cbd87ef5791431
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ ## The TO-DO list
2
+
3
+ * Add minify capability on production environment
4
+ * Add config file
5
+ * Add virtual hosting
6
+ * Add php proxying, and rails as well
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 + 'res'
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
- if size > Math.ldexp(1, 40)
15
- sprintf("%5.2f", size / Math.ldexp(1, 40)) + ' GB'
16
- elsif (size / Math.ldexp(1, 20)) > 0.1
17
- sprintf("%5.2f", size / Math.ldexp(1, 20)).to_s + ' MB'
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 + ' kB'
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 BASEDIR + 'res/bootstrap.min.css'
43
+ send_file(File.join(BASEDIR, 'res/bootstrap.min.css'))
27
44
  end
45
+
28
46
  get '/.res/style.css' do
29
- send_file BASEDIR + 'res/style.css'
47
+ send_file(File.join(BASEDIR, 'res/style.css'))
30
48
  end
49
+
31
50
  get '/.res/jquery.min.js' do
32
- send_file BASEDIR + 'res/jquery.min.js'
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 BASEDIR + 'res/glyphicons-halflings-regular.woff'
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 BASEDIR + 'res/glyphicons-halflings-regular.ttf'
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 BASEDIR + 'res/glyphicons-halflings-regular.svg'
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 + unescape(request.path_info))
68
+ path = File.expand_path(File.join(Dir.pwd, unescape(request.path_info)))
69
+
46
70
  if File.file? path
47
- send_file path
48
- elsif File.exists? File.expand_path(path + '/index.html')
49
- redirect request.path_info + '/index.html'
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 request.path_info
78
+ @parent = File.dirname(request.path_info)
79
+
54
80
  Dir.foreach(path) do |entry|
55
- next if entry == '.' or entry == '..'
56
- url_base = ""
57
- url_base = request.path_info unless request.path_info == '/'
58
- if File.directory? File.expand_path(path + '/' + entry)
59
- @folders << {name: entry, href: url_base + '/' + entry}
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
- size: dynamic_size(File.size(File.expand_path(path + '/' + entry))),
63
- href: url_base + '/' + entry}
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'
@@ -1,3 +1,3 @@
1
1
  module Hstatic
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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 development)') { |val| set :environment, val.to_sym }
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
- arr1 = $.grep($('a.list-group-item'), function(e, i){
62
- return ! re.test(e.innerHTML);
59
+ $.each($('a.list-group-item'), function(i, e){
60
+ if (! re.test(e.innerHTML)) {
61
+ $(e).hide();
62
+ }
63
63
  });
64
- arr2 = $.grep($('tr:has(a)'), function(e, i){
65
- return ! re.test($('a', e).html());
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.1
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-16 00:00:00.000000000 Z
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
-