showdown 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 958ee315105469253d9fbd832c171b2ef1f15e19
4
+ data.tar.gz: 13016588093dae912458b1d099bd795eb9cbdb16
5
+ SHA512:
6
+ metadata.gz: 0cbb041f83eb57906b36bcbb10c9079786da5feabd8c2ecd3a51df6d3c8ba4c6995ebbf40f9a8c3f4fedc30648b64269eabec9a29ad9f13261a931230417908c
7
+ data.tar.gz: daa52d897ba08d125fd118a2b76ab4cb809d28cb4b32674b4470cd0fef79601a25fdee8f0826759f8e7be295efc31be56407ec4e9776f07133eae09aabf2b854
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ Style/LineLength:
2
+ Max: 99
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in md_preview.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Fumitaka Tokumitsu
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,21 @@
1
+ # md_preview
2
+
3
+ Near-Real time Markdown viewer.
4
+
5
+ ## Installation
6
+
7
+ Install it yourself as:
8
+
9
+ $ gem install md_preview
10
+
11
+ ## Usage
12
+
13
+ $ md_preview /path/to/your/file.md
14
+
15
+ ## Contributing
16
+
17
+ 1. Fork it ( https://github.com/[my-github-username]/md_preview/fork )
18
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
19
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
20
+ 4. Push to the branch (`git push origin my-new-feature`)
21
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/md_preview ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ PORT = 3000
3
+ RACKUP_FILE_PATH = "#{File.expand_path('../../lib', __FILE__)}/config.ru"
4
+
5
+ Signal.trap(:INT) do
6
+ puts 'SIGINT'
7
+ exit(0)
8
+ end
9
+
10
+ def help
11
+ $stdout.puts 'usage: md_preview <path>'
12
+ end
13
+
14
+ unless ARGV[0]
15
+ help
16
+ exit 1
17
+ end
18
+
19
+ TARGET_PATH = File.expand_path(ARGV[0])
20
+
21
+ system "TARGET_PATH=#{TARGET_PATH} thin -R #{RACKUP_FILE_PATH} -p #{PORT} start"
data/lib/config.ru ADDED
@@ -0,0 +1,14 @@
1
+ lib = File.expand_path('..', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'md_preview'
5
+
6
+ puts "tartget: #{ENV['TARGET_PATH']}"
7
+
8
+ map '/' do
9
+ run Rack::File.new(File.expand_path(File.dirname(__FILE__)) + '/html/index.html')
10
+ end
11
+
12
+ map '/websocket' do
13
+ run MdPreview::RackApp.new # backend: { debug: true }
14
+ end
@@ -0,0 +1,40 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8"/>
5
+ <title>Sample of web_socket.js</title>
6
+ <script type="text/javascript">
7
+ var ws;
8
+ function init() {
9
+ ws = new WebSocket("ws://localhost:3000/websocket");
10
+
11
+ ws.onopen = function() {
12
+ // output("onopend");
13
+ }
14
+
15
+ ws.onmessage = function(e) {
16
+ // console.log(e.data);
17
+ document.getElementById('output').innerHTML = e.data;
18
+ }
19
+
20
+ ws.onclose = function() {
21
+ // output("onclose");
22
+ }
23
+
24
+ ws.onerror = function() {
25
+ // output("onerror");
26
+ }
27
+ }
28
+
29
+ function output(str) {
30
+ var log = document.getElementById('log');
31
+ var escaped = str.replace(/&/, "&amp;").replace(/</, "&lt;").replace(/>/, "&gt;").replace(/"/, "&quot;");
32
+ log.innerHTML = escaped + '<br>' + log.innerHTML;
33
+ }
34
+ </script>
35
+ </head>
36
+ <body onload="init();">
37
+ <div id="log"></div>
38
+ <div id="output"></div>
39
+ </body>
40
+ </html>
@@ -0,0 +1,3 @@
1
+ module MdPreview
2
+ VERSION = "0.0.1"
3
+ end
data/lib/md_preview.rb ADDED
@@ -0,0 +1,59 @@
1
+ require 'rack/websocket'
2
+ require 'md_preview/version'
3
+ require 'redcarpet'
4
+
5
+ module MdPreview
6
+ # Convert markdown to html.
7
+ module Converter
8
+ def markdown
9
+ @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML)
10
+ end
11
+
12
+ def converted_html
13
+ markdown.render(File.open(@target_path).read)
14
+ end
15
+ end
16
+
17
+ # Check file change.
18
+ module WatchDog
19
+ def file_changed?
20
+ @old_file_mtime ||= File.stat(@target_path).mtime
21
+
22
+ if File.stat(@target_path).mtime > @old_file_mtime
23
+ @old_file_mtime = File.stat(@target_path).mtime
24
+ true
25
+ else
26
+ false
27
+ end
28
+ end
29
+ end
30
+
31
+ # Rack application class
32
+ class RackApp < Rack::WebSocket::Application
33
+ include Converter
34
+ include WatchDog
35
+
36
+ def initialize
37
+ @target_path = ENV['TARGET_PATH']
38
+ end
39
+
40
+ def on_open(_env)
41
+ puts 'client connected'
42
+
43
+ send_data converted_html
44
+
45
+ EM.add_periodic_timer(0.5) do
46
+ send_data converted_html if file_changed?
47
+ end
48
+ end
49
+
50
+ def on_message(_env, msg)
51
+ puts "message received: #{msg}"
52
+ EM.send_data "Message: #{msg}"
53
+ end
54
+
55
+ def on_close(_env)
56
+ puts 'client disconnected'
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'md_preview/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "showdown"
8
+ spec.version = MdPreview::VERSION
9
+ spec.authors = ["Fumitaka Tokumitsu"]
10
+ spec.email = ["toku345@gmail.com"]
11
+ spec.summary = 'Near-Real time markdown preview'
12
+ spec.description = 'Near-Real time markdown preview'
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_runtime_dependency 'websocket-rack'
22
+ spec.add_runtime_dependency 'redcarpet'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe MdPreview do
4
+ it 'has a version number' do
5
+ expect(MdPreview::VERSION).not_to be nil
6
+ end
7
+ end
8
+
9
+ describe MdPreview::RackApp do
10
+ end
11
+
12
+ describe MdPreview::Converter do
13
+ include MdPreview::Converter
14
+
15
+ before(:all) { @target_path = File.expand_path('../support/test.md', __FILE__) }
16
+
17
+ describe '#converted_html' do
18
+ let(:expected_html) { "<p>This is <em>bongos</em>, indeed.</p>\n" }
19
+
20
+ context '@markdown is nil' do
21
+ before(:each) { @markdown = nil }
22
+
23
+ it 'return converted html' do
24
+ expect(converted_html).to eq expected_html
25
+ end
26
+ end
27
+
28
+ context '@markdown is not nil' do
29
+ before(:all) { @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) }
30
+
31
+ it 'return converted html' do
32
+ expect(converted_html).to eq expected_html
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ describe MdPreview::WatchDog do
39
+ include MdPreview::WatchDog
40
+
41
+ before(:all) { @target_path = File.expand_path('../support/test.md', __FILE__) }
42
+
43
+ describe '#file_changed?' do
44
+ context 'file is chenged' do
45
+ before(:each) do
46
+ test_time = Time.now
47
+ FileUtils.touch(@target_path, mtime: test_time)
48
+ @old_file_mtime = test_time - 60 # a minute ago
49
+ end
50
+
51
+ it { expect(file_changed?).to eq true }
52
+ end
53
+
54
+ context "file isn't chenge" do
55
+ before(:each) do
56
+ test_time = Time.now
57
+ FileUtils.touch(@target_path, mtime: test_time)
58
+ @old_file_mtime = test_time
59
+ end
60
+
61
+ it { expect(file_changed?).to eq false }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'md_preview'
@@ -0,0 +1 @@
1
+ This is *bongos*, indeed.
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: showdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fumitaka Tokumitsu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: websocket-rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redcarpet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
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: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Near-Real time markdown preview
84
+ email:
85
+ - toku345@gmail.com
86
+ executables:
87
+ - md_preview
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/md_preview
100
+ - lib/config.ru
101
+ - lib/html/index.html
102
+ - lib/md_preview.rb
103
+ - lib/md_preview/version.rb
104
+ - md_preview.gemspec
105
+ - spec/md_preview_spec.rb
106
+ - spec/spec_helper.rb
107
+ - spec/support/test.md
108
+ homepage: ''
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.2.2
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Near-Real time markdown preview
132
+ test_files:
133
+ - spec/md_preview_spec.rb
134
+ - spec/spec_helper.rb
135
+ - spec/support/test.md