octodown 0.0.1alpha1 → 0.1.0beta1

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: f3011aaac61ee304bc3439716128d596750f8492
4
+ data.tar.gz: f391bb139714707d690efd512f2145d3565cf339
5
+ SHA512:
6
+ metadata.gz: 438fc034632fc7760d0bd91bc9448f34a9ca551ddf3fef6d13f44f798ea90a1c74d874a24b75eeb7a5fd837c25a432adcf078cb48f46deedda403d68945552bf
7
+ data.tar.gz: 114b94fffa16b686ef1fd6c2dee9f652cb40cf4d9dd60a9579d326ec1654bf17b68aaecae7c7192b13b8b64f5518d2a1151eebe5fe73e09433be2e6453316111
checksums.yaml.gz.sig ADDED
Binary file
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  :octocat: octodown
2
2
  ==================
3
+ [![GemVersion](https://badge.fury.io/rb/octodown.svg)](http://badge.fury.io/rb/octodown)
3
4
  [![Build Status](https://travis-ci.org/ianks/octodown.svg)](https://travis-ci.org/ianks/octodown)
4
5
 
5
6
  Ever wanted to easily preview what you markdown would look like *exactly* on
@@ -9,7 +10,7 @@ you. Dead simple. Never get caught writing ugly markdown again.
9
10
  ## Features:
10
11
 
11
12
  * Uses the same markdown parsers and CSS as Github for true duplication.
12
- - Yes emojis *are* included :clap:
13
+ - Yes emojis *are* included
13
14
  * Fast. `octodown` uses native parsers to ensure performance.
14
15
  * Multiple CSS styles. Choose from either:
15
16
  - `$ octodown --style atom README.md`
@@ -26,17 +27,28 @@ you. Dead simple. Never get caught writing ugly markdown again.
26
27
  2. If you have a non-system Ruby (*highly recommended*):
27
28
  * `$ gem install octodown`
28
29
  3. Else:
29
- * `$ sudo gem install octodown --no-ri --no-rdoc`
30
+ * `$ sudo gem install octodown`
30
31
 
31
32
  ## Usage
32
33
 
34
+ 1. Basic:
33
35
  $ octodown README.md
36
+ 2. Markdown preview styling
37
+ $ octodown --style atom README.md
38
+ 3. *nix lovers
39
+ $ echo '# Hello world!' | octodown --raw > index.html
34
40
 
35
41
  ## Notes
36
42
 
37
43
  1. With no arguments given, octodown will read STDIN until EOF is reached. In
38
44
  order to work with this mode, type what you want into the input, then press
39
45
  `Ctrl-D` when finished.
46
+ 2. octodown attempts to use default OS support for opening HTML files from
47
+ terminal. In Mac, this would be the `open` command; for Linux it is either
48
+ `xdg-open` or `x-www-browser`. If these are not set, octodown will not
49
+ automatically open the file in the browser. If octodown doesn't have the
50
+ commands neccesary to open files in a browser, please consider opening a pull
51
+ request to add support!
40
52
 
41
53
  ## Contributing
42
54
 
Binary file
data/bin/octodown CHANGED
@@ -2,58 +2,41 @@
2
2
 
3
3
  require 'octodown'
4
4
  require 'optparse'
5
- require 'pathname'
6
- require 'securerandom'
7
5
 
8
6
  include Octodown
9
7
 
10
8
  options = {}
11
9
 
12
10
  OptionParser.new do |opts|
13
- opts.banner = "Usage: octodown [options]"
11
+ opts.banner = 'Usage: octodown [options]'
14
12
 
15
- opts.on("-s", "--style [STYLE]", [:github, :atom], "Choose style (atom, github)") do |s|
13
+ opts.on('-s', '--style [STYLE]', [:github, :atom], 'Choose style (atom, github)') do |s|
16
14
  options[:style] = s
17
15
  end
18
16
 
19
- opts.on_tail("-h", "--help", "Show this message") do
17
+ opts.on('-r', '--[no-]raw', 'Print raw HTML to STDOUT') do |r|
18
+ options[:raw] = r
19
+ end
20
+
21
+ opts.on_tail('-h', '--help', 'Show this message') do
20
22
  puts opts
21
23
  exit
22
24
  end
23
25
  end.parse!
24
26
 
25
- def create_html_from_md(filename, template)
26
- unstyled_html = Renderer::GithubMarkdown.new(filename).to_html
27
- Renderer::HTML.new(unstyled_html, template).render
28
- end
29
-
30
-
31
- def open_browser_cmd
32
- if RUBY_PLATFORM.include? 'darwin'
33
- return '/usr/bin/open'
34
- elsif RUBY_PLATFORM.include? 'linux'
35
- candidates = %w(/usr/bin/xdg-open /usr/bin/x-www-browser)
36
-
37
- candidates.each do |cmd|
38
- return cmd if File.exists? cmd
39
- end
40
- else
41
- return 'start'
42
- end
43
-
44
- false
45
- end
27
+ def main(options)
28
+ include Octodown::Support
46
29
 
47
- def open_in_browser(html)
48
- tmp = Pathname.new "/tmp/octodown_#{SecureRandom.hex}.html"
49
- file = File.open(tmp, 'w') { |file| file.write html }
30
+ input_contents = ARGF.read
31
+ style = options[:style] || 'github'
50
32
 
51
- if cmd = open_browser_cmd
52
- Process.spawn(cmd, tmp.to_s, [:out, :err] => File.open('/dev/null').fileno)
33
+ if options[:raw]
34
+ puts Helpers.markdown_to_raw_html input_contents, style
53
35
  else
54
- raise RuntimeError, 'No compatible shell command to open file in browser'
36
+ browser = Browser.new
37
+ html_file = Helpers.markdown_to_html input_contents, style
38
+ browser.open html_file
55
39
  end
56
40
  end
57
41
 
58
- html = create_html_from_md ARGF.read, options[:style] || 'github'
59
- open_in_browser html
42
+ main(options)
@@ -0,0 +1,33 @@
1
+ module Octodown
2
+ module Support
3
+ class Browser
4
+ def initialize
5
+ @cmd = determine_browser_open_cmd
6
+ end
7
+
8
+ def open(file)
9
+ out_file = File.open('/dev/null').fileno
10
+ Process.spawn cmd, file.path, [:out, :err] => out_file
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :cmd
16
+
17
+ def determine_browser_open_cmd
18
+ open_in_browser_candidates.detect { |cmd| File.exists? cmd }
19
+ end
20
+
21
+ def open_in_browser_candidates
22
+ # TODO: More robust detection for OS
23
+ if RUBY_PLATFORM.include? 'darwin'
24
+ %w(/usr/bin/open)
25
+ elsif RUBY_PLATFORM.include? 'linux'
26
+ %w(/usr/bin/xdg-open /usr/bin/x-www-browser)
27
+ else
28
+ %w(start)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Octodown
2
+ module Support
3
+ module Helpers
4
+ # TODO: Find a better home for this logic
5
+ def self.markdown_to_html(contents, template)
6
+ html = markdown_to_raw_html(contents, template)
7
+ tmp = Octodown::Support::HTMLFile.new 'octodown'
8
+ tmp.persistent_write html
9
+ end
10
+
11
+ def self.markdown_to_raw_html(contents, template)
12
+ unstyled_html = Octodown::Renderer::GithubMarkdown.new(contents).to_html
13
+ Octodown::Renderer::HTML.new(unstyled_html, template).render
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ require 'tempfile'
2
+ require 'fileutils'
3
+
4
+ module Octodown
5
+ module Support
6
+ class HTMLFile < Tempfile
7
+ def persist
8
+ ObjectSpace.undefine_finalizer self
9
+ self
10
+ end
11
+
12
+ def persistent_write(content)
13
+ self.write content
14
+ self.close
15
+ self.persist
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,7 +3,7 @@
3
3
  <html>
4
4
  <head>
5
5
  <title><%= title %></title>
6
-
6
+ <link rel="shortcut icon" href="https://raw.githubusercontent.com/ianks/octodown/master/assets/favicon.png" type="image/png" />
7
7
  <style>
8
8
  <%= stylesheet %>
9
9
  </style>
@@ -1,3 +1,3 @@
1
1
  module Octodown
2
- VERSION = '0.0.1alpha1'
2
+ VERSION = '0.1.0beta1'
3
3
  end
data/lib/octodown.rb CHANGED
@@ -1,6 +1,9 @@
1
- require 'octodown/version'
2
1
  require 'octodown/renderer/github_markdown'
3
2
  require 'octodown/renderer/html'
3
+ require 'octodown/support/browser'
4
+ require 'octodown/support/helpers'
5
+ require 'octodown/support/html_file'
6
+ require 'octodown/version'
4
7
 
5
8
  module Octodown
6
9
  def self.root
data/octodown.gemspec CHANGED
@@ -17,15 +17,15 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ['lib']
19
19
 
20
- spec.add_dependency 'github-markup'
21
- spec.add_dependency 'github-linguist'
22
- spec.add_dependency 'html-pipeline'
23
- spec.add_dependency 'sanitize'
24
- spec.add_dependency 'github-markdown'
25
- spec.add_dependency 'gemoji'
26
- spec.add_dependency 'pygments.rb'
20
+ spec.add_dependency 'github-markup', '~> 1.3.1'
21
+ spec.add_dependency 'github-linguist', '~> 4.2.5'
22
+ spec.add_dependency 'html-pipeline', '~> 1.11.0'
23
+ spec.add_dependency 'sanitize', '~> 3.1.0'
24
+ spec.add_dependency 'github-markdown', '~> 0.6.8'
25
+ spec.add_dependency 'gemoji', '~> 2.1.0'
26
+ spec.add_dependency 'pygments.rb', '~> 0.6.0'
27
27
 
28
- spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
29
29
  spec.add_development_dependency 'bundler', '~> 1.7'
30
- spec.add_development_dependency 'rake', '~> 10.0'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
31
  end
@@ -0,0 +1,10 @@
1
+ describe Octodown::Support::Browser do
2
+ subject { Octodown::Support::Browser.new }
3
+
4
+ describe 'open' do
5
+ it 'opens file in browser' do
6
+ expect(subject).to receive(:open).with('dummy/test.md')
7
+ subject.open 'dummy/test.md'
8
+ end
9
+ end
10
+ end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,174 +1,175 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octodown
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1alpha1
5
- prerelease: 5
4
+ version: 0.1.0beta1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ian Ker-Seymer
9
8
  autorequire:
10
9
  bindir: bin
11
- cert_chain: []
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDfDCCAmSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBCMRQwEgYDVQQDDAtpLmtl
14
+ cnNleW1lcjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYD
15
+ Y29tMB4XDTE0MTIxOTA3MjMxOFoXDTE1MTIxOTA3MjMxOFowQjEUMBIGA1UEAwwL
16
+ aS5rZXJzZXltZXIxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
17
+ ARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKVwZDJ78nh4
18
+ 49fzhIhSG4hjXcMU2KWwEQIWXp1gESBSvj4NrcygsNvo+y+cbsxB021Fbtw4D1m/
19
+ Lhqxs8l0MewdaDxwIARu57e+hSX9DpwuDSJzoOBfpWpvdj9QOT0ByeGARCD3Dz4P
20
+ l4zsZW2HYK3/zWdWznwjh6Jlb/zQaWUgJBanMs15IODVpJ01IW2YqNxDgE1/aaiv
21
+ kcEE04a3XlNXvRqz0EtDgg6EJdsArVFdtoxT8IGBEvgiltiXusNWfRdAFdtU+Phg
22
+ Wt/zC43O+nMc8vKQIf7z8gY6ESFTLKYKZEKSAQMzK0EtN/QiTPrrUFLL9WZ4VACg
23
+ lLmpPiOdIGsCAwEAAaN9MHswCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
24
+ BBYEFE9Q3qbzppIUo0ihetWNmRiDLUV8MCAGA1UdEQQZMBeBFWkua2Vyc2V5bWVy
25
+ QGdtYWlsLmNvbTAgBgNVHRIEGTAXgRVpLmtlcnNleW1lckBnbWFpbC5jb20wDQYJ
26
+ KoZIhvcNAQEFBQADggEBAHn26tJwdKaN5Rz8nI6weXyYhvdm9zH1RGD4/ksMPbvu
27
+ nX16vDqnXHM5KHeC1NgS1ESRlQ0grI5VZlNstFjQXFqbsdAP+UfsnLGpZc4x4C2O
28
+ gTyUm/TyRZpgGdauRjoR2arPc5M5RDp1xY2XsXKfdWyWlZt0CnKrTezSCyNriHZC
29
+ 8lBhjW73DtD3kmT411PpnN2GMaQQ3svM03XFBQUdyw0gvrKFRv56nVCrGND+KSs3
30
+ YGBeYMyEy7Q4wf7k4k5yyDUZyyaeg0DF/kNEN5llspJ9DHMP2cQqOiH+IQSNiUhR
31
+ 32sJqaZRHeJLDhZPLi5yXItTsQnPy6uob2oyypwFYTM=
32
+ -----END CERTIFICATE-----
12
33
  date: 2014-12-25 00:00:00.000000000 Z
13
34
  dependencies:
14
35
  - !ruby/object:Gem::Dependency
15
36
  name: github-markup
16
37
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
38
  requirements:
19
- - - ! '>='
39
+ - - "~>"
20
40
  - !ruby/object:Gem::Version
21
- version: '0'
41
+ version: 1.3.1
22
42
  type: :runtime
23
43
  prerelease: false
24
44
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
45
  requirements:
27
- - - ! '>='
46
+ - - "~>"
28
47
  - !ruby/object:Gem::Version
29
- version: '0'
48
+ version: 1.3.1
30
49
  - !ruby/object:Gem::Dependency
31
50
  name: github-linguist
32
51
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
52
  requirements:
35
- - - ! '>='
53
+ - - "~>"
36
54
  - !ruby/object:Gem::Version
37
- version: '0'
55
+ version: 4.2.5
38
56
  type: :runtime
39
57
  prerelease: false
40
58
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
59
  requirements:
43
- - - ! '>='
60
+ - - "~>"
44
61
  - !ruby/object:Gem::Version
45
- version: '0'
62
+ version: 4.2.5
46
63
  - !ruby/object:Gem::Dependency
47
64
  name: html-pipeline
48
65
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
66
  requirements:
51
- - - ! '>='
67
+ - - "~>"
52
68
  - !ruby/object:Gem::Version
53
- version: '0'
69
+ version: 1.11.0
54
70
  type: :runtime
55
71
  prerelease: false
56
72
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
73
  requirements:
59
- - - ! '>='
74
+ - - "~>"
60
75
  - !ruby/object:Gem::Version
61
- version: '0'
76
+ version: 1.11.0
62
77
  - !ruby/object:Gem::Dependency
63
78
  name: sanitize
64
79
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
80
  requirements:
67
- - - ! '>='
81
+ - - "~>"
68
82
  - !ruby/object:Gem::Version
69
- version: '0'
83
+ version: 3.1.0
70
84
  type: :runtime
71
85
  prerelease: false
72
86
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
87
  requirements:
75
- - - ! '>='
88
+ - - "~>"
76
89
  - !ruby/object:Gem::Version
77
- version: '0'
90
+ version: 3.1.0
78
91
  - !ruby/object:Gem::Dependency
79
92
  name: github-markdown
80
93
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
94
  requirements:
83
- - - ! '>='
95
+ - - "~>"
84
96
  - !ruby/object:Gem::Version
85
- version: '0'
97
+ version: 0.6.8
86
98
  type: :runtime
87
99
  prerelease: false
88
100
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
101
  requirements:
91
- - - ! '>='
102
+ - - "~>"
92
103
  - !ruby/object:Gem::Version
93
- version: '0'
104
+ version: 0.6.8
94
105
  - !ruby/object:Gem::Dependency
95
106
  name: gemoji
96
107
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
108
  requirements:
99
- - - ! '>='
109
+ - - "~>"
100
110
  - !ruby/object:Gem::Version
101
- version: '0'
111
+ version: 2.1.0
102
112
  type: :runtime
103
113
  prerelease: false
104
114
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
115
  requirements:
107
- - - ! '>='
116
+ - - "~>"
108
117
  - !ruby/object:Gem::Version
109
- version: '0'
118
+ version: 2.1.0
110
119
  - !ruby/object:Gem::Dependency
111
120
  name: pygments.rb
112
121
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
122
  requirements:
115
- - - ! '>='
123
+ - - "~>"
116
124
  - !ruby/object:Gem::Version
117
- version: '0'
125
+ version: 0.6.0
118
126
  type: :runtime
119
127
  prerelease: false
120
128
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
129
  requirements:
123
- - - ! '>='
130
+ - - "~>"
124
131
  - !ruby/object:Gem::Version
125
- version: '0'
132
+ version: 0.6.0
126
133
  - !ruby/object:Gem::Dependency
127
134
  name: rspec
128
135
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
136
  requirements:
131
- - - ! '>='
137
+ - - "~>"
132
138
  - !ruby/object:Gem::Version
133
- version: '0'
139
+ version: 3.1.0
134
140
  type: :development
135
141
  prerelease: false
136
142
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
143
  requirements:
139
- - - ! '>='
144
+ - - "~>"
140
145
  - !ruby/object:Gem::Version
141
- version: '0'
146
+ version: 3.1.0
142
147
  - !ruby/object:Gem::Dependency
143
148
  name: bundler
144
149
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
150
  requirements:
147
- - - ~>
151
+ - - "~>"
148
152
  - !ruby/object:Gem::Version
149
153
  version: '1.7'
150
154
  type: :development
151
155
  prerelease: false
152
156
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
157
  requirements:
155
- - - ~>
158
+ - - "~>"
156
159
  - !ruby/object:Gem::Version
157
160
  version: '1.7'
158
161
  - !ruby/object:Gem::Dependency
159
162
  name: rake
160
163
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
164
  requirements:
163
- - - ~>
165
+ - - "~>"
164
166
  - !ruby/object:Gem::Version
165
167
  version: '10.0'
166
168
  type: :development
167
169
  prerelease: false
168
170
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
171
  requirements:
171
- - - ~>
172
+ - - "~>"
172
173
  - !ruby/object:Gem::Version
173
174
  version: '10.0'
174
175
  description:
@@ -179,22 +180,27 @@ executables:
179
180
  extensions: []
180
181
  extra_rdoc_files: []
181
182
  files:
182
- - .gitignore
183
- - .rspec
184
- - .travis.yml
183
+ - ".gitignore"
184
+ - ".rspec"
185
+ - ".travis.yml"
185
186
  - Gemfile
186
187
  - LICENSE.txt
187
188
  - README.md
188
189
  - Rakefile
189
190
  - assets/atom.css
191
+ - assets/favicon.png
190
192
  - assets/github.css
191
193
  - bin/octodown
192
194
  - lib/octodown.rb
193
195
  - lib/octodown/renderer/github_markdown.rb
194
196
  - lib/octodown/renderer/html.rb
197
+ - lib/octodown/support/browser.rb
198
+ - lib/octodown/support/helpers.rb
199
+ - lib/octodown/support/html_file.rb
195
200
  - lib/octodown/template/octodown.html.erb
196
201
  - lib/octodown/version.rb
197
202
  - octodown.gemspec
203
+ - spec/browser_spec.rb
198
204
  - spec/dummy/test.md
199
205
  - spec/markdown_generation_spec.rb
200
206
  - spec/spec_helper.rb
@@ -202,29 +208,29 @@ files:
202
208
  homepage: https://github.com/ianks/octodown
203
209
  licenses:
204
210
  - MIT
211
+ metadata: {}
205
212
  post_install_message:
206
213
  rdoc_options: []
207
214
  require_paths:
208
215
  - lib
209
216
  required_ruby_version: !ruby/object:Gem::Requirement
210
- none: false
211
217
  requirements:
212
- - - ! '>='
218
+ - - ">="
213
219
  - !ruby/object:Gem::Version
214
220
  version: '0'
215
221
  required_rubygems_version: !ruby/object:Gem::Requirement
216
- none: false
217
222
  requirements:
218
- - - ! '>'
223
+ - - ">"
219
224
  - !ruby/object:Gem::Version
220
225
  version: 1.3.1
221
226
  requirements: []
222
227
  rubyforge_project:
223
- rubygems_version: 1.8.23.2
228
+ rubygems_version: 2.4.5
224
229
  signing_key:
225
- specification_version: 3
230
+ specification_version: 4
226
231
  summary: Simple and precise markdown previewing from your terminal.
227
232
  test_files:
233
+ - spec/browser_spec.rb
228
234
  - spec/dummy/test.md
229
235
  - spec/markdown_generation_spec.rb
230
236
  - spec/spec_helper.rb
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ s��{�� ��~"�BI���������J�.�$8�^T�����7�,]?��8\�kg�*��F�mw6RgkyY$����:���>Y6@&Z�x�c�����~���u=tY)���#t ��u\r�:��϶i�w���sS��´�� �"W�c���L�7��F&:�R�,