mascut 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.0.3 (2010-04-08)
2
+ * add Rack option
3
+
1
4
  = 0.0.2 (2009-12-18)
2
5
  * add cache-control
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
data/bin/mascut CHANGED
@@ -5,21 +5,36 @@ rescue LoadError
5
5
  require 'rubygems'
6
6
  require 'rack'
7
7
  end
8
+
8
9
  begin
9
10
  require 'mascut'
10
11
  rescue LoadError
11
- require File.join(File.dirname(__FILE__), %w[ .. lib mascut ]) # for development
12
+ $: << File.join(File.dirname(__FILE__), %w[ .. lib ]) # for development
13
+ require 'mascut'
12
14
  end
13
-
15
+
16
+ Version = Mascut::VERSION
17
+ p opts = Mascut::Option.parse
14
18
 
15
19
  app = Rack::Builder.new do
16
20
  use Rack::CommonLogger, $stdout
17
21
  use Rack::ShowExceptions
18
22
  use Rack::ShowStatus
19
23
 
20
- run Rack::Cascade.new([ Mascut.new, Rack::File.new('.') ])
24
+ run Rack::Cascade.new([ Mascut::Mascut.new, Rack::File.new('.') ])
21
25
  end.to_app
22
26
 
23
- Rack::Handler::Mongrel.run app, :Host => '0.0.0.0', :Port => 9203 do
24
- puts '*** Mascut has started on http://localhost:9203/ ***'
27
+ begin
28
+ require opts[:server]
29
+ server = Rack::Handler.get(opts[:server])
30
+ rescue LoadError, NameError => e
31
+ begin
32
+ server = Rack::Handler::Mongrel
33
+ rescue LoadError => e
34
+ server = Rack::Handler::WEBrick
35
+ end
36
+ end
37
+
38
+ server.run app, opts do
39
+ puts "*** Mascut has started on http://#{opts[:Host]}:#{opts[:Port]}/ ***"
25
40
  end
data/lib/mascut.rb CHANGED
@@ -1,47 +1,7 @@
1
- require 'sinatra/base'
2
-
3
- class Mascut < Sinatra::Base
4
- get '/mascut' do
5
- headers 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache'
6
-
7
- now = Time.now
8
- files = Dir['**/*']
9
-
10
- catch :reload do
11
- loop do
12
- files.each {|file| throw(:reload, 'reload') if File.exist?(file) and now < File.mtime(file) }
13
- sleep 1
14
- end
15
- end
16
- end
17
-
18
- get %r{^/(.+\.html)$} do |name|
19
- halt(404) unless File.exist?(name)
20
-
21
- # I don't use nokogiri because it corercts wrong html.
22
- File.read(name).sub('</head>', <<-JS)
23
- <script src='http://www.google.com/jsapi'></script>
24
- <script>
25
- var comet = function() {
26
- $.ajax({
27
- type: 'GET',
28
- url: '/mascut',
29
- success: function(msg) {
30
- msg == 'reload' ? location.reload() : comet();
31
- }
32
- });
33
- }
34
-
35
- google.load('jquery', '1');
36
- google.setOnLoadCallback(comet);
37
- </script>
38
- </head>
39
- JS
40
- end
41
-
42
- get %r{^/(.+\.css)$} do |name|
43
- content_type :css
44
- File.exist?(name) ? File.read(name) : halt(404)
45
- end
1
+ module Mascut
2
+ VERSION = File.read(File.join(File.dirname(__FILE__), %w[ .. VERSION ])).chomp
3
+
4
+ autoload :Mascut, 'mascut/mascut'
5
+ autoload :Option, 'mascut/option'
46
6
  end
47
7
 
@@ -0,0 +1,48 @@
1
+ require 'sinatra/base'
2
+
3
+ module Mascut
4
+ class Mascut < Sinatra::Base
5
+ get '/mascut' do
6
+ headers 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache'
7
+
8
+ now = Time.now
9
+ files = Dir['**/*']
10
+
11
+ catch :reload do
12
+ loop do
13
+ files.each {|file| throw(:reload, 'reload') if File.exist?(file) and now < File.mtime(file) }
14
+ sleep 1
15
+ end
16
+ end
17
+ end
18
+
19
+ get %r{^/(.+\.html)$} do |name|
20
+ halt(404) unless File.exist?(name)
21
+
22
+ # I don't use nokogiri because it corercts wrong html.
23
+ File.read(name).sub('</head>', <<-JS)
24
+ <script src='http://www.google.com/jsapi'></script>
25
+ <script>
26
+ var comet = function() {
27
+ $.ajax({
28
+ type: 'GET',
29
+ url: '/mascut',
30
+ success: function(msg) {
31
+ msg == 'reload' ? location.reload() : comet();
32
+ }
33
+ });
34
+ }
35
+
36
+ google.load('jquery', '1');
37
+ google.setOnLoadCallback(comet);
38
+ </script>
39
+ </head>
40
+ JS
41
+ end
42
+
43
+ get %r{^/(.+\.css)$} do |name|
44
+ content_type :css
45
+ File.exist?(name) ? File.read(name) : halt(404)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,38 @@
1
+ require 'optparse'
2
+
3
+ module Mascut
4
+ class Option
5
+ def self.parse(args = ARGV.dup)
6
+ {
7
+ :server => 'mongrel',
8
+ :Host => '0.0.0.0',
9
+ :Port => 9203
10
+ }.tap do |options|
11
+ OptionParser.new do |opts|
12
+ opts.separator 'Rack options:' # almost same as rack
13
+ opts.on('-s', '--server SERVER', 'serve using SERVER (default: mongrel)') { |s|
14
+ options[:server] = s
15
+ }
16
+
17
+ opts.on('-o', '--host HOST', 'listen on HOST (default: 0.0.0.0)') { |host|
18
+ options[:Host] = host
19
+ }
20
+
21
+ opts.on('-p', '--port PORT', 'use PORT (default: 9203)') { |port|
22
+ options[:Port] = port
23
+ }
24
+
25
+ opts.on('-D', '--daemonize', 'run daemonized in the background') { |d|
26
+ options[:daemonize] = d ? true : false
27
+ }
28
+
29
+ opts.separator ''
30
+ opts.separator 'Mascut options:(TODO)'
31
+
32
+ opts.permute!(args)
33
+ options[:files] = args
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mascut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - okitan
@@ -9,29 +14,37 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-18 00:00:00 +09:00
17
+ date: 2010-04-08 00:00:00 +09:00
13
18
  default_executable: mascut
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: sinatra
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 9
30
+ - 4
23
31
  version: 0.9.4
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 2
44
+ - 9
33
45
  version: 1.2.9
34
- version:
46
+ type: :development
47
+ version_requirements: *id002
35
48
  description: instant comet-like server in order to debug web pages
36
49
  email: okitakunio@gmail.com
37
50
  executables:
@@ -51,6 +64,8 @@ files:
51
64
  - VERSION
52
65
  - bin/mascut
53
66
  - lib/mascut.rb
67
+ - lib/mascut/mascut.rb
68
+ - lib/mascut/option.rb
54
69
  - spec/mascut_spec.rb
55
70
  - spec/spec.opts
56
71
  - spec/spec_helper.rb
@@ -67,18 +82,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
82
  requirements:
68
83
  - - ">="
69
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
70
87
  version: "0"
71
- version:
72
88
  required_rubygems_version: !ruby/object:Gem::Requirement
73
89
  requirements:
74
90
  - - ">="
75
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
76
94
  version: "0"
77
- version:
78
95
  requirements: []
79
96
 
80
97
  rubyforge_project:
81
- rubygems_version: 1.3.5
98
+ rubygems_version: 1.3.6
82
99
  signing_key:
83
100
  specification_version: 3
84
101
  summary: instant comet-like server in order to debug web pages