gfm_live_preview 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03f5e33aadd4ea80fc853606ed7573e897bf3fbd
4
+ data.tar.gz: 0c3250041599c70c2fb6cde7c2cf90ff0edafcf5
5
+ SHA512:
6
+ metadata.gz: 248f6b2579efc6a9f0953bdfdfe58c2d650e97b0afc0de51e38b56be4327377c40e6d1ccc13ae47f26677b36916a420b2997fc92f8badfdf57c5808caf4a5759
7
+ data.tar.gz: 42962bb71610d20c1c27a01de98f4fc6f140011b99bb674ba642db11bc8d2bce3eade4439450c2821d60c8ffec9e337f964631dd963bbda966571e20d69f0860
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p247
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gfm_live_preview.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ntl
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.md ADDED
@@ -0,0 +1,29 @@
1
+ # GfmLivePreview
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gfm_live_preview'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gfm_live_preview
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ Bundler.require
4
+ require "gfm_live_preview"
5
+
6
+ task :test do
7
+ GfmLivePreview.run! File.expand_path("../test/sample.md", __FILE__)
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gfm_live_preview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gfm_live_preview"
8
+ spec.version = GfmLivePreview::VERSION
9
+ spec.authors = ["ntl"]
10
+ spec.email = ["nathanladd+github@gmail.com"]
11
+ spec.description = %q{Live preview your github flavored markdown file (with syntax highlighting!).}
12
+ spec.summary = %q{Live preview your github flavored markdown file (with syntax highlighting!). Loads via sinatra on port 31337 of localhost.}
13
+ spec.homepage = "https://github.com/ntl/gfm_live_preview"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "github-linguist"
25
+ spec.add_dependency "github-markdown"
26
+ spec.add_dependency "listen"
27
+ spec.add_dependency "sinatra"
28
+ spec.add_dependency "sinatra-websocket"
29
+ end
@@ -0,0 +1,20 @@
1
+ require "listen"
2
+ require "linguist"
3
+ require "github/markdown"
4
+ require "sinatra"
5
+ require "sinatra-websocket"
6
+
7
+ require "gfm_live_preview/server"
8
+ require "gfm_live_preview/syntax_highlighter"
9
+ require "gfm_live_preview/version"
10
+
11
+ module GfmLivePreview
12
+ extend self
13
+
14
+ attr :file
15
+
16
+ def run! markdown_file
17
+ @file = markdown_file
18
+ Server.run!
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ module GfmLivePreview
2
+ class Server < ::Sinatra::Application
3
+ enable :inline_templates
4
+ set :port, 31337
5
+ set :sockets, []
6
+
7
+ def syntax_highlight! str
8
+ SyntaxHighlighter.highlight! str do |string, hexcolor|
9
+ "<span style=\"color:##{hexcolor}\">#{string}</span>"
10
+ end
11
+ rescue => e
12
+ puts "Exception during syntax highlighting: #{e}"
13
+ e.backtrace.each do |line| puts line; end
14
+ end
15
+
16
+ def render_readme_html
17
+ readme_md = File.read ::GfmLivePreview.file
18
+ syntax_highlight! readme_md
19
+ GitHub::Markdown.render_gfm readme_md
20
+ end
21
+
22
+ def doc_path
23
+ File.expand_path '..', ::GfmLivePreview.file
24
+ end
25
+
26
+ get "/" do
27
+ if request.websocket?
28
+ request.websocket do |ws|
29
+ ws.onopen do
30
+ ws.send render_readme_html
31
+ listener = Listen.to doc_path do
32
+ puts "Detected change in doc/ directory; rerendering!"
33
+ ws.send render_readme_html
34
+ end
35
+ listener.start
36
+ settings.sockets << ws
37
+ end
38
+ ws.onclose do
39
+ settings.sockets.delete ws
40
+ end
41
+ end
42
+ else
43
+ erb :index
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ module GfmLivePreview
2
+ class SyntaxHighlighter
3
+ MATCHER = %r{^```(.+?)$(.*?)^```$}m
4
+
5
+ def self.highlight! str
6
+ str.gsub! MATCHER do |match|
7
+ code_snippet = $2
8
+ language = Linguist::Language.find_by_alias $1
9
+ language.colorize code_snippet
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module GfmLivePreview
2
+ VERSION = "0.9.0"
3
+ end
@@ -0,0 +1,121 @@
1
+ /*
2
+ Some simple Github-like styles, with syntax highlighting CSS via Pygments.
3
+ */
4
+ body{
5
+ font-family: helvetica, arial, freesans, clean, sans-serif;
6
+ color: #333;
7
+ background-color: #fff;
8
+ border: none;
9
+ line-height: 1.5;
10
+ margin: 2em 3em;
11
+ text-align:left;
12
+ }
13
+ pre{
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ -webkit-border-radius: 5px;
17
+ -moz-border-radius: 5px;
18
+ border-radius: 5px;
19
+ overflow: auto;
20
+ }
21
+ code{
22
+ background-color: #eee;
23
+ padding: 1px 3px;
24
+ -webkit-border-radius: 2px;
25
+ -moz-border-radius: 2px;
26
+ border-radius: 2px;
27
+ }
28
+ li p{
29
+ margin: 0.3em;
30
+ }
31
+ li{
32
+ list-style-type: disc;
33
+ }
34
+ a:link, a:visited{
35
+ color: #33e;
36
+ text-decoration: none;
37
+ }
38
+ a:hover{
39
+ color: #00f;
40
+ text-shadow:1px 1px 2px #ccf;
41
+ text-decoration:underline;
42
+ }
43
+ h1{
44
+ color: #999;
45
+ font-weight: bold;
46
+ }
47
+ h2{
48
+ border-bottom: 1px dotted #aaa;
49
+ margin-bottom: 1em;
50
+ color: #333;
51
+ }
52
+ h3{
53
+ color: #666;
54
+ }
55
+ .shadow{
56
+ -webkit-box-shadow:0 5px 15px #000;
57
+ -moz-box-shadow:0 5px 15px #000;
58
+ box-shadow:0 5px 15px #000;
59
+ }
60
+
61
+
62
+ .hll { background-color: #ffffcc }
63
+ .c { color: #888888 } /* Comment */
64
+ .err { color: #a61717; background-color: #e3d2d2 } /* Error */
65
+ .k { color: #008800; font-weight: bold } /* Keyword */
66
+ .cm { color: #888888 } /* Comment.Multiline */
67
+ .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
68
+ .c1 { color: #888888 } /* Comment.Single */
69
+ .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
70
+ .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
71
+ .ge { font-style: italic } /* Generic.Emph */
72
+ .gr { color: #aa0000 } /* Generic.Error */
73
+ .gh { color: #303030 } /* Generic.Heading */
74
+ .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
75
+ .go { color: #888888 } /* Generic.Output */
76
+ .gp { color: #555555 } /* Generic.Prompt */
77
+ .gs { font-weight: bold } /* Generic.Strong */
78
+ .gu { color: #606060 } /* Generic.Subheading */
79
+ .gt { color: #aa0000 } /* Generic.Traceback */
80
+ .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
81
+ .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
82
+ .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
83
+ .kp { color: #008800 } /* Keyword.Pseudo */
84
+ .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
85
+ .kt { color: #888888; font-weight: bold } /* Keyword.Type */
86
+ .m { color: #0000DD; font-weight: bold } /* Literal.Number */
87
+ .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
88
+ .na { color: #336699 } /* Name.Attribute */
89
+ .nb { color: #003388 } /* Name.Builtin */
90
+ .nc { color: #bb0066; font-weight: bold } /* Name.Class */
91
+ .no { color: #003366; font-weight: bold } /* Name.Constant */
92
+ .nd { color: #555555 } /* Name.Decorator */
93
+ .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
94
+ .nf { color: #0066bb; font-weight: bold } /* Name.Function */
95
+ .nl { color: #336699; font-style: italic } /* Name.Label */
96
+ .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
97
+ .py { color: #336699; font-weight: bold } /* Name.Property */
98
+ .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
99
+ .nv { color: #336699 } /* Name.Variable */
100
+ .ow { color: #008800 } /* Operator.Word */
101
+ .w { color: #bbbbbb } /* Text.Whitespace */
102
+ .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
103
+ .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
104
+ .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
105
+ .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
106
+ .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
107
+ .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
108
+ .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
109
+ .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
110
+ .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
111
+ .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
112
+ .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
113
+ .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
114
+ .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
115
+ .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
116
+ .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
117
+ .bp { color: #003388 } /* Name.Builtin.Pseudo */
118
+ .vc { color: #336699 } /* Name.Variable.Class */
119
+ .vg { color: #dd7700 } /* Name.Variable.Global */
120
+ .vi { color: #3333bb } /* Name.Variable.Instance */
121
+ .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
@@ -0,0 +1,4 @@
1
+ div#readme-html {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
@@ -0,0 +1,35 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Mudrat Projector Readme</title>
5
+ <link rel="stylesheet" type="css" media="all" href="github.css" />
6
+ <link rel="stylesheet" type="css" media="all" href="readme.css" />
7
+ </head>
8
+ <body>
9
+ <div id="readme-html">
10
+ </div><!-- /#readme-html -->
11
+ </body>
12
+ <script type="text/javascript">
13
+ window.onload = function() {
14
+ (function() {
15
+ var reload_css = function() {
16
+ var links = document.getElementsByTagName("link");
17
+ for(var cc = 0; cc < links.length; cc++) {
18
+ var link = links[cc];
19
+ if(link.rel == "stylesheet") {
20
+ link.href += "?";
21
+ }
22
+ }
23
+ };
24
+
25
+ var readme_html = document.getElementById("readme-html");
26
+ var web_socket_url = "ws://" + window.location.host + window.location.pathname;
27
+ var ws = new WebSocket(web_socket_url);
28
+ ws.onmessage = function(m) {
29
+ readme_html.innerHTML = m.data;
30
+ reload_css();
31
+ };
32
+ })();
33
+ };
34
+ </script>
35
+ </html>
data/test/sample.md ADDED
@@ -0,0 +1,9 @@
1
+ # This is a test
2
+
3
+ ```ruby
4
+ class RubySyntax
5
+ def works?
6
+ true
7
+ end
8
+ end
9
+ ```
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gfm_live_preview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - ntl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: github-linguist
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: github-markdown
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: listen
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sinatra
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sinatra-websocket
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Live preview your github flavored markdown file (with syntax highlighting!).
112
+ email:
113
+ - nathanladd+github@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .ruby-version
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - gfm_live_preview.gemspec
125
+ - lib/gfm_live_preview.rb
126
+ - lib/gfm_live_preview/server.rb
127
+ - lib/gfm_live_preview/syntax_highlighter.rb
128
+ - lib/gfm_live_preview/version.rb
129
+ - lib/public/github.css
130
+ - lib/public/readme.css
131
+ - lib/views/index.erb
132
+ - test/sample.md
133
+ homepage: https://github.com/ntl/gfm_live_preview
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.0.3
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Live preview your github flavored markdown file (with syntax highlighting!).
157
+ Loads via sinatra on port 31337 of localhost.
158
+ test_files:
159
+ - test/sample.md
160
+ has_rdoc: