rdoc-view 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rdoc-view.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 tamtam180
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,29 @@
1
+ = RDocView
2
+
3
+ RDocView is a real-time viewer of RDoc/Markdown which used WebSocket.
4
+
5
+ = Install
6
+
7
+ gem install rdoc-view
8
+
9
+ = Usage
10
+
11
+ rdoc-view [-p port] [-o addr] [-t type] filename
12
+
13
+ -p port set the port (default is 4567)
14
+ -o addr set the host (default is 0.0.0.0)
15
+ -t type set the document type (rdoc or md)
16
+ if omits, judging from the extension
17
+
18
+ browse http://localhost:4567/
19
+ and edit filename by your favorite editor.
20
+ Change of a file is detected and a rendering is carried out in real time.
21
+
22
+ = Support Browser
23
+ - Google Chrome
24
+ - Firefox
25
+
26
+ = License
27
+
28
+ - MIT License
29
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/rdoc-view ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rdoc-view'
@@ -0,0 +1,3 @@
1
+ module RDocView
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rdoc-view.rb ADDED
@@ -0,0 +1,134 @@
1
+ # coding: utf-8
2
+
3
+ $LOAD_PATH.unshift File.dirname(__FILE__)
4
+ require "rdoc-view/version"
5
+
6
+ require "net/https"
7
+ require "uri"
8
+ require "optparse"
9
+ require "rdoc"
10
+ require "rdoc/markup/to_html"
11
+
12
+ require "sinatra/base"
13
+ require "sinatra-websocket"
14
+ require "fssm"
15
+
16
+ module RDocView
17
+ def convert(file, type)
18
+ html = ""
19
+ text = open(file){|f|f.read}
20
+ case type
21
+ when "md"
22
+ uri = URI.parse("https://api.github.com/markdown/raw")
23
+ https = Net::HTTP.new(uri.host, uri.port)
24
+ https.use_ssl = true
25
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
26
+ #https.set_debug_output $stderr
27
+ https.start do | access |
28
+ resp = access.post(uri.path, text, {"content-type" => "text/plain"})
29
+ html = resp.body
30
+ end
31
+ else
32
+ h = RDoc::Markup::ToHtml.new
33
+ html = h.convert(text)
34
+ end
35
+ return html
36
+ end
37
+ module_function :convert
38
+
39
+ class ViewApp < Sinatra::Base
40
+
41
+ opt_type = nil
42
+ OptionParser.new { |op |
43
+ op.on('-p port', 'set the port (default is 4567)') { |val| set :port, Integer(val) }
44
+ op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| set :bind, val }
45
+ op.on('-t type', 'set the document type (rdoc or md)',
46
+ 'if omits, judging from the extension') { |val| opt_type = val.downcase }
47
+ }.parse!(ARGV)
48
+ set :environment, :production
49
+
50
+ raise "ARGV is empty." if ARGV.empty?
51
+ raise "File Not Found:#{ARGV[0]}" unless File.exists?(ARGV[0])
52
+
53
+ set :target_file, ARGV[0]
54
+ set :server, "thin"
55
+ set :sockets, []
56
+
57
+ support_extensions = ["rdoc", "md"]
58
+ set :type, opt_type
59
+ set :type, File.extname(ARGV[0]).downcase().slice(1..-1) unless support_extensions.include?(opt_type)
60
+
61
+ send_func = Proc.new do | ws |
62
+ if File.exists?(settings.target_file) then
63
+ # convert to html
64
+ html = RDocView.convert(settings.target_file, settings.type)
65
+ html.force_encoding("utf-8")
66
+
67
+ EM.next_tick do
68
+ if ws then
69
+ ws.send(html)
70
+ else
71
+ settings.sockets.each do |s|
72
+ s.send(html)
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ # blockingしちゃうので。
80
+ th = Thread.new(send_func) do | send_func |
81
+ FSSM.monitor(File.dirname(settings.target_file), File.basename(settings.target_file)) do
82
+ update {|b,r| send_func.call()}
83
+ delete {|b,r| }
84
+ create {|b,r| send_func.call()}
85
+ end
86
+ end
87
+
88
+ # 簡易的なTimer。定期的にPingを飛ばす。
89
+ th_timer = Thread.new() do
90
+ while true
91
+ EM.next_tick do
92
+ settings.sockets.each do |s|
93
+ s.ping()
94
+ end
95
+ end
96
+ sleep 5
97
+ end
98
+ end
99
+
100
+ error 500 do
101
+ "Error: Internal Server Error."
102
+ end
103
+
104
+ get "/" do
105
+ erb :index
106
+ end
107
+
108
+ get "/rdoc" do
109
+ if request.websocket? then
110
+ request.websocket do | ws |
111
+ ws.onopen do
112
+ settings.sockets << ws
113
+ send_func.call(ws)
114
+ end
115
+ ws.onmessage do | msg |
116
+ end
117
+ ws.onclose do
118
+ settings.sockets.delete(ws)
119
+ end
120
+ ws.onerror do
121
+ end
122
+ ws.onping do
123
+ end
124
+ ws.onpong do
125
+ end
126
+ end
127
+ else
128
+ 500
129
+ end
130
+ end
131
+ end
132
+ ViewApp.run!
133
+ end
134
+
@@ -0,0 +1,77 @@
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5
+ <title>RDoc Document Viewer</title>
6
+ <link href="http://developer.github.com/css/reset.css" rel="stylesheet" type="text/css" />
7
+ <link href="http://developer.github.com/css/960.css" rel="stylesheet" type="text/css" />
8
+ <link href="http://developer.github.com/css/uv_active4d.css" rel="stylesheet" type="text/css" />
9
+ <link href="http://developer.github.com/shared/css/documentation.css" media="screen" rel="stylesheet" type="text/css">
10
+ <link href="http://developer.github.com/shared/css/pygments.css" media="screen" rel="stylesheet" type="text/css">
11
+ <style>
12
+ .logo {
13
+ padding-top: 10px;
14
+ font-size: 48px;
15
+ }
16
+ .closed {
17
+ color: #e91000;
18
+ }
19
+ .error {
20
+ color: #e91000;
21
+ }
22
+ .opened {
23
+ color: #0065e9;
24
+ }
25
+ </style>
26
+ <script src="http://developer.github.com/shared/js/jquery.js" type="text/javascript"></script>
27
+ <script src="http://developer.github.com/shared/js/documentation.js" type="text/javascript"></script>
28
+ <script type="text/javascript">
29
+ var timerId;
30
+ function ws_connect() {
31
+ var ws = new WebSocket("ws://" + location.host + "/rdoc")
32
+ ws.onopen = function() {
33
+ if (timerId) {
34
+ clearTimeout(timerId);
35
+ timerId = undefined;
36
+ }
37
+ $("#status").html('<span class="opened">OPENED</span>');
38
+ };
39
+ ws.onmessage = function(e) {
40
+ $("div.content").html(e.data);
41
+ };
42
+ ws.onclose = function() {
43
+ $("#status").html('<span class="closed">CLOSED</span>');
44
+ // 再接続
45
+ timerId = setTimeout(function(){
46
+ ws_connect();
47
+ }, 5000)
48
+ };
49
+ ws.onerror = function(e) {
50
+ $("#status").html('<span class="error">ERROR</span>');
51
+ };
52
+ }
53
+ $(function() {
54
+ ws_connect();
55
+ });
56
+ </script>
57
+ </head>
58
+ <body class="api">
59
+
60
+ <div id="header-wrapper">
61
+ <div id="header">
62
+ <a class="logo">RDocViewer</a>
63
+ <ul class="nav">
64
+ <li id="filename"><%=File.basename(settings.target_file)%></li>
65
+ <li id="status"></li>
66
+ </ul>
67
+ </div>
68
+ </div>
69
+
70
+ <div id="wrapper">
71
+ <div class="content">
72
+ </div>
73
+ </div>
74
+
75
+ </body>
76
+ </html>
77
+
data/rdoc-view.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rdoc-view/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rdoc-view"
8
+ gem.version = RDocView::VERSION
9
+ gem.authors = ["tamtam180"]
10
+ gem.email = ["kirscheless@gmail.com"]
11
+ gem.description = %q{Realtime RDoc viewer with WebSocket.}
12
+ gem.summary = %q{Realtime RDoc viewer with WebSocket.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/) - %w[.gitignore]
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "sinatra"
21
+ gem.add_dependency "sinatra-websocket"
22
+ gem.add_dependency "fssm"
23
+ gem.add_dependency "rdoc"
24
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rdoc-view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tamtam180
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sinatra
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sinatra-websocket
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fssm
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rdoc
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Realtime RDoc viewer with WebSocket.
79
+ email:
80
+ - kirscheless@gmail.com
81
+ executables:
82
+ - rdoc-view
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.rdoc
89
+ - Rakefile
90
+ - bin/rdoc-view
91
+ - lib/rdoc-view.rb
92
+ - lib/rdoc-view/version.rb
93
+ - lib/views/index.erb
94
+ - rdoc-view.gemspec
95
+ homepage: ''
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.24
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Realtime RDoc viewer with WebSocket.
119
+ test_files: []