mascut 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.rdoc +4 -0
- data/README.rdoc +4 -1
- data/Rakefile +0 -2
- data/VERSION +1 -1
- data/bin/mascut +5 -2
- data/lib/mascut/mascut.rb +35 -21
- data/lib/mascut/option.rb +20 -10
- metadata +5 -19
data/HISTORY.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -19,6 +19,9 @@ Simply execute this command at the top of your working directory
|
|
19
19
|
Accessing <http://localhost:9203/working_html.html> with your browser, you can see it works as comet.
|
20
20
|
When you edit your working stuffs, your browser will automatically be reloaded!!
|
21
21
|
|
22
|
+
For Additional Information, just see helps
|
23
|
+
% mascut --help
|
24
|
+
|
22
25
|
== Copyright
|
23
26
|
|
24
|
-
Copyright (c) 2009 okitan. See LICENSE for details.
|
27
|
+
Copyright (c) 2009-2010 okitan. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -11,8 +11,6 @@ begin
|
|
11
11
|
gem.homepage = 'http://github.com/okitan/mascut'
|
12
12
|
gem.authors = %w[ okitan ]
|
13
13
|
|
14
|
-
gem.add_dependency 'sinatra', '>=0.9.4'
|
15
|
-
|
16
14
|
gem.add_development_dependency 'rspec', '>= 1.2.9'
|
17
15
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
18
16
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bin/mascut
CHANGED
@@ -14,14 +14,17 @@ rescue LoadError
|
|
14
14
|
end
|
15
15
|
|
16
16
|
Version = Mascut::VERSION
|
17
|
-
|
17
|
+
opts = Mascut::Option.parse
|
18
18
|
|
19
19
|
app = Rack::Builder.new do
|
20
20
|
use Rack::CommonLogger, $stdout
|
21
21
|
use Rack::ShowExceptions
|
22
22
|
use Rack::ShowStatus
|
23
|
+
|
24
|
+
use Rack::ContentLength
|
23
25
|
|
24
|
-
|
26
|
+
use Mascut::Mascut, opts[:mascut], opts[:files], opts
|
27
|
+
run Rack::File.new('.')
|
25
28
|
end.to_app
|
26
29
|
|
27
30
|
begin
|
data/lib/mascut/mascut.rb
CHANGED
@@ -1,32 +1,51 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
|
3
1
|
module Mascut
|
4
|
-
class Mascut
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class Mascut
|
3
|
+
def initialize(app, path = nil, files = nil, opts = nil)
|
4
|
+
@app = app
|
5
|
+
@path = path || '/mascut'
|
6
|
+
@files = files || Dir['**/*']
|
7
|
+
@opts = opts || {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
if env['PATH_INFO'] == @path
|
12
|
+
mascut
|
13
|
+
else
|
14
|
+
status, headers, body = @app.call(env)
|
15
|
+
if status == 200 and headers['Content-Type'] =~ /^text\/html/
|
16
|
+
body = [ File.read(body.path) ] if body.is_a?(Rack::File)
|
17
|
+
body.map! {|html| mascutize(html) }
|
18
|
+
headers['Content-Length'] = body.to_a.inject(0) { |len, part| len + Rack::Utils.bytesize(part) }.to_s
|
19
|
+
|
20
|
+
[ status, headers, [mascutize(body.first)] ]
|
21
|
+
else
|
22
|
+
[ status, headers, body ]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def mascut
|
8
28
|
now = Time.now
|
9
|
-
files = Dir['**/*']
|
10
29
|
|
11
30
|
catch :reload do
|
12
31
|
loop do
|
13
|
-
files.each {|file| throw(:reload, 'reload') if File.exist?(file) and now < File.mtime(file) }
|
14
|
-
sleep 1
|
32
|
+
@files.each {|file| throw(:reload, 'reload') if File.exist?(file) and now < File.mtime(file) }
|
33
|
+
sleep (@opts[:interval] || 1.0)
|
15
34
|
end
|
16
35
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
get %r{^/(.+\.html)$} do |name|
|
20
|
-
halt(404) unless File.exist?(name)
|
21
36
|
|
22
|
-
|
23
|
-
|
37
|
+
[ 200, { 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache', 'Content-Type' => 'text/plain' }, ['reload'] ]
|
38
|
+
end
|
39
|
+
|
40
|
+
def mascutize(html)
|
41
|
+
# I don't use html parser like nokogiri, because it corrects html to be debugged
|
42
|
+
html.sub('</head>', <<-JS)
|
24
43
|
<script src='http://www.google.com/jsapi'></script>
|
25
44
|
<script>
|
26
45
|
var comet = function() {
|
27
46
|
$.ajax({
|
28
47
|
type: 'GET',
|
29
|
-
url: '
|
48
|
+
url: '#{@path}',
|
30
49
|
success: function(msg) {
|
31
50
|
msg == 'reload' ? location.reload() : comet();
|
32
51
|
}
|
@@ -39,10 +58,5 @@ google.setOnLoadCallback(comet);
|
|
39
58
|
</head>
|
40
59
|
JS
|
41
60
|
end
|
42
|
-
|
43
|
-
get %r{^/(.+\.css)$} do |name|
|
44
|
-
content_type :css
|
45
|
-
File.exist?(name) ? File.read(name) : halt(404)
|
46
|
-
end
|
47
61
|
end
|
48
62
|
end
|
data/lib/mascut/option.rb
CHANGED
@@ -9,28 +9,38 @@ module Mascut
|
|
9
9
|
:Port => 9203
|
10
10
|
}.tap do |options|
|
11
11
|
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: mascut [files] [rack options] [mascut options]"
|
13
|
+
|
12
14
|
opts.separator 'Rack options:' # almost same as rack
|
13
|
-
opts.on('-s', '--server SERVER', 'serve using SERVER (default: mongrel)')
|
15
|
+
opts.on('-s', '--server SERVER', 'serve using SERVER (default: mongrel)') do |s|
|
14
16
|
options[:server] = s
|
15
|
-
|
17
|
+
end
|
16
18
|
|
17
|
-
opts.on('-o', '--host HOST', 'listen on HOST (default: 0.0.0.0)')
|
19
|
+
opts.on('-o', '--host HOST', 'listen on HOST (default: 0.0.0.0)') do |host|
|
18
20
|
options[:Host] = host
|
19
|
-
|
21
|
+
end
|
20
22
|
|
21
|
-
opts.on('-p', '--port PORT', 'use PORT (default: 9203)')
|
23
|
+
opts.on('-p', '--port PORT', 'use PORT (default: 9203)') do |port|
|
22
24
|
options[:Port] = port
|
23
|
-
|
25
|
+
end
|
24
26
|
|
25
|
-
opts.on('-D', '--daemonize', 'run daemonized in the background')
|
27
|
+
opts.on('-D', '--daemonize', 'run daemonized in the background') do |d|
|
26
28
|
options[:daemonize] = d ? true : false
|
27
|
-
|
29
|
+
end
|
28
30
|
|
29
31
|
opts.separator ''
|
30
|
-
opts.separator 'Mascut options:
|
32
|
+
opts.separator 'Mascut options:'
|
33
|
+
|
34
|
+
opts.on('-m', '--mascut PATH', 'absolute path for comet(default on Mascut::Mascut: /mascut)') do |path|
|
35
|
+
options[:mascut] = path.index('/') == 0 ? path : "/#{path}"
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-i', '--interval SEC', Float, 'interval to monitor files(default on Mascut::Mascut: 1.0 sec)') do |sec|
|
39
|
+
options[:interval] = sec
|
40
|
+
end
|
31
41
|
|
32
42
|
opts.permute!(args)
|
33
|
-
options[:files] = args
|
43
|
+
options[:files] = args.size > 0 ? args : nil
|
34
44
|
end
|
35
45
|
end
|
36
46
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- okitan
|
@@ -14,27 +14,13 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-04-
|
17
|
+
date: 2010-04-12 00:00:00 +09:00
|
18
18
|
default_executable: mascut
|
19
19
|
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
name: sinatra
|
22
|
-
prerelease: false
|
23
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
requirements:
|
25
|
-
- - ">="
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 9
|
30
|
-
- 4
|
31
|
-
version: 0.9.4
|
32
|
-
type: :runtime
|
33
|
-
version_requirements: *id001
|
34
20
|
- !ruby/object:Gem::Dependency
|
35
21
|
name: rspec
|
36
22
|
prerelease: false
|
37
|
-
requirement: &
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
38
24
|
requirements:
|
39
25
|
- - ">="
|
40
26
|
- !ruby/object:Gem::Version
|
@@ -44,7 +30,7 @@ dependencies:
|
|
44
30
|
- 9
|
45
31
|
version: 1.2.9
|
46
32
|
type: :development
|
47
|
-
version_requirements: *
|
33
|
+
version_requirements: *id001
|
48
34
|
description: instant comet-like server in order to debug web pages
|
49
35
|
email: okitakunio@gmail.com
|
50
36
|
executables:
|