github-markdown-preview 1.5.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 +7 -0
- data/.gitignore +50 -0
- data/.travis.yml +7 -0
- data/CHANGELOG.md +29 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +7 -0
- data/Rakefile +11 -0
- data/bin/github-markdown-preview +51 -0
- data/contributing.md +20 -0
- data/data/css/github.css +1 -0
- data/data/css/github2.css +1 -0
- data/github-markdown-preview.gemspec +28 -0
- data/lib/github-markdown-preview.rb +8 -0
- data/lib/github-markdown-preview/html_preview.rb +151 -0
- data/lib/github-markdown-preview/resources.rb +9 -0
- data/lib/github-markdown-preview/version.rb +3 -0
- data/readme.md +75 -0
- data/sample.png +0 -0
- data/sample_preview.md +22 -0
- data/test/github-markdown-preview_test.rb +25 -0
- data/test/html_preview_test.rb +132 -0
- metadata +127 -0
data/sample.png
ADDED
Binary file
|
data/sample_preview.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Sample Preview Render
|
2
|
+
|
3
|
+
Uses github css to preview not only structure and content, but also _look_ and **feel** (awkward bolding and italics for demonstration purposes)
|
4
|
+
|
5
|
+
Emoji support: :rocket:
|
6
|
+
|
7
|
+
Relative links: [readme.md](readme.md)
|
8
|
+
|
9
|
+
Syntax highlighting example courtesy of http://stackoverflow.com/a/705754
|
10
|
+
```ruby
|
11
|
+
class HelloWorld
|
12
|
+
def initialize(name)
|
13
|
+
@name = name.capitalize
|
14
|
+
end
|
15
|
+
def sayHi
|
16
|
+
puts "Hello #{@name}!"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
hello = HelloWorld.new("World")
|
21
|
+
hello.sayHi
|
22
|
+
```
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
|
3
|
+
class TestBin < Minitest::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@ghp_scipt = File.join(File.dirname(__FILE__), '..', 'bin', 'github-markdown-preview')
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_no_params
|
9
|
+
IO.popen("bundle exec #{@ghp_scipt}") do |io|
|
10
|
+
assert_match /Usage.*/, io.read, 'No parameter call should output usage'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_version_ouput
|
15
|
+
IO.popen("bundle exec #{@ghp_scipt} -v") do |io|
|
16
|
+
assert_match GithubMarkdownPreview::VERSION, io.read, '-v call should output version'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_file_not_found
|
21
|
+
IO.popen("bundle exec #{@ghp_scipt} this_file_does_not_exist 2>&1") do |io|
|
22
|
+
assert_match /.*No such file/, io.read, 'Bad file name should get a helpful error'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'github-markdown-preview'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'tmpdir'
|
4
|
+
|
5
|
+
class TestHtmlPreview < Minitest::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@ghp = GithubMarkdownPreview::HtmlPreview
|
9
|
+
@source_file_path = File.join(Dir.tmpdir, 'test.md')
|
10
|
+
end
|
11
|
+
|
12
|
+
def write(file_name, text)
|
13
|
+
File.open(file_name, 'w') { |f| f.write(text) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def read(file_name)
|
17
|
+
assert File.exist?(file_name), "Cannot read file: #{file_name}"
|
18
|
+
File.open(file_name).read
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Helper method based on Fowler's advice in http://martinfowler.com/articles/nonDeterminism.html#AsynchronousBehavior
|
23
|
+
#
|
24
|
+
# Requires you pass a block which returns true when your asynchronous process has finished
|
25
|
+
def wait_for_async_operation
|
26
|
+
start_time = Time.now
|
27
|
+
wait_limit = 5
|
28
|
+
polling_interval = 0.1
|
29
|
+
|
30
|
+
until yield
|
31
|
+
if Time.now - start_time > wait_limit
|
32
|
+
flunk 'Async operation should not time out.'
|
33
|
+
end
|
34
|
+
sleep (polling_interval)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_create_preview_on_init
|
39
|
+
write(@source_file_path, '## foo')
|
40
|
+
markdown_preview = @ghp.new( @source_file_path )
|
41
|
+
assert_match /.*<h2>foo<\/h2>.*/,
|
42
|
+
read(markdown_preview.preview_file),
|
43
|
+
'Preview should be correct on initialization'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_wrapper_markup_included
|
47
|
+
write(@source_file_path, '## foo')
|
48
|
+
markdown_preview = @ghp.new( @source_file_path )
|
49
|
+
assert_equal markdown_preview.wrap_preview("<h2>foo<\/h2>"),
|
50
|
+
read(markdown_preview.preview_file),
|
51
|
+
'Wrapper markup should be in preview file'
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_update_preview
|
55
|
+
write(@source_file_path, '## foo')
|
56
|
+
markdown_preview = @ghp.new( @source_file_path )
|
57
|
+
assert_match /.*<h2>foo<\/h2>.*/, read(markdown_preview.preview_file),
|
58
|
+
'Preview should be initially rendered correctly'
|
59
|
+
|
60
|
+
write(@source_file_path, '## foo bar')
|
61
|
+
markdown_preview.update
|
62
|
+
assert_match /.*<h2>foo bar<\/h2>.*/,
|
63
|
+
read(markdown_preview.preview_file),
|
64
|
+
'Preview should be updated correctly'
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_preview_beside_src_file
|
68
|
+
write(@source_file_path, '## foo')
|
69
|
+
markdown_preview = @ghp.new( @source_file_path )
|
70
|
+
assert_equal File.dirname(@source_file_path),
|
71
|
+
File.dirname(markdown_preview.preview_file),
|
72
|
+
'Preview file should be in same dir as source file'
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_preview_delete
|
76
|
+
write(@source_file_path, '## foo')
|
77
|
+
markdown_preview = @ghp.new( @source_file_path )
|
78
|
+
markdown_preview.delete
|
79
|
+
assert !File.exist?(markdown_preview.preview_file), 'Preview file should been deleted'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_preview_delete_on_exit
|
83
|
+
at_exit { assert !File.exist?(@source_file_path + '.html'), 'Preview file should be deleted on exit' }
|
84
|
+
write(@source_file_path, '## foo')
|
85
|
+
markdown_preview = @ghp.new( @source_file_path )
|
86
|
+
markdown_preview.delete_on_exit = true
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_update_callbacks
|
90
|
+
write(@source_file_path, '## foo')
|
91
|
+
markdown_preview = @ghp.new( @source_file_path )
|
92
|
+
first_update_callback_called = false
|
93
|
+
second_update_callback_called = false
|
94
|
+
markdown_preview.on_update { first_update_callback_called = true }
|
95
|
+
markdown_preview.on_update { second_update_callback_called = true }
|
96
|
+
markdown_preview.update
|
97
|
+
assert first_update_callback_called, 'First update callback should be called'
|
98
|
+
assert second_update_callback_called, 'Second update callback should be called'
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_watch_source_file
|
102
|
+
write(@source_file_path, '## foo')
|
103
|
+
markdown_preview = @ghp.new( @source_file_path )
|
104
|
+
updated_by_watch = false
|
105
|
+
markdown_preview.on_update { updated_by_watch = true }
|
106
|
+
markdown_preview.watch
|
107
|
+
|
108
|
+
write(@source_file_path, '## foo bar')
|
109
|
+
|
110
|
+
wait_for_async_operation { updated_by_watch }
|
111
|
+
|
112
|
+
assert_match /.*<h2>foo bar<\/h2>.*/,
|
113
|
+
read(markdown_preview.preview_file)
|
114
|
+
'Preview file should be updated correctly by file watcher'
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_file_not_found
|
118
|
+
assert_raises GithubMarkdownPreview::FileNotFoundError do
|
119
|
+
@ghp.new('this_file_does_not_exist')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_file_deleted_behind_us
|
124
|
+
assert_raises GithubMarkdownPreview::FileNotFoundError do
|
125
|
+
write(@source_file_path, '## foo')
|
126
|
+
markdown_preview = @ghp.new( @source_file_path )
|
127
|
+
File.delete(@source_file_path)
|
128
|
+
markdown_preview.update
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: github-markdown-preview
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Marcotte
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2013-05-11 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: listen
|
16
|
+
prerelease: false
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.3
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: *id001
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: github-linguist
|
26
|
+
prerelease: false
|
27
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 2.6.7
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id002
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: html-pipeline
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.0.12
|
42
|
+
type: :runtime
|
43
|
+
version_requirements: *id003
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: minitest
|
46
|
+
prerelease: false
|
47
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- &id006
|
50
|
+
- ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
type: :development
|
54
|
+
version_requirements: *id004
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
prerelease: false
|
58
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "1.3"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id005
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rake
|
67
|
+
prerelease: false
|
68
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- *id006
|
71
|
+
type: :development
|
72
|
+
version_requirements: *id007
|
73
|
+
description: Use your favorite editor plus the usual edit/refresh cycle to quickly write and polish your Github markdown files.
|
74
|
+
email: dmarcotte@gmail.com
|
75
|
+
executables:
|
76
|
+
- github-markdown-preview
|
77
|
+
extensions: []
|
78
|
+
|
79
|
+
extra_rdoc_files: []
|
80
|
+
|
81
|
+
files:
|
82
|
+
- .gitignore
|
83
|
+
- .travis.yml
|
84
|
+
- CHANGELOG.md
|
85
|
+
- Gemfile
|
86
|
+
- LICENSE.txt
|
87
|
+
- Rakefile
|
88
|
+
- bin/github-markdown-preview
|
89
|
+
- contributing.md
|
90
|
+
- data/css/github.css
|
91
|
+
- data/css/github2.css
|
92
|
+
- github-markdown-preview.gemspec
|
93
|
+
- lib/github-markdown-preview.rb
|
94
|
+
- lib/github-markdown-preview/html_preview.rb
|
95
|
+
- lib/github-markdown-preview/resources.rb
|
96
|
+
- lib/github-markdown-preview/version.rb
|
97
|
+
- readme.md
|
98
|
+
- sample.png
|
99
|
+
- sample_preview.md
|
100
|
+
- test/github-markdown-preview_test.rb
|
101
|
+
- test/html_preview_test.rb
|
102
|
+
homepage: https://github.com/dmarcotte/github-markdown-preview
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- *id006
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- *id006
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.0.3
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Local previews for Github Flavored Markdown files
|
125
|
+
test_files:
|
126
|
+
- test/github-markdown-preview_test.rb
|
127
|
+
- test/html_preview_test.rb
|