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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c86082a49ca3f4757bdca009f9909af576a31c36
4
- data.tar.gz: 6df08137470ee5458bd9de3c4c163526d6efb244
3
+ metadata.gz: fb7a81f2c5a4368fe8f980db25ba2ccfd700a4db
4
+ data.tar.gz: 337f31ef3bda894d4f4f76ecddec338c8fa71a32
5
5
  SHA512:
6
- metadata.gz: 5be544c4a834852ca60eab96a1d559388cb8ce7fb480d665e0070c6bd1370af6b5481e02d9dcf10fbf4dfbe6c4fc1f18c57a69ca62d23d190b1e8589b3f85130
7
- data.tar.gz: 92ce6b662544f8a45ecf531f22be88965ff32680106c3a275fc4ae21320fb310517784149648bc6ac22d805a2d370c73b17362e6a3f30b609c46f3e7d4877264
6
+ metadata.gz: 5b4a35f7edb06eed47bfb04c270495325d4aecafe94a09af61b996144c1f382986a5b5665aff7659e6bfa804482e493b3227fe3043c0cee5a0527f8e3f787343
7
+ data.tar.gz: 83e7567923b1fb779d761f3c0b92a48b5687b666df7fbac0d7c2972f510e3622c652cbeda98d12416cc3cdf6d64dc7a13f08eb9986a982ce1c15d11595f2dd40
data/bin/gfm_live_preview CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env ruby -rubygems
2
2
 
3
- require 'gfm_live_preview'
3
+ begin
4
+ require 'gfm_live_preview'
5
+ rescue LoadError
6
+ require 'rubygems'
7
+ require 'gfm_live_preview'
8
+ end
4
9
 
5
- GfmLivePreview.run! ARGV.shift
10
+ GfmLivePreview.run! ARGV
@@ -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 :port, 31337
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 render_readme_html
17
- readme_md = File.read ::GfmLivePreview.file
18
- syntax_highlight! readme_md
19
- GitHub::Markdown.render_gfm readme_md
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 render_readme_html
31
+ ws.send render_document
31
32
  listener = Listen.to doc_path do
32
- ws.send render_readme_html
33
+ ws.send render_document
33
34
  end
34
35
  listener.start
35
36
  settings.sockets << ws
@@ -1,3 +1,3 @@
1
1
  module GfmLivePreview
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.6"
3
3
  end
@@ -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
- def run! markdown_file
17
- @file = markdown_file
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
@@ -0,0 +1,8 @@
1
+ div#document {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
5
+
6
+ ol li {
7
+ list-style-type: decimal;
8
+ }
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="readme.css" />
6
+ <link rel="stylesheet" type="css" media="all" href="gfm_live_preview.css" />
7
7
  </head>
8
8
  <body>
9
- <div id="readme-html">
10
- </div><!-- /#readme-html -->
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 readme_html = document.getElementById("readme-html");
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
- readme_html.innerHTML = m.data;
29
+ md_document.innerHTML = m.data;
30
30
  reload_css();
31
31
  };
32
32
  })();
data/test/sample.md CHANGED
@@ -7,3 +7,17 @@ class RubySyntax
7
7
  end
8
8
  end
9
9
  ```
10
+
11
+ ### OL
12
+
13
+ 1. Numbered
14
+ 2. List
15
+ 3. of
16
+ 4. Things
17
+
18
+ ### UL
19
+
20
+ * There
21
+ * is
22
+ * no
23
+ * order
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.5
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: 2013-10-27 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- div#readme-html {
2
- margin: 0;
3
- padding: 0;
4
- }