cheatly 0.1.0 → 0.1.1
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 +4 -4
- data/lib/cheatly/adapter/file.rb +0 -2
- data/lib/cheatly/adapter/github.rb +5 -3
- data/lib/cheatly/cli.rb +8 -6
- data/lib/cheatly/renderer.rb +7 -5
- data/lib/cheatly/sheet.rb +11 -8
- data/lib/cheatly/version.rb +1 -1
- data/sheets/gpg.md +36 -0
- data/sheets/{markdown.yml → markdown.md} +15 -15
- data/sheets/migrations.md +4 -0
- data/test/cli_test.rb +22 -0
- data/test/sheet_test.rb +32 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a95708a0ba7e2cd6ae42d96ccb21f5831f625b
|
4
|
+
data.tar.gz: 72ef8506ad5d566176224a1b46bb0320e7e831d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 119a38f79205a13aaed68d23659eac99c361e458b31c5d029320e256ab7c0c1a7cf1e05541620e7ef7efc9fb9a1519fead2304099ec39a0f74a357d636c737e5
|
7
|
+
data.tar.gz: 3a08fe096011cdf93edd25a45e715d528039c14c2a09d99fcc41fca4e8b7e24939f20f45447ebdbef5df59c846adbb1b2b1347d001da83ac6c7827c9d37bc7af
|
data/lib/cheatly/adapter/file.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require "base64"
|
2
|
-
require "yaml"
|
3
|
-
|
4
2
|
require "octokit"
|
5
3
|
|
6
4
|
module Cheatly
|
@@ -19,7 +17,11 @@ module Cheatly
|
|
19
17
|
response.map { |f| f.name.gsub(/\.[a-z]+\z/, '') }
|
20
18
|
end
|
21
19
|
|
22
|
-
def create
|
20
|
+
def create(name, body)
|
21
|
+
raise NotImplementedError
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(name, body)
|
23
25
|
raise NotImplementedError
|
24
26
|
end
|
25
27
|
end
|
data/lib/cheatly/cli.rb
CHANGED
@@ -15,6 +15,8 @@ module Cheatly
|
|
15
15
|
|
16
16
|
class_option :local, type: :boolean, aliases: "-l", desc: "Run using local file system"
|
17
17
|
|
18
|
+
class_option :nopaginate, type: :boolean, desc: "Disable pagination"
|
19
|
+
|
18
20
|
desc "show SHEET_NAME", "show a cheat sheet"
|
19
21
|
def show(handle)
|
20
22
|
sheet = model.find(handle)
|
@@ -22,7 +24,7 @@ module Cheatly
|
|
22
24
|
puts "Sheet not found, run 'cheatly list' to see the availables."
|
23
25
|
return
|
24
26
|
end
|
25
|
-
page
|
27
|
+
page unless options[:nopaginate]
|
26
28
|
renderer = Renderer.new
|
27
29
|
md = Redcarpet::Markdown.new(renderer, no_intra_emphasis: true)
|
28
30
|
puts md.render(sheet.to_s)
|
@@ -31,7 +33,7 @@ module Cheatly
|
|
31
33
|
desc "list sheets", "list all available sheets"
|
32
34
|
def list
|
33
35
|
sheets = model.all
|
34
|
-
page
|
36
|
+
page unless options[:nopaginate]
|
35
37
|
puts "List of available cheat-sheets:"
|
36
38
|
sheets.each do |sheet|
|
37
39
|
puts " #{sheet.title}"
|
@@ -40,14 +42,14 @@ module Cheatly
|
|
40
42
|
|
41
43
|
desc "create SHEET_NAME", "create a new sheet cheat"
|
42
44
|
def create(handle)
|
43
|
-
sheet =
|
45
|
+
sheet = LocalSheet.new(handle)
|
44
46
|
sheet.body = write_to_tempfile(handle)
|
45
47
|
sheet.save
|
46
48
|
end
|
47
49
|
|
48
50
|
desc "edit SHEET_NAME", "edit an existent sheet cheat"
|
49
51
|
def edit(handle)
|
50
|
-
sheet =
|
52
|
+
sheet = LocalSheet.find(handle)
|
51
53
|
sheet.body = write_to_tempfile(handle, sheet.body)
|
52
54
|
sheet.save
|
53
55
|
end
|
@@ -67,14 +69,14 @@ module Cheatly
|
|
67
69
|
|
68
70
|
def model
|
69
71
|
if options[:local]
|
70
|
-
|
72
|
+
LocalSheet
|
71
73
|
else
|
72
74
|
Sheet
|
73
75
|
end
|
74
76
|
end
|
75
77
|
|
76
78
|
def write_to_tempfile(title, body = nil)
|
77
|
-
tempfile = Tempfile.new(title + '.
|
79
|
+
tempfile = Tempfile.new(title + '.md')
|
78
80
|
tempfile.write(body) if body
|
79
81
|
tempfile.close
|
80
82
|
system "#{editor} #{tempfile.path}"
|
data/lib/cheatly/renderer.rb
CHANGED
@@ -17,11 +17,13 @@ module Cheatly
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def header(title, level)
|
20
|
-
sep =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
sep =
|
21
|
+
case level
|
22
|
+
when 1 then '='
|
23
|
+
when 2 then '+'
|
24
|
+
when 3 then '-'
|
25
|
+
else ''
|
26
|
+
end
|
25
27
|
|
26
28
|
"\n#{title.bold}\n#{(sep * title.length).bold}\n"
|
27
29
|
end
|
data/lib/cheatly/sheet.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Cheatly
|
2
2
|
class Sheet
|
3
|
-
attr_accessor :title, :body
|
3
|
+
attr_accessor :title, :body, :persisted
|
4
4
|
|
5
5
|
def initialize(title, body = nil, options = {})
|
6
6
|
@title, @body = title, body
|
@@ -13,6 +13,7 @@ module Cheatly
|
|
13
13
|
|
14
14
|
def create
|
15
15
|
adapter.create(title, body)
|
16
|
+
@persisted = true
|
16
17
|
end
|
17
18
|
|
18
19
|
def update
|
@@ -29,8 +30,9 @@ module Cheatly
|
|
29
30
|
|
30
31
|
def self.find(name)
|
31
32
|
body = adapter.find(name)
|
32
|
-
|
33
|
-
rescue Octokit::NotFound
|
33
|
+
self.new(name, body, persisted: true)
|
34
|
+
rescue Octokit::NotFound, Octokit::TooManyRequests
|
35
|
+
puts "Octokit error."
|
34
36
|
nil
|
35
37
|
rescue RuntimeError => e
|
36
38
|
puts e.message
|
@@ -45,15 +47,16 @@ module Cheatly
|
|
45
47
|
@adapter ||= Cheatly::Adapter::GitHub.new
|
46
48
|
end
|
47
49
|
|
48
|
-
def self.with_file_adapter
|
49
|
-
@adapter = Cheatly::Adapter::File.new
|
50
|
-
self
|
51
|
-
end
|
52
|
-
|
53
50
|
private
|
54
51
|
|
55
52
|
def adapter
|
56
53
|
self.class.adapter
|
57
54
|
end
|
58
55
|
end
|
56
|
+
|
57
|
+
class LocalSheet < Sheet
|
58
|
+
def self.adapter
|
59
|
+
@adapter ||= Cheatly::Adapter::File.new
|
60
|
+
end
|
61
|
+
end
|
59
62
|
end
|
data/lib/cheatly/version.rb
CHANGED
data/sheets/gpg.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# GPG
|
2
|
+
|
3
|
+
## Encrypt/Decrypt data
|
4
|
+
### To encrypt data:
|
5
|
+
gpg -e -u "Sender User Name" -r "Receiver User Name" somefile
|
6
|
+
|
7
|
+
### To decrypt data:
|
8
|
+
gpg -d mydata.tar.gpg
|
9
|
+
|
10
|
+
## Keys manipulation
|
11
|
+
### Create a key:
|
12
|
+
gpg --gen-key
|
13
|
+
|
14
|
+
### Export a key:
|
15
|
+
gpg --export -a "User Name" > public.key
|
16
|
+
|
17
|
+
### Export a private key:
|
18
|
+
gpg --export-secret-key -a "User Name" > private.key
|
19
|
+
|
20
|
+
### Import a friend's public key:
|
21
|
+
gpg --import public.key
|
22
|
+
|
23
|
+
### Import a private key:
|
24
|
+
gpg --allow-secret-key-import --import private.key
|
25
|
+
|
26
|
+
### Delete a public key:
|
27
|
+
gpg --delete-key "User Name"
|
28
|
+
|
29
|
+
### Delete a private key:
|
30
|
+
gpg --delete-secret-key "User Name"
|
31
|
+
|
32
|
+
### To list the keys in your public key ring:
|
33
|
+
gpg --list-keys
|
34
|
+
|
35
|
+
### To list the keys in your secret key ring:
|
36
|
+
gpg --list-secret-keys
|
@@ -1,30 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Headings:
|
1
|
+
# markdown
|
2
|
+
|
3
|
+
## Headings:
|
4
4
|
|
5
5
|
# h1 => <h1>h1</h1>
|
6
6
|
## h2 => <h2>h2</h2>
|
7
7
|
...
|
8
8
|
###### h6 => <h6>h6</h6>
|
9
9
|
|
10
|
-
Paragraphs
|
10
|
+
## Paragraphs
|
11
11
|
|
12
12
|
Separate paragraphs with double newlines. => <p>Separate paragraphs with double newlines.</p>
|
13
13
|
|
14
14
|
This is a second paragraph. => <p>This is a second paragraph.
|
15
15
|
This is not a third paragraph. => This is not a third paragraph.</p>
|
16
16
|
|
17
|
-
Blockquotes:
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
## Blockquotes:
|
18
|
+
=> <blockquote>
|
19
|
+
> This is a quote. => <p>This is a quote. You can use multiple lines.</p>
|
20
|
+
> You can use multiple lines. => </blockquote>
|
21
21
|
|
22
|
-
Code:
|
22
|
+
## Code:
|
23
23
|
|
24
|
-
|
24
|
+
`code goes here` => <code>code goes here</code>
|
25
25
|
|
26
|
-
Lists:
|
27
|
-
|
26
|
+
## Lists:
|
27
|
+
=> <ul>
|
28
28
|
* item 1 => <li>item 1</li>
|
29
29
|
* item 2 => <li>item 2</li>
|
30
30
|
* item 3 => <li>item 3</li>
|
@@ -36,15 +36,15 @@ markdown: |
|
|
36
36
|
1. item 3 => <li>item 3</li>
|
37
37
|
=> </ol>
|
38
38
|
|
39
|
-
Inline:
|
39
|
+
## Inline:
|
40
40
|
|
41
41
|
*emphasis* => <em>emphasis</em>
|
42
42
|
**strong** => <strong>strong</strong>
|
43
43
|
|
44
|
-
Links:
|
44
|
+
## Links:
|
45
45
|
|
46
46
|
[Text to display](http://example.com/) => <a href='http://example.com'>Text to display</a>
|
47
47
|
|
48
|
-
Images:
|
48
|
+
## Images:
|
49
49
|
|
50
50
|
 => <img src='/path/to/image.jpg alt='alt text' />
|
data/sheets/migrations.md
CHANGED
data/test/cli_test.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class CliTest < MiniTest::Test
|
4
|
+
|
5
|
+
def test_list
|
6
|
+
cli = Cheatly::CLI.new([], nopaginate: true)
|
7
|
+
cli.list
|
8
|
+
|
9
|
+
cli = Cheatly::CLI.new([], local: true, nopaginate: true)
|
10
|
+
cli.list
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_show
|
14
|
+
cli = Cheatly::CLI.new([], nopaginate: true)
|
15
|
+
cli.show "help"
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_help
|
19
|
+
cli = Cheatly::CLI.new([], nopaginate: true)
|
20
|
+
cli.help
|
21
|
+
end
|
22
|
+
end
|
data/test/sheet_test.rb
CHANGED
@@ -8,11 +8,41 @@ class SheetTest < MiniTest::Test
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def test_sheet_find
|
11
|
-
|
12
|
-
assert
|
11
|
+
assert Cheatly::Sheet.find("bash")
|
12
|
+
assert Cheatly::LocalSheet.find("bash")
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_sheet_not_found
|
16
16
|
assert_nil Cheatly::Sheet.find("foo")
|
17
17
|
end
|
18
|
+
|
19
|
+
def test_write_sheet
|
20
|
+
sheet = Cheatly::Sheet.new("foo")
|
21
|
+
assert_raises(NotImplementedError) { sheet.save }
|
22
|
+
|
23
|
+
sheet = Cheatly::LocalSheet.new("foobar")
|
24
|
+
sheet.body = "foobar"
|
25
|
+
sheet.save
|
26
|
+
|
27
|
+
assert_nil Cheatly::Sheet.find("foobar")
|
28
|
+
assert Cheatly::LocalSheet.find("foobar")
|
29
|
+
ensure
|
30
|
+
FileUtils.rm "sheets/foobar.md"
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_update_sheet
|
34
|
+
sheet = Cheatly::LocalSheet.new("bar")
|
35
|
+
sheet.body = "foo"
|
36
|
+
sheet.save
|
37
|
+
|
38
|
+
assert sheet.persisted
|
39
|
+
|
40
|
+
sheet.body = "foo"
|
41
|
+
sheet.save
|
42
|
+
|
43
|
+
assert sheet = Cheatly::LocalSheet.find("bar")
|
44
|
+
assert_equal "foo", sheet.body
|
45
|
+
ensure
|
46
|
+
FileUtils.rm "sheets/bar.md"
|
47
|
+
end
|
18
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cheatly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arthur Neves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -150,11 +150,13 @@ files:
|
|
150
150
|
- sheets/bash.md
|
151
151
|
- sheets/exceptions.md
|
152
152
|
- sheets/gem_release.md
|
153
|
+
- sheets/gpg.md
|
153
154
|
- sheets/help.md
|
154
|
-
- sheets/markdown.
|
155
|
+
- sheets/markdown.md
|
155
156
|
- sheets/migrations.md
|
156
157
|
- sheets/sprintf.md
|
157
158
|
- sheets/status_codes.md
|
159
|
+
- test/cli_test.rb
|
158
160
|
- test/sheet_test.rb
|
159
161
|
- test/test_helper.rb
|
160
162
|
homepage: ''
|
@@ -182,5 +184,6 @@ signing_key:
|
|
182
184
|
specification_version: 4
|
183
185
|
summary: A cheat-sheet cli for a cheat repository
|
184
186
|
test_files:
|
187
|
+
- test/cli_test.rb
|
185
188
|
- test/sheet_test.rb
|
186
189
|
- test/test_helper.rb
|