ghpreview-instant_markdown_d 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 347040a9ee2ee3ff65fc0e34a214b5c2c4fa2270
4
+ data.tar.gz: 6fe7ddc9a1b6b93249ee420549286675dd220e26
5
+ SHA512:
6
+ metadata.gz: 87080b216e6730fbba0601ebe8b3b8d3e9d1b2b16d0dc3dc21bfead446af03f8418908545c1c77bc981850834fb076f93c7b0a5a2bc0ba6f8c0ce17aa90b0035
7
+ data.tar.gz: 6ef39275e745806aaa10459c386d53c5e8aeb9c70b39580d8e24d19d35847cec792c5382b66086de05451d1eeee9e5a3781c59927dea95d59c7fa9dfd7ed5261
@@ -0,0 +1,18 @@
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
18
+ vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ghpreview-instant_markdown_d.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yuichi TANIKAWA
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.
@@ -0,0 +1,42 @@
1
+ # GHPreview::InstantMarkdownD
2
+
3
+ GHPreview::InstantMarkdownD is a small server that is compatible with [instant-markdown-d](https://github.com/suan/instant-markdown-d).
4
+ It uses `ghpreview` for previewing Markdown files.
5
+
6
+ See also
7
+ * [ghpreview](https://github.com/neo/ghpreview )
8
+ * [instant-markdown-d](https://github.com/suan/instant-markdown-d )
9
+
10
+ ## Prerequisites
11
+
12
+ You'll need the icu library.
13
+
14
+ If you're on a Mac
15
+
16
+ ```bash
17
+ $ brew install icu4c
18
+ ```
19
+
20
+ or on Ubuntu
21
+
22
+ ```bash
23
+ $ sudo apt-get install libicu-dev
24
+ ```
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ $ gem install ghpreview-instant_markdown_d
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ See [instant-markdown-d](https://github.com/suan/instant-markdown-d ).
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ghpreview/instant_markdown_d'
4
+
5
+ GHPreview::InstantMarkdownD::Previewer.new
@@ -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 'ghpreview/instant_markdown_d/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ghpreview-instant_markdown_d"
8
+ spec.version = GHPreview::InstantMarkdownD::VERSION
9
+ spec.authors = ["Yuichi TANIKAWA"]
10
+ spec.email = ["t.yuichi111@gmail.com"]
11
+ spec.summary = %q{Small server running ghpreview compatible with instant-markdown-d}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_dependency 'ghpreview', '~> 0.1'
22
+ spec.add_dependency 'rack', '~> 1.5'
23
+ spec.add_dependency 'thin', '~> 1.6'
24
+ spec.add_dependency 'faye-websocket', '~> 0.7'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ end
@@ -0,0 +1,2 @@
1
+ require_relative 'instant_markdown_d/version'
2
+ require_relative 'instant_markdown_d/previewer'
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <%= stylesheet_links %>
6
+ <style>
7
+ body { padding: 30px 0; }
8
+ #readme { width: 914px; margin: 0 auto; }
9
+ </style>
10
+ <script>
11
+ var socket = new EventSource('/');
12
+
13
+ socket.onopen = function() {
14
+ console.log('OPEN');
15
+ };
16
+
17
+ socket.onmessage = function(event) {
18
+ console.log('MESSAGE: ' + event.data);
19
+ };
20
+
21
+ socket.onerror = function(event) {
22
+ console.log('ERROR: ' + event.message);
23
+ };
24
+
25
+ socket.addEventListener('preview', function(event) {
26
+ document.getElementsByClassName('markdown-body')[0].innerHTML = event.data;
27
+ });
28
+
29
+ socket.addEventListener('die', function(event) {
30
+ socket.close();
31
+ console.log('DIE');
32
+ });
33
+ </script>
34
+ </head>
35
+ <body>
36
+ <div id="readme">
37
+ <article class="markdown-body">
38
+ </article>
39
+ </div>
40
+ </body>
41
+ </html>
@@ -0,0 +1,9 @@
1
+ require 'ghpreview/wrapper'
2
+
3
+ GHPreview::Wrapper.class_eval do
4
+ remove_const :STYLED_TEMPLATE_FILEPATH
5
+ const_set :STYLED_TEMPLATE_FILEPATH, '/tmp/ghpreview-instant_makrdown_d-template.erb'
6
+
7
+ remove_const :RAW_TEMPLATE_FILEPATH
8
+ const_set :RAW_TEMPLATE_FILEPATH, "#{File.dirname(__FILE__)}/template.erb"
9
+ end
@@ -0,0 +1,24 @@
1
+ require 'eventmachine'
2
+
3
+ require_relative 'server'
4
+ require_relative 'viewer'
5
+ require_relative 'extension/ghpreview/wrapper'
6
+
7
+ module GHPreview
8
+ module InstantMarkdownD
9
+ class Previewer
10
+ HOST = 'localhost'
11
+ PORT = 8090
12
+
13
+ def initialize
14
+ Wrapper.generate_template_with_fingerprinted_stylesheet_links
15
+
16
+ EM.defer do
17
+ Viewer.open_url HOST, PORT
18
+ end
19
+
20
+ Server.run HOST, PORT
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'faye/websocket'
2
+
3
+ module GHPreview
4
+ module InstantMarkdownD
5
+ class Sender
6
+ def self.setup
7
+ Faye::WebSocket.load_adapter('thin')
8
+ end
9
+
10
+ def self.request?(env)
11
+ Faye::EventSource.eventsource?(env)
12
+ end
13
+
14
+ def self.response(env)
15
+ @es ||= Faye::EventSource.new(env)
16
+ @es.onclose = ->(event) { @es = nil }
17
+ @es.rack_response
18
+ end
19
+
20
+ def self.send(content, event)
21
+ @es.send(content, event: event.to_s) if @es
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,54 @@
1
+ require 'rack/request'
2
+ require 'rack/response'
3
+ require 'eventmachine'
4
+ require 'ghpreview/converter'
5
+
6
+ require_relative 'sender'
7
+
8
+ module GHPreview
9
+ module InstantMarkdownD
10
+ class Server
11
+
12
+ def self.run(host, port)
13
+ Sender.setup
14
+ Rack::Handler::Thin.run new, Host: host, Port: port
15
+ end
16
+
17
+ def call(env)
18
+ if Sender.request? env
19
+ puts 'connetion establish!'
20
+
21
+ Sender.response env
22
+
23
+ else
24
+ req = Rack::Request.new(env)
25
+
26
+ case req.request_method
27
+ when 'GET'
28
+ Rack::Response.new(Wrapper.wrap_html nil).finish
29
+
30
+ when 'PUT'
31
+ EM.defer do
32
+ md = req.body.read
33
+ html = Converter.to_html md
34
+ Sender.send html, :preview
35
+ end
36
+
37
+ [200, {}, []]
38
+
39
+ when 'DELETE'
40
+ EM.add_timer(1) do
41
+ Sender.send 'die', :die
42
+ Process.kill('TERM', Process.pid)
43
+ end
44
+
45
+ [200, {}, []]
46
+
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module GHPreview
2
+ module InstantMarkdownD
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module GHPreview
2
+ module InstantMarkdownD
3
+ class Viewer
4
+ def self.open_url(host, port)
5
+ command = if RUBY_PLATFORM =~ /linux/
6
+ 'xdg-open'
7
+ else
8
+ 'open'
9
+ end
10
+ `#{command} http://#{host}:#{port}`
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe GHPreview::InstantMarkdownD do
4
+ it 'should have a version number' do
5
+ GHPreview::InstantMarkdownD::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'ghpreview/instant_markdown_d'
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ghpreview-instant_markdown_d
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Yuichi TANIKAWA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ghpreview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thin
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faye-websocket
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
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: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Small server running ghpreview compatible with instant-markdown-d
112
+ email:
113
+ - t.yuichi111@gmail.com
114
+ executables:
115
+ - ghpreview-instant_markdown_d
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/ghpreview-instant_markdown_d
127
+ - ghpreview-instant_markdown_d.gemspec
128
+ - lib/ghpreview/instant_markdown_d.rb
129
+ - lib/ghpreview/instant_markdown_d/extension/ghpreview/template.erb
130
+ - lib/ghpreview/instant_markdown_d/extension/ghpreview/wrapper.rb
131
+ - lib/ghpreview/instant_markdown_d/previewer.rb
132
+ - lib/ghpreview/instant_markdown_d/sender.rb
133
+ - lib/ghpreview/instant_markdown_d/server.rb
134
+ - lib/ghpreview/instant_markdown_d/version.rb
135
+ - lib/ghpreview/instant_markdown_d/viewer.rb
136
+ - spec/ghpreview/instant_markdown_d_spec.rb
137
+ - spec/spec_helper.rb
138
+ homepage: ''
139
+ licenses:
140
+ - MIT
141
+ metadata: {}
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 2.2.2
159
+ signing_key:
160
+ specification_version: 4
161
+ summary: Small server running ghpreview compatible with instant-markdown-d
162
+ test_files:
163
+ - spec/ghpreview/instant_markdown_d_spec.rb
164
+ - spec/spec_helper.rb