hstatic 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hstatic +1 -1
- data/lib/hstatic/app.rb +20 -17
- data/lib/hstatic/version.rb +2 -1
- data/lib/hstatic.rb +26 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87fb753e036fc90718781e2343ef78d7b043b89
|
4
|
+
data.tar.gz: 6e04b8a734f59391e3326ddd1ee9dc72bdbf0008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0eeeaa9c35cda041f39a29fd07a0efdf1473370ab3970bf011f97461b9547809608f31a5742a79b34af9fbf753112670f0c207773ccb818156154db3aaa2f46
|
7
|
+
data.tar.gz: 80c515b13c7f5d6e01bc780e956db067a89fe8135768c09e2bde29fbb007e3626b28eab4ca63ce20d85cd7133d7e49f99164d4c3625c326a320e20864840395a
|
data/bin/hstatic
CHANGED
data/lib/hstatic/app.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
require 'sinatra/base'
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require 'haml'
|
3
|
+
require 'slim'
|
4
4
|
|
5
|
+
# Main gem namespace
|
5
6
|
module Hstatic
|
6
7
|
BASEDIR = File.join(File.dirname(__FILE__), '..', '..')
|
7
8
|
|
9
|
+
# Main Sinatra Application
|
10
|
+
#
|
11
|
+
# It handles the publishing index pages and instantiation of
|
12
|
+
# templates files
|
8
13
|
class App < Sinatra::Base
|
9
14
|
configure do
|
10
15
|
set :views, File.join(BASEDIR, 'views')
|
@@ -16,11 +21,11 @@ module Hstatic
|
|
16
21
|
def dynamic_size(size)
|
17
22
|
case
|
18
23
|
when size > 2**40
|
19
|
-
sprintf(
|
24
|
+
sprintf('%5.2f', size / 2**40) << ' GB'
|
20
25
|
when (size / 2**20) > 0.1
|
21
|
-
sprintf(
|
26
|
+
sprintf('%5.2f', size / 2**20) << ' MB'
|
22
27
|
else
|
23
|
-
sprintf(
|
28
|
+
sprintf('%5.2f', size / 2**10) << ' kB'
|
24
29
|
end
|
25
30
|
end
|
26
31
|
end
|
@@ -28,20 +33,18 @@ module Hstatic
|
|
28
33
|
# Finally every Tilt supported template is rendered
|
29
34
|
helpers do
|
30
35
|
def render_file(path)
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
if template = Tilt[path]
|
37
|
+
ext, _ = Tilt.mappings.find { |k, v| v.include? template }
|
38
|
+
|
39
|
+
if self.respond_to? ext.to_sym
|
34
40
|
method = self.method(ext)
|
35
41
|
basename = File.basename(path, File.extname(path)).to_sym
|
36
42
|
|
37
|
-
method.call
|
38
|
-
else
|
39
|
-
raise Exception.new "No template found for #{path}"
|
43
|
+
return method.call basename, :views => File.dirname(path)
|
40
44
|
end
|
41
|
-
rescue Exception => e
|
42
|
-
logger.info e.message
|
43
|
-
send_file path
|
44
45
|
end
|
46
|
+
|
47
|
+
send_file path
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -85,9 +88,9 @@ module Hstatic
|
|
85
88
|
@parent = File.dirname(request.path_info)
|
86
89
|
|
87
90
|
Dir.foreach(path) do |entry|
|
88
|
-
next if entry ==
|
91
|
+
next if entry == '.' || entry == '..'
|
89
92
|
|
90
|
-
url_base = File.join(
|
93
|
+
url_base = File.join('/', request.path_info)
|
91
94
|
link = File.join(url_base, entry)
|
92
95
|
filename = File.expand_path(File.join(path, entry))
|
93
96
|
|
@@ -103,7 +106,7 @@ module Hstatic
|
|
103
106
|
# Render view
|
104
107
|
haml :index
|
105
108
|
else
|
106
|
-
[404,
|
109
|
+
[404, 'File not found']
|
107
110
|
end
|
108
111
|
end
|
109
112
|
end
|
data/lib/hstatic/version.rb
CHANGED
data/lib/hstatic.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'hstatic/version'
|
2
|
+
require 'hstatic/app'
|
3
3
|
|
4
4
|
require 'yaml/store'
|
5
5
|
|
6
|
+
# Main gem namespace
|
6
7
|
module Hstatic
|
8
|
+
#
|
9
|
+
# Main Sinatra Application
|
10
|
+
#
|
11
|
+
# Added launch class method for handling settings and execution details
|
7
12
|
class App
|
8
13
|
def self.launch(argv)
|
9
14
|
if argv.any?
|
10
15
|
require 'optparse'
|
11
|
-
OptionParser.new
|
12
|
-
op.on(
|
13
|
-
|
16
|
+
OptionParser.new do |op|
|
17
|
+
op.on('-o host',
|
18
|
+
'specify host (default is localhost)') { |val| set :bind, val }
|
14
19
|
|
15
|
-
op.on(
|
16
|
-
|
20
|
+
op.on('-p port', '--port port',
|
21
|
+
'set the port (default is 4567)') do |val|
|
17
22
|
@port_set = true
|
18
23
|
set :port, Integer(val)
|
19
24
|
end
|
20
25
|
|
21
|
-
op.on(
|
22
|
-
|
26
|
+
op.on('-s server',
|
27
|
+
'specify server (default is thin)') { |val| set :server, val }
|
23
28
|
|
24
|
-
op.on(
|
25
|
-
|
29
|
+
op.on('-x',
|
30
|
+
'turn on the mutex lock (default is off)') { set :lock, true }
|
26
31
|
|
27
|
-
op.on(
|
32
|
+
op.on('-v', '--version', 'show version') do
|
28
33
|
puts "hstatic tool: v#{VERSION}"
|
29
34
|
exit
|
30
35
|
end
|
31
|
-
|
36
|
+
end.parse!(ARGV.dup)
|
32
37
|
end
|
33
38
|
|
34
|
-
launches_file = File.join ENV['HOME'],
|
39
|
+
launches_file = File.join ENV['HOME'], '.cache/hstatic_launches'
|
35
40
|
@launches = Psych::Store.new launches_file, true
|
36
41
|
@launches.transaction do
|
37
|
-
unless @port_set
|
38
|
-
set :port, @launches[Dir.pwd] || 4567
|
39
|
-
end
|
40
|
-
|
42
|
+
set :port, @launches[Dir.pwd] || 4567 unless @port_set
|
41
43
|
@launches[Dir.pwd] = settings.port
|
42
44
|
end
|
43
45
|
|
44
46
|
# Processing path and port
|
45
|
-
pid_file = File.join(Dir.tmpdir,
|
46
|
-
File.open(pid_file, File::CREAT|File::APPEND|File::RDWR) do |f|
|
47
|
+
pid_file = File.join(Dir.tmpdir, 'hstatic.pid')
|
48
|
+
File.open(pid_file, File::CREAT | File::APPEND | File::RDWR) do |f|
|
47
49
|
f.readlines.each do |line|
|
48
|
-
instances = line.strip.split(
|
50
|
+
instances = line.strip.split(':')
|
49
51
|
if instances[1] == settings.port.to_s
|
50
|
-
puts
|
52
|
+
puts 'hstatic instance running already on the same port. Exiting'
|
51
53
|
exit
|
52
54
|
end
|
53
55
|
end
|
@@ -60,12 +62,12 @@ module Hstatic
|
|
60
62
|
if File.exists? pid_file
|
61
63
|
instances = File.open(pid_file, File::RDONLY) do |f|
|
62
64
|
f.readlines.map do |line|
|
63
|
-
pair = line.strip.split(
|
65
|
+
pair = line.strip.split(':')
|
64
66
|
pair unless pair[0] == Dir.pwd && pair[1] == settings.port.to_s
|
65
67
|
end.compact
|
66
68
|
end
|
67
69
|
|
68
|
-
File.open(pid_file, File::WRONLY|File::TRUNC) do |f|
|
70
|
+
File.open(pid_file, File::WRONLY | File::TRUNC) do |f|
|
69
71
|
instances.each do |pair|
|
70
72
|
f.write "#{pair[0]}:#{pair[1]}\n"
|
71
73
|
end
|
@@ -73,7 +75,6 @@ module Hstatic
|
|
73
75
|
|
74
76
|
File.unlink pid_file unless instances.length > 0
|
75
77
|
end
|
76
|
-
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
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.1.
|
4
|
+
version: 0.1.3
|
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: 2014-
|
11
|
+
date: 2014-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|