downterm 0.1.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: bbe4f92ac149f0ad1ecf96b5107fc0b8a7300cf3
4
+ data.tar.gz: 64307764bded34852704a7df86054ec4cb3cc0ce
5
+ SHA512:
6
+ metadata.gz: f2070bfdeb9cdde7477d44d40807ff1f74e4825abd6f21d7a3eb9e974583afa6d074c31c990679bab84b089626acf9f6069132f14e6be338648d88e76e680241
7
+ data.tar.gz: 521a3db1984a2d3f9711bd9ee4493215757a5bf5fe879086ebd9c014b870d10ce338790960d2067fd1a44b66b24e70da1ccde047f36cfeda9bb726e796427c27
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ /.bundle/
3
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in usaidwat.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Michael Dippery
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'downterm/version'
4
+
5
+ GEMSPEC = `git ls-files | grep gemspec`.chomp
6
+ GEM = "downterm-#{Downterm::VERSION}.gem"
7
+
8
+ desc "Build downterm.gem"
9
+ task :build => :perms do
10
+ system "gem", "build", GEMSPEC
11
+ end
12
+
13
+ desc "Ensure correct permissions for downterm.gem"
14
+ task :perms do
15
+ system "chmod", "-R", "a+rX", *`git ls-files`.chomp.split("\n")
16
+ end
17
+
18
+ desc "Install downterm.gem"
19
+ task :install => :build do
20
+ system "gem", "install", GEM
21
+ end
22
+
23
+ desc "Push gem to RubyGems"
24
+ task :release => :build do
25
+ system "git", "tag", "-s", "-m", "downterm v#{Downterm::VERSION}", "v#{Downterm::VERSION}"
26
+ system "gem", "push", GEM
27
+ end
28
+
29
+ desc "Clean built products"
30
+ task :clean do
31
+ rm Dir.glob("*.gem"), :verbose => true
32
+ end
33
+
34
+ task :default => :build
data/downterm.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'downterm/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'downterm'
8
+ gem.version = Downterm::VERSION
9
+ gem.licenses = ['MIT']
10
+ gem.authors = ['Michael Dippery']
11
+ gem.email = ['michael@monkey-robot.com']
12
+ gem.homepage = 'https://github.com/mdippery/downterm'
13
+ gem.description = 'Converts Markdown into text suitable for output to a terminal'
14
+ gem.summary = 'Converts Markdown into text suitable for output to a terminal'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.required_ruby_version = '>= 1.9.3'
22
+
23
+ gem.add_runtime_dependency('highline', '~> 1.7')
24
+ gem.add_runtime_dependency('rainbow', '~> 2.0')
25
+ gem.add_runtime_dependency('redcarpet', '~> 3.3')
26
+
27
+ gem.add_development_dependency('rspec', '~> 3.3')
28
+ end
data/lib/downterm.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'downterm/render'
2
+ require 'downterm/version'
@@ -0,0 +1,119 @@
1
+ require 'highline'
2
+ require 'rainbow'
3
+ require 'redcarpet'
4
+
5
+ module Downterm
6
+ module Render
7
+ class Terminal < Redcarpet::Render::Base
8
+ def paragraph(text)
9
+ "#{text}\n\n"
10
+ end
11
+
12
+ def normal_text(text)
13
+ text
14
+ end
15
+
16
+ def linebreak
17
+ "\n"
18
+ end
19
+
20
+ def header(text, header_level)
21
+ "#{'#' * header_level} #{text}\n\n"
22
+ end
23
+
24
+ def entity(text)
25
+ case text
26
+ when "&gt;" then return ">"
27
+ when "&lt;" then return "<"
28
+ when "&amp;" then return "&"
29
+ else return text
30
+ end
31
+ end
32
+
33
+ def emphasis(text)
34
+ Rainbow(text).underline.to_s
35
+ end
36
+
37
+ def double_emphasis(text)
38
+ Rainbow(text).bright.to_s
39
+ end
40
+
41
+ def triple_emphasis(text)
42
+ Rainbow(text).bright.underline.to_s
43
+ end
44
+
45
+ def link(link, link_title, content)
46
+ "#{Rainbow(content).underline} <#{link}>"
47
+ end
48
+
49
+ def autolink(link, link_type)
50
+ Rainbow(link).underline.to_s
51
+ end
52
+
53
+ def image(link, title, content)
54
+ Rainbow(link).underline.to_s
55
+ end
56
+
57
+ def codespan(code)
58
+ "`#{code}`"
59
+ end
60
+
61
+ def block_code(code, language)
62
+ code.split("\n").map { |line| " #{line}"}.join("\n")
63
+ end
64
+
65
+ def block_quote(quote)
66
+ quote.split("\n").map { |line| "> #{line}" }.join("\n")
67
+ end
68
+
69
+ def block_html(raw_html)
70
+ raw_html
71
+ end
72
+
73
+ def raw_html(raw_html)
74
+ raw_html
75
+ end
76
+
77
+ def strikethrough(text)
78
+ text
79
+ end
80
+
81
+ def superscript(text)
82
+ if text.length > 1
83
+ "^(#{text})"
84
+ else
85
+ "^#{text}"
86
+ end
87
+ end
88
+
89
+ def list(contents, list_type)
90
+ case list_type
91
+ when :unordered then return contents
92
+ when :ordered then return number_list(contents.split("\n")).join("\n")
93
+ end
94
+ end
95
+
96
+ def list_item(text, list_type)
97
+ case list_type
98
+ when :unordered then return "* #{text}"
99
+ when :ordered then return "#{text}"
100
+ end
101
+ end
102
+
103
+ def hrule
104
+ '-' * HighLine::SystemExtensions.terminal_size[0] + "\n\n"
105
+ end
106
+
107
+ def postprocess(full_document)
108
+ full_document.rstrip
109
+ end
110
+
111
+ private
112
+
113
+ def number_list(items)
114
+ width = items.count.to_s.length
115
+ (1..items.count).zip(items).map { |e| sprintf("%*d. %s", width, e[0], e[1]) }
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module Downterm
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,286 @@
1
+ require 'spec_helper'
2
+
3
+ module Downterm
4
+ module Render
5
+ describe Terminal do
6
+ let(:terminal) { Terminal.new }
7
+ let(:markdown) { Redcarpet::Markdown.new(terminal, :autolink => true,
8
+ :strikethrough => true,
9
+ :superscript => true) }
10
+
11
+ describe 'emphasized text' do
12
+ it 'is underlined' do
13
+ md = 'the word *italicized* is italicized'
14
+ expected = "the word #{Rainbow("italicized").underline} is italicized"
15
+ actual = markdown.render(md)
16
+ expect(actual).to eq(expected)
17
+ end
18
+
19
+ it 'is underlined when delineated by underscores' do
20
+ md = 'the word _italicized_ is italicized'
21
+ expected = "the word #{Rainbow("italicized").underline} is italicized"
22
+ actual = markdown.render(md)
23
+ expect(actual).to eq(expected)
24
+ end
25
+
26
+ it 'is bolded when it is doubly emphasized' do
27
+ md = 'the word **emphasized** is bolded'
28
+ expected = "the word #{Rainbow("emphasized").bright} is bolded"
29
+ actual = markdown.render(md)
30
+ expect(actual).to eq(expected)
31
+ end
32
+
33
+ it 'is bolded and underlined when triply emphasized' do
34
+ md = 'the word ***emphasized*** is emphatic'
35
+ expected = "the word #{Rainbow("emphasized").bright.underline} is emphatic"
36
+ actual = markdown.render(md)
37
+ expect(actual).to eq(expected)
38
+ end
39
+ end
40
+
41
+ describe 'superscript text' do
42
+ it 'is rendered verbatim' do
43
+ md = 'e = mc^2'
44
+ expected = md
45
+ actual = markdown.render(md)
46
+ expect(actual).to eq(expected)
47
+ end
48
+
49
+ it 'is rendered verbatim even when consisting of multiple characters' do
50
+ md = 'this gem is really cool^(not)'
51
+ expected = md
52
+ actual = markdown.render(md)
53
+ expect(actual).to eq(expected)
54
+ end
55
+ end
56
+
57
+ describe 'a list' do
58
+ it 'is rendered verbatim when ordered' do
59
+ md = [
60
+ 'This is a list:',
61
+ '',
62
+ '1. Item 1',
63
+ '2. Item 2',
64
+ ].join("\n")
65
+ expected = md
66
+ actual = markdown.render(md)
67
+ expect(actual).to eq(expected)
68
+ end
69
+
70
+ it 'is rendered verbatim when unordered' do
71
+ md = [
72
+ 'This is a list:',
73
+ '',
74
+ '* Item 1',
75
+ '* Item 2',
76
+ ].join("\n")
77
+ expected = md
78
+ actual = markdown.render(md)
79
+ expect(actual).to eq(expected)
80
+ end
81
+
82
+ it 'is right-aligned' do
83
+ md = [
84
+ 'This is a list:',
85
+ '',
86
+ '1. Item 1',
87
+ '2. Item 2',
88
+ '3. Item 3',
89
+ '4. Item 4',
90
+ '5. Item 5',
91
+ '6. Item 6',
92
+ '7. Item 7',
93
+ '8. Item 8',
94
+ '9. Item 9',
95
+ '10. Item 10',
96
+ '11. Item 11',
97
+ ].join("\n")
98
+ expected = [
99
+ 'This is a list:',
100
+ '',
101
+ ' 1. Item 1',
102
+ ' 2. Item 2',
103
+ ' 3. Item 3',
104
+ ' 4. Item 4',
105
+ ' 5. Item 5',
106
+ ' 6. Item 6',
107
+ ' 7. Item 7',
108
+ ' 8. Item 8',
109
+ ' 9. Item 9',
110
+ '10. Item 10',
111
+ '11. Item 11',
112
+ ].join("\n")
113
+ actual = markdown.render(md)
114
+ expect(actual).to eq(expected)
115
+ end
116
+ end
117
+
118
+ describe 'code' do
119
+ it 'is rendered verbatim when inline' do
120
+ md = '`import antigravity`'
121
+ expected = md
122
+ actual = markdown.render(md)
123
+ expect(actual).to eq(expected)
124
+ end
125
+
126
+ it 'is rendered verbatim when in a block' do
127
+ md = [
128
+ %q(This is some code:),
129
+ %q(),
130
+ %q( import antigravity),
131
+ %q( puts "I'm using Python!"),
132
+ ].join("\n")
133
+ expected = md
134
+ actual = markdown.render(md)
135
+ expect(actual).to eq(expected)
136
+ end
137
+ end
138
+
139
+ describe 'a horizontal rule' do
140
+ it 'is rendered as a series of dashes across the terminal' do
141
+ md = [
142
+ 'This is some text',
143
+ '',
144
+ '---',
145
+ '',
146
+ 'This is some more text',
147
+ ].join("\n")
148
+ expected = [
149
+ 'This is some text',
150
+ '',
151
+ '-' * HighLine::SystemExtensions.terminal_size[0],
152
+ '',
153
+ 'This is some more text',
154
+ ].join("\n")
155
+ actual = markdown.render(md)
156
+ expect(actual).to eq(expected)
157
+ end
158
+ end
159
+
160
+ describe 'a quote' do
161
+ it 'is rendered verbatim' do
162
+ md = [
163
+ 'This is a cool quote:',
164
+ '',
165
+ '> One, two! One, two! And through and through',
166
+ '> The vorpal blade went snicker-snack!',
167
+ '> He left it dead, and with its head',
168
+ '> He went galumphing back',
169
+ ].join("\n")
170
+ expected = md
171
+ actual = markdown.render(md)
172
+ expect(actual).to eq(expected)
173
+ end
174
+ end
175
+
176
+ describe 'strikethrough text' do
177
+ it 'is rendered dimmer than surrounding text' do
178
+ md = 'today is ~~beautiful~~ grey'
179
+ expected = "today is beautiful grey"
180
+ actual = markdown.render(md)
181
+ expect(actual).to eq(expected)
182
+ end
183
+ end
184
+
185
+ describe 'an image' do
186
+ it 'is printed as a link to the image file' do
187
+ md = '![Michael](http://monkey-robot.com/static/images/michael.png)'
188
+ expected = "#{Rainbow('http://monkey-robot.com/static/images/michael.png').underline}"
189
+ actual = markdown.render(md)
190
+ expect(actual).to eq(expected)
191
+ end
192
+ end
193
+
194
+ describe 'a link' do
195
+ it 'is formatted when it has a title' do
196
+ md = 'check out [my blog](http://monkey-robot.com/) please!'
197
+ expected = "check out #{Rainbow("my blog").underline} <http://monkey-robot.com/> please!"
198
+ actual = markdown.render(md)
199
+ expect(actual).to eq(expected)
200
+ end
201
+
202
+ it 'is formatted when it is created automatically' do
203
+ md = 'check out http://monkey-robot.com/'
204
+ expected = "check out #{Rainbow("http://monkey-robot.com/").underline}"
205
+ actual = markdown.render(md)
206
+ expect(actual).to eq(expected)
207
+ end
208
+ end
209
+
210
+ describe 'an entity' do
211
+ it 'is converted from &gt; to >' do
212
+ md = '-&gt; look at this!'
213
+ expected = '-> look at this!'
214
+ actual = markdown.render(md)
215
+ expect(actual).to eq(expected)
216
+ end
217
+
218
+ it 'is converted from &lt; to <' do
219
+ md = 'left &lt;&lt; shift'
220
+ expected = 'left << shift'
221
+ actual = markdown.render(md)
222
+ expect(actual).to eq(expected)
223
+ end
224
+
225
+ it 'is converted from &amp; to &' do
226
+ md = 'i like cake &amp; ice cream'
227
+ expected = 'i like cake & ice cream'
228
+ actual = markdown.render(md)
229
+ expect(actual).to eq(expected)
230
+ end
231
+ end
232
+
233
+ describe 'HTML' do
234
+ it 'is rendered verbatim when in a block' do
235
+ md = [
236
+ 'This is some HTML:',
237
+ '',
238
+ '<div><p><strong>This is HTML!</strong></p></div>',
239
+ '',
240
+ "And now we're back to plaintext.",
241
+ ].join("\n")
242
+ expected = md
243
+ actual = markdown.render(md)
244
+ expect(actual).to eq(expected)
245
+ end
246
+
247
+ it 'is rendered verbatim when inline' do
248
+ md = '<strong>This is HTML!</strong>'
249
+ expected = md
250
+ actual = markdown.render(md)
251
+ expect(actual).to eq(expected)
252
+ end
253
+ end
254
+
255
+ describe 'a header' do
256
+ it 'is rendered verbatim' do
257
+ md = [
258
+ "Here's some text",
259
+ '',
260
+ '## Header 2',
261
+ '',
262
+ 'And now a new section',
263
+ ].join("\n")
264
+ expected = md
265
+ actual = markdown.render(md)
266
+ expect(actual).to eq(expected)
267
+ end
268
+ end
269
+
270
+ describe 'a linebreak' do
271
+ it 'is rendered as a new line' do
272
+ md = [
273
+ 'Line 1 ',
274
+ 'Line 2',
275
+ ].join("\n")
276
+ expected = [
277
+ 'Line 1',
278
+ 'Line 2',
279
+ ].join("\n")
280
+ actual = markdown.render(md)
281
+ expect(actual).to eq(expected)
282
+ end
283
+ end
284
+ end
285
+ end
286
+ end
@@ -0,0 +1,4 @@
1
+ require 'highline'
2
+ require 'rainbow'
3
+ require 'redcarpet'
4
+ require 'downterm'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: downterm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Dippery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rainbow
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redcarpet
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: Converts Markdown into text suitable for output to a terminal
70
+ email:
71
+ - michael@monkey-robot.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - Rakefile
80
+ - downterm.gemspec
81
+ - lib/downterm.rb
82
+ - lib/downterm/render.rb
83
+ - lib/downterm/version.rb
84
+ - spec/downterm/render_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: https://github.com/mdippery/downterm
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.9.3
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.5
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Converts Markdown into text suitable for output to a terminal
110
+ test_files:
111
+ - spec/downterm/render_spec.rb
112
+ - spec/spec_helper.rb