gfm_live_preview 0.9.5 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/gfm_live_preview +7 -2
- data/lib/gfm_live_preview/cli.rb +33 -0
- data/lib/gfm_live_preview/server.rb +8 -7
- data/lib/gfm_live_preview/version.rb +1 -1
- data/lib/gfm_live_preview.rb +10 -3
- data/lib/public/gfm_live_preview.css +8 -0
- data/lib/views/index.erb +5 -5
- data/test/sample.md +14 -0
- metadata +4 -3
- data/lib/public/readme.css +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb7a81f2c5a4368fe8f980db25ba2ccfd700a4db
|
4
|
+
data.tar.gz: 337f31ef3bda894d4f4f76ecddec338c8fa71a32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b4a35f7edb06eed47bfb04c270495325d4aecafe94a09af61b996144c1f382986a5b5665aff7659e6bfa804482e493b3227fe3043c0cee5a0527f8e3f787343
|
7
|
+
data.tar.gz: 83e7567923b1fb779d761f3c0b92a48b5687b666df7fbac0d7c2972f510e3622c652cbeda98d12416cc3cdf6d64dc7a13f08eb9986a982ce1c15d11595f2dd40
|
data/bin/gfm_live_preview
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module GfmLivePreview
|
4
|
+
class CLI
|
5
|
+
DEFAULTS = {
|
6
|
+
port: 31337,
|
7
|
+
}
|
8
|
+
|
9
|
+
attr :argv
|
10
|
+
|
11
|
+
def initialize(argv)
|
12
|
+
@argv = argv
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse(argv)
|
16
|
+
new(argv).parse
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse
|
20
|
+
options = DEFAULTS.dup
|
21
|
+
|
22
|
+
OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] FILE"
|
24
|
+
|
25
|
+
opts.on '-p', '--port PORT', 'Specify port other than 31337' do |port|
|
26
|
+
options[:port] = port.to_i
|
27
|
+
end
|
28
|
+
end.parse(argv)
|
29
|
+
|
30
|
+
[argv.last, options]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module GfmLivePreview
|
2
2
|
class Server < ::Sinatra::Application
|
3
3
|
enable :inline_templates
|
4
|
-
set :
|
4
|
+
set :bind, "0.0.0.0"
|
5
|
+
set :port, GfmLivePreview.config.fetch(:port)
|
5
6
|
set :sockets, []
|
6
7
|
|
7
8
|
def syntax_highlight! str
|
@@ -13,10 +14,10 @@ module GfmLivePreview
|
|
13
14
|
e.backtrace.each do |line| puts line; end
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
-
|
18
|
-
syntax_highlight!
|
19
|
-
GitHub::Markdown.render_gfm
|
17
|
+
def render_document
|
18
|
+
document = File.read ::GfmLivePreview.file
|
19
|
+
syntax_highlight! document
|
20
|
+
GitHub::Markdown.render_gfm document
|
20
21
|
end
|
21
22
|
|
22
23
|
def doc_path
|
@@ -27,9 +28,9 @@ module GfmLivePreview
|
|
27
28
|
if request.websocket?
|
28
29
|
request.websocket do |ws|
|
29
30
|
ws.onopen do
|
30
|
-
ws.send
|
31
|
+
ws.send render_document
|
31
32
|
listener = Listen.to doc_path do
|
32
|
-
ws.send
|
33
|
+
ws.send render_document
|
33
34
|
end
|
34
35
|
listener.start
|
35
36
|
settings.sockets << ws
|
data/lib/gfm_live_preview.rb
CHANGED
@@ -4,7 +4,6 @@ require "github/markdown"
|
|
4
4
|
require "sinatra"
|
5
5
|
require "sinatra-websocket"
|
6
6
|
|
7
|
-
require "gfm_live_preview/server"
|
8
7
|
require "gfm_live_preview/syntax_highlighter"
|
9
8
|
require "gfm_live_preview/version"
|
10
9
|
|
@@ -13,8 +12,16 @@ module GfmLivePreview
|
|
13
12
|
|
14
13
|
attr :file
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
autoload :CLI, "gfm_live_preview/cli"
|
16
|
+
autoload :Server, "gfm_live_preview/server"
|
17
|
+
|
18
|
+
def run! argv
|
19
|
+
@file, options = CLI.parse argv
|
20
|
+
config.update options
|
18
21
|
Server.run!
|
19
22
|
end
|
23
|
+
|
24
|
+
def config
|
25
|
+
@config ||= {}
|
26
|
+
end
|
20
27
|
end
|
data/lib/views/index.erb
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
<head>
|
4
4
|
<title>Github Flavored Markdown Live Preview</title>
|
5
5
|
<link rel="stylesheet" type="css" media="all" href="github.css" />
|
6
|
-
<link rel="stylesheet" type="css" media="all" href="
|
6
|
+
<link rel="stylesheet" type="css" media="all" href="gfm_live_preview.css" />
|
7
7
|
</head>
|
8
8
|
<body>
|
9
|
-
<div id="
|
10
|
-
</div><!-- /#
|
9
|
+
<div id="document">
|
10
|
+
</div><!-- /#document -->
|
11
11
|
</body>
|
12
12
|
<script type="text/javascript">
|
13
13
|
window.onload = function() {
|
@@ -22,11 +22,11 @@ window.onload = function() {
|
|
22
22
|
}
|
23
23
|
};
|
24
24
|
|
25
|
-
var
|
25
|
+
var md_document = document.getElementById("document");
|
26
26
|
var web_socket_url = "ws://" + window.location.host + window.location.pathname;
|
27
27
|
var ws = new WebSocket(web_socket_url);
|
28
28
|
ws.onmessage = function(m) {
|
29
|
-
|
29
|
+
md_document.innerHTML = m.data;
|
30
30
|
reload_css();
|
31
31
|
};
|
32
32
|
})();
|
data/test/sample.md
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gfm_live_preview
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ntl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,11 +125,12 @@ files:
|
|
125
125
|
- bin/gfm_live_preview
|
126
126
|
- gfm_live_preview.gemspec
|
127
127
|
- lib/gfm_live_preview.rb
|
128
|
+
- lib/gfm_live_preview/cli.rb
|
128
129
|
- lib/gfm_live_preview/server.rb
|
129
130
|
- lib/gfm_live_preview/syntax_highlighter.rb
|
130
131
|
- lib/gfm_live_preview/version.rb
|
132
|
+
- lib/public/gfm_live_preview.css
|
131
133
|
- lib/public/github.css
|
132
|
-
- lib/public/readme.css
|
133
134
|
- lib/views/index.erb
|
134
135
|
- test/sample.md
|
135
136
|
homepage: https://github.com/ntl/gfm_live_preview
|
data/lib/public/readme.css
DELETED