hackpad-cli 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5037a0a37741a8faadffe8bcf9a879f9cdebc73d
4
- data.tar.gz: 13b30296a3f1bba92040cc4fd0938a2ccff19665
3
+ metadata.gz: 11393a54a4eee8671b2f1408c718cae2acf0636a
4
+ data.tar.gz: c8e34dc2fc56963f34fd9359d56567010571e5e1
5
5
  SHA512:
6
- metadata.gz: bcc048e283ead0d1eff603cab042d039aeef5c501c86599645eea8215c45a2144a2dc18d13cb4303de5d27f3ce6c8e2fd6a9f14b144472a4b5309ce02d30e575
7
- data.tar.gz: 35fe21d9f7ffee3887de231c4e736affbf5a686ff985d10f979b5897f036bc4cb3acfd8864e91ed957f16fff3edf58cb3e8cf200fa9234973b5f594ef77e4cd6
6
+ metadata.gz: 3bdad090ea55e18a3919a8b284d73e30578ddb2624b0f1b156f72f9b83c3c7cde85cdd31fe1fe8bd6bd54ce34318c50466a594b2737cdae534477222a255df50
7
+ data.tar.gz: 0efabd1139cea5ab5386f57f5d581631b497086c4d60b3623e886822efc61f2505ae71991f5d834fced5755ee8b2226daf30aa5d4d4cb7f8f4decfcd5637dfa5
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  Hackpad-cli changelog
2
2
  =====================
3
3
 
4
+ v0.1.2 - 2014-05-27
5
+ -------------------
6
+
7
+ - improve markdown cleanup:
8
+ - transform isolated bold in h3
9
+ - remove parasite lines in list that are left by non-displayed comments
10
+ - add a visual indication of currently used workspace in the `workspaces` command
11
+
4
12
  v0.1.1 - 2014-05-25
5
13
  -------------------
6
14
 
data/README.md CHANGED
@@ -13,7 +13,7 @@ This is a command-line utility to check and manipulate hackpad documents.
13
13
  It uses Hackpad REST API 1.0 https://hackpad.com/fQD2DRz22Wf and was tested with ruby 1.9.3 and 2.1.1.
14
14
 
15
15
  Initially this tool was created to overcome the frustration of the md export of pads,
16
- because we need to copy them to other places sometimes. Proper markdown would be appreciated. It does that by transforming the html in markdown with the https://github.com/xijo/reverse_markdown gem.
16
+ because we need to copy them to other places sometimes. Proper markdown would be appreciated. It does that by transforming the html in markdown with the https://github.com/xijo/reverse_markdown gem, and applying some extra cleaning over it.
17
17
 
18
18
  Offline hackpad reading
19
19
  -----------------------
data/hackpad-cli.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'thor'
22
- spec.add_dependency 'cliprompt', '~> 0.0.4'
22
+ spec.add_dependency 'cliprompt', '~> 0.0.5'
23
23
  spec.add_dependency 'paint'
24
24
  spec.add_dependency 'oauth'
25
25
  spec.add_dependency 'reverse_markdown'
@@ -1,6 +1,7 @@
1
1
  require 'oauth'
2
2
  require 'net/http'
3
3
  require 'json'
4
+ require 'reverse_markdown'
4
5
 
5
6
  module Hackpad
6
7
  module Cli
@@ -33,18 +34,35 @@ module Hackpad
33
34
  end
34
35
 
35
36
  def read(id, ext)
36
- get "/api/1.0/pad/#{id}/content.#{ext}", false
37
+ realext = (ext == 'md') ? 'html' : ext
38
+ get "/api/1.0/pad/#{id}/content.#{realext}", false, (ext == 'md')
37
39
  end
38
40
 
39
- def get(url, json = true)
41
+ def get(url, json = true, to_md = false)
40
42
  res = @token.get url, 'User-Agent' => "hackpad-cli v#{Hackpad::Cli::VERSION}"
41
43
  if res.is_a? Net::HTTPSuccess
42
- json ? JSON.parse(res.body) : res.body
44
+ if json
45
+ JSON.parse(res.body)
46
+ else
47
+ if to_md
48
+ cleanup_md(res.body)
49
+ else
50
+ res.body
51
+ end
52
+ end
43
53
  else
44
54
  fail ApiException, "HTTP error, code #{res.code}"
45
55
  end
46
56
  end
47
57
 
58
+ def cleanup_md(text)
59
+ back = ReverseMarkdown.convert(text, github_flavored: true).strip
60
+ back.sub!(/<head>.*<\/head>\n/m, '')
61
+ back.gsub!(/-([^\n]+)\n\n -/m, "-\\1\n -")
62
+ back.gsub!(/\n( )*-([^\n]+)\n?\n( )*-([^\n]+)\n?\n/m, "\n\\1-\\2\n\\3-\\4\n")
63
+ back.gsub(/\n\n\*\*([^\*]+)\*\*\n\n/, "\n\n### \\1\n\n")
64
+ end
65
+
48
66
  end
49
67
  end
50
68
  end
@@ -1,4 +1,3 @@
1
- require 'reverse_markdown'
2
1
  require 'paint'
3
2
 
4
3
  require_relative 'config'
@@ -27,6 +26,9 @@ module Hackpad
27
26
 
28
27
  def workspaces
29
28
  @config.workspaces.each do |s|
29
+ if s.name == @config.workspace
30
+ s.name = "> #{s.name}"
31
+ end
30
32
  table s.name, s.site
31
33
  end
32
34
  end
@@ -81,14 +83,9 @@ module Hackpad
81
83
  end
82
84
 
83
85
  def show(id, format)
84
- ext = (format == 'md') ? 'html' : format
85
86
  pad = Pad.new id
86
- pad.load ext
87
- if format == 'md'
88
- @output.puts ReverseMarkdown.convert(pad.content, github_flavored: true)
89
- else
90
- @output.puts pad.content
91
- end
87
+ pad.load format
88
+ @output.puts pad.content
92
89
  end
93
90
 
94
91
  private
@@ -59,7 +59,6 @@ module Hackpad
59
59
  Store.exist? 'meta', @id
60
60
  end
61
61
 
62
-
63
62
  end
64
63
  end
65
64
  end
@@ -1,5 +1,5 @@
1
1
  module Hackpad
2
2
  module Cli
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -44,11 +44,22 @@ describe Hackpad::Cli::Api do
44
44
 
45
45
  describe '.read' do
46
46
  before { Hackpad::Cli::Api.prepare config }
47
- it 'returns expected json' do
48
- stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/content.html')
49
- .to_return(body: '<b>blah</b>', status: 200)
50
- expect(subject.read('aaa', 'html')).to eq('<b>blah</b>')
47
+ context 'when we want html,' do
48
+ before { stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/content.html')
49
+ .to_return(body: '<b>blah</b>', status: 200) }
50
+ it { expect(subject.read('aaa', 'html')).to eq('<b>blah</b>') }
51
+ end
52
+ context 'when we want txt,' do
53
+ before { stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/content.txt')
54
+ .to_return(body: 'blah', status: 200) }
55
+ it { expect(subject.read('aaa', 'txt')).to eq('blah') }
51
56
  end
57
+ context 'when we want md,' do
58
+ before { stub_request(:get, 'http://x.hackpad.com/api/1.0/pad/aaa/content.html')
59
+ .to_return(body: '<b>blah</b>', status: 200) }
60
+ it { expect(subject.read('aaa', 'md')).to eq('**blah**') }
61
+ end
62
+
52
63
  end
53
64
 
54
65
  describe '.get' do
@@ -49,7 +49,7 @@ describe Hackpad::Cli::Client do
49
49
  after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
50
50
 
51
51
  it do
52
- expect(output).to receive(:printf).with(format, 'default', 'http://example.com')
52
+ expect(output).to receive(:printf).with(format, '> default', 'http://example.com')
53
53
  expect(output).to receive(:printf).with(format, 'default2', 'http://2.example.com')
54
54
  client.workspaces
55
55
  end
@@ -66,9 +66,7 @@ describe Hackpad::Cli::Client do
66
66
  after { FileUtils.rm workspacefile2 if File.exist?(workspacefile2) }
67
67
 
68
68
  it do
69
- expect(output).to receive(:puts).with('What workspace do you want to use as default from now on?')
70
- expect(output).to receive(:printf).with("> %-3s %s\n", 0, "default")
71
- expect(output).to receive(:printf).with(" %-3s %s\n", 1, "default2")
69
+ expect(output).to receive(:print).with("What workspace do you want to use as default from now on? \n> 0 default\n 1 default2\nChoose a number: [0] ")
72
70
  client.default
73
71
  expect(YAML.load_file(configfile)['workspace']).to eq 'default2'
74
72
  end
@@ -240,12 +238,7 @@ describe Hackpad::Cli::Client do
240
238
  end
241
239
 
242
240
  context 'when a markdown version is asked,' do
243
- before { pad.stub(:content).and_return('<ul><li>this is content</li></ul>') }
244
- before do
245
- ReverseMarkdown.stub(:convert)
246
- .with('<ul><li>this is content</li></ul>', github_flavored: true)
247
- .and_return('- this is content')
248
- end
241
+ before { pad.stub(:content).and_return('- this is content') }
249
242
  it do
250
243
  expect(output).to receive(:puts).with('- this is content')
251
244
  client.show '123', 'md'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hackpad-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mose
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-24 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.4
33
+ version: 0.0.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.4
40
+ version: 0.0.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: paint
43
43
  requirement: !ruby/object:Gem::Requirement