jist 1.3.1 → 1.4.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.
data/README.md CHANGED
@@ -28,6 +28,12 @@ $ jist a.rb
28
28
  https://gist.github.com/0d07bc98c139810a4075
29
29
  ```
30
30
 
31
+ Upload multiple files :
32
+ ```shell
33
+ $ jist a b c
34
+ $ jist *.rb
35
+ ```
36
+
31
37
  By default it reads from STDIN, and you can set a filename with `-f`.
32
38
 
33
39
  ```shell
@@ -62,6 +68,12 @@ $ jist -c <a.rb
62
68
  https://gist.github.com/7db51bb5f4f35c480fc8
63
69
  ```
64
70
 
71
+ If you'd like to copy the resulting embeddable URL to your clipboard, use `--copy-js`.
72
+
73
+ ```shell
74
+ $ jist --copy-js <a.rb
75
+ <script src="https://gist.github.com/7db51bb5f4f35c480fc8"></script>
76
+ ```
65
77
  And you can just ask jist to open a browser window directly with `-o`.
66
78
 
67
79
  ```shell
data/bin/jist CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
-
5
- require 'jist'
4
+ require File.expand_path('../../lib/jist', __FILE__)
6
5
 
7
6
  # For the holdings of options.
8
7
  options = {}
@@ -33,14 +32,15 @@ If you would like to shorten the resulting gist URL, use the -s flag. This will
33
32
  use GitHub's URL shortener, git.io.
34
33
 
35
34
  To copy the resulting URL to your clipboard you can use the -c option, or to just
36
- open it directly in your browser, use -o. You can add `alias jist='jist -c'` to
37
- your shell's rc file to configure this behaviour by default.
35
+ open it directly in your browser, use -o. Using the -e option will copy the embeddable
36
+ URL to the clipboard. You can add `alias jist='jist -c'` to your shell's rc file to configure this
37
+ behaviour by default.
38
38
 
39
39
  Instead of creating a new jist, you can update an existing one by passing its ID
40
40
  or URL with "-u". For this to work, you must be logged in, and have created the
41
41
  original gist with the same GitHub account.
42
42
 
43
- Usage: #{executable_name} [-o|-c] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
43
+ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P] [-f NAME]* FILE*
44
44
  #{executable_name} --login
45
45
 
46
46
  EOS
@@ -82,6 +82,10 @@ Usage: #{executable_name} [-o|-c] [-p] [-s] [-d DESC] [-t TOKEN|-a] [-u URL] [-P
82
82
  opts.on("-c", "--copy", "Copy the resulting URL to the clipboard") do
83
83
  options[:copy] = true
84
84
  end
85
+ opts.on("-e", "--embed", "Copy the embed code for the gist to the clipboard") do
86
+ options[:embed] = true
87
+ options[:copy] = true
88
+ end
85
89
 
86
90
  opts.on("-o", "--open", "Open the resulting URL in a browser") do
87
91
  options[:open] = true
@@ -105,11 +109,21 @@ end
105
109
  opts.parse!
106
110
 
107
111
  begin
112
+ options[:output] = if options[:embed] && options[:shorten]
113
+ raise Jist::Error, "--embed does not make sense with --shorten"
114
+ elsif options[:embed]
115
+ :javascript
116
+ elsif options[:shorten]
117
+ :short_url
118
+ else
119
+ :html_url
120
+ end
121
+
108
122
  if options[:paste]
109
- puts Jist.gist(Jist.paste, options)['html_url']
123
+ puts Jist.gist(Jist.paste, options)
110
124
  elsif ARGV.size == 0
111
125
  $stderr.puts "(type a gist. <ctrl-c> to cancel, <ctrl-d> when done)" if $stdin.tty?
112
- puts Jist.gist(ARGF.read, options)['html_url']
126
+ puts Jist.gist(ARGF.read, options)
113
127
  else
114
128
  files = {}
115
129
  ARGV.zip(filenames).each do |(file, name)|
@@ -120,7 +134,7 @@ begin
120
134
  end
121
135
  end
122
136
 
123
- puts Jist.multi_gist(files, options)['html_url']
137
+ puts Jist.multi_gist(files, options)
124
138
  end
125
139
  rescue Jist::Error => e
126
140
  puts "Error: #{e.message}"
@@ -7,7 +7,7 @@ require 'uri'
7
7
  module Jist
8
8
  extend self
9
9
 
10
- VERSION = '1.3.1'
10
+ VERSION = '1.4.0'
11
11
 
12
12
  # A list of clipboard commands with copy and paste support.
13
13
  CLIPBOARD_COMMANDS = {
@@ -21,26 +21,18 @@ module Jist
21
21
  GIT_IO_URL = URI("http://git.io")
22
22
 
23
23
  # Exception tag for errors raised while gisting.
24
- module Error; end
24
+ module Error;
25
+ def self.exception(*args)
26
+ RuntimeError.new(*args).extend(self)
27
+ end
28
+ end
25
29
  class ClipboardError < RuntimeError; include Error end
26
30
 
27
31
  # Upload a gist to https://gist.github.com
28
32
  #
29
33
  # @param [String] content the code you'd like to gist
30
- # @param [Hash] options more detailed options
31
- #
32
- # @option options [String] :description the description
33
- # @option options [String] :filename ('a.rb') the filename
34
- # @option options [Boolean] :public (false) is this gist public
35
- # @option options [Boolean] :anonymous (false) is this gist anonymous
36
- # @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
37
- # @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
38
- # @option options [String] :update the URL or id of a gist to update
39
- # @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
40
- # @option options [Boolean] :open (false) Open the resulting URL in a browser.
41
- #
42
- # @return [Hash] the decoded JSON response from the server
43
- # @raise [Jist::Error] if something went wrong
34
+ # @param [Hash] options more detailed options, see
35
+ # the documentation for {multi_gist}
44
36
  #
45
37
  # @see http://developer.github.com/v3/gists/
46
38
  def gist(content, options = {})
@@ -56,13 +48,17 @@ module Jist
56
48
  # @option options [String] :description the description
57
49
  # @option options [Boolean] :public (false) is this gist public
58
50
  # @option options [Boolean] :anonymous (false) is this gist anonymous
59
- # @option options [Boolean] :shorten (false) Shorten the resulting URL using git.io.
60
51
  # @option options [String] :access_token (`File.read("~/.jist")`) The OAuth2 access token.
61
52
  # @option options [String] :update the URL or id of a gist to update
62
53
  # @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
63
54
  # @option options [Boolean] :open (false) Open the resulting URL in a browser.
55
+ # @option options [Symbol] :output (:all) The type of return value you'd like:
56
+ # :html_url gives a String containing the url to the gist in a browser
57
+ # :short_url gives a String contianing a git.io url that redirects to html_url
58
+ # :javascript gives a String containing a script tag suitable for embedding the gist
59
+ # :all gives a Hash containing the parsed json response from the server
64
60
  #
65
- # @return [Hash] the decoded JSON response from the server
61
+ # @return [String, Hash] the return value as configured by options[:output]
66
62
  # @raise [Jist::Error] if something went wrong
67
63
  #
68
64
  # @see http://developer.github.com/v3/gists/
@@ -207,18 +203,27 @@ module Jist
207
203
 
208
204
  # Called after an HTTP response to gist to perform post-processing.
209
205
  #
210
- # @param [String] body the HTTP-200 response
211
- # @param [Hash] options any options
212
- # @option options [Boolean] :copy copy the URL to the clipboard
213
- # @return [Hash] the parsed JSON response from the server
206
+ # @param [String] body the text body from the github api
207
+ # @param [Hash] options more detailed options, see
208
+ # the documentation for {multi_gist}
214
209
  def on_success(body, options={})
215
210
  json = JSON.parse(body)
216
211
 
217
- json['html_url'] = shorten(json['html_url']) if options[:shorten]
218
- Jist.copy(json['html_url']) if options[:copy]
212
+ output = case options[:output]
213
+ when :javascript
214
+ %Q{<script src="#{json['html_url']}.js"></script>}
215
+ when :html_url
216
+ json['html_url']
217
+ when :short_url
218
+ shorten(json['html_url'])
219
+ else
220
+ json
221
+ end
222
+
223
+ Jist.copy(output.to_s) if options[:copy]
219
224
  Jist.open(json['html_url']) if options[:open]
220
225
 
221
- json
226
+ output
222
227
  end
223
228
 
224
229
  # Copy a string to the clipboard.
@@ -9,10 +9,10 @@ describe '...' do
9
9
  end
10
10
 
11
11
  def ask_for_copy
12
- Jist.on_success({'html_url' => @bobo_url}.to_json, :copy => true )
12
+ Jist.on_success({'html_url' => @bobo_url}.to_json, :copy => true, :output => :html_url)
13
13
  end
14
14
  def jist_but_dont_ask_for_copy
15
- Jist.on_success({'html_url' => 'http://example.com/'}.to_json)
15
+ Jist.on_success({'html_url' => 'http://example.com/'}.to_json, :output => :html_url)
16
16
  end
17
17
 
18
18
  it 'should try to copy the url when the clipboard option is passed' do
@@ -20,6 +20,12 @@ describe '...' do
20
20
  ask_for_copy
21
21
  end
22
22
 
23
+ it 'should try to copy the embed url when the clipboard-js option is passed' do
24
+ js_link = %Q{<script src="#{@bobo_url}.js"></script>}
25
+ Jist.should_receive(:copy).with(js_link)
26
+ Jist.on_success({'html_url' => @bobo_url}.to_json, :copy => true, :output => :javascript)
27
+ end
28
+
23
29
  it "should not copy when not asked to" do
24
30
  Jist.should_not_receive(:copy).with(@bobo_url)
25
31
  jist_but_dont_ask_for_copy
@@ -5,7 +5,7 @@ describe '...' do
5
5
  end
6
6
 
7
7
  it "should return a shortened version of the URL" do
8
- Jist.gist("Test gist", :shorten => true).should == {"html_url" => "http://git.io/XXXXXX"}
8
+ Jist.gist("Test gist", :output => :short_url).should == "http://git.io/XXXXXX"
9
9
  end
10
10
  end
11
11
 
metadata CHANGED
@@ -1,24 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jist
3
3
  version: !ruby/object:Gem::Version
4
+ version: 1.4.0
4
5
  prerelease:
5
- version: 1.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Conrad Irwin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-03-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- type: :runtime
15
+ name: json
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
+ type: :runtime
22
23
  prerelease: false
23
24
  version_requirements: !ruby/object:Gem::Requirement
24
25
  none: false
@@ -26,15 +27,15 @@ dependencies:
26
27
  - - ! '>='
27
28
  - !ruby/object:Gem::Version
28
29
  version: '0'
29
- name: json
30
30
  - !ruby/object:Gem::Dependency
31
- type: :development
31
+ name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
37
  version: '0'
38
+ type: :development
38
39
  prerelease: false
39
40
  version_requirements: !ruby/object:Gem::Requirement
40
41
  none: false
@@ -42,15 +43,15 @@ dependencies:
42
43
  - - ! '>='
43
44
  - !ruby/object:Gem::Version
44
45
  version: '0'
45
- name: rake
46
46
  - !ruby/object:Gem::Dependency
47
- type: :development
47
+ name: rspec
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ type: :development
54
55
  prerelease: false
55
56
  version_requirements: !ruby/object:Gem::Requirement
56
57
  none: false
@@ -58,15 +59,15 @@ dependencies:
58
59
  - - ! '>='
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
- name: rspec
62
62
  - !ruby/object:Gem::Dependency
63
- type: :development
63
+ name: webmock
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
+ type: :development
70
71
  prerelease: false
71
72
  version_requirements: !ruby/object:Gem::Requirement
72
73
  none: false
@@ -74,7 +75,6 @@ dependencies:
74
75
  - - ! '>='
75
76
  - !ruby/object:Gem::Version
76
77
  version: '0'
77
- name: webmock
78
78
  description: Provides a single function (Jist.gist) that uploads a gist.
79
79
  email: conrad.irwin@gmail.com
80
80
  executables:
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  version: '0'
117
117
  requirements: []
118
118
  rubyforge_project:
119
- rubygems_version: 1.8.24
119
+ rubygems_version: 1.8.23
120
120
  signing_key:
121
121
  specification_version: 3
122
122
  summary: Just allows you to upload gists