Browse files

Add "Print embed code" option.

-e or --embed option will be copied to the clipboard JavaScript embed code . and print stdout.
  • Loading branch information...
1 parent 9c080a3 commit a8e17d262a76340d896e10528cc35669dd01805c @mironal mironal committed Feb 16, 2013
Showing with 26 additions and 5 deletions.
  1. +12 −2 gist
  2. +12 −1 lib/gist.rb
  3. +1 −1 man/gist.1
  4. +1 −1 man/gist.1.html
View
14 gist
@@ -1140,6 +1140,7 @@ module Gist
gist_extension = defaults["extension"]
browse_enabled = defaults["browse"]
description = nil
+ embed_enabled = nil
opts = OptionParser.new do |opts|
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -1162,6 +1163,10 @@ module Gist
browse_enabled = o
end
+ opts.on('-e', '--embed', 'Print javascript embed code') do |o|
+ embed_enabled = o
+ end
+
opts.on('-m', '--man', 'Print manual') do
Gist::Manpage.display("gist")
end
@@ -1205,13 +1210,18 @@ module Gist
url = write(files, private_gist, description)
browse(url) if browse_enabled
- puts copy(url)
+ puts copy(to_embed(url)) if embed_enabled
+ puts copy(url) unless embed_enabled
rescue => e
warn e
puts opts
end
end
+ def to_embed(url)
+ %Q[<script src="#{url}.js"></script>]
+ end
+
def write(files, private_gist = false, description = nil)
url = URI.parse(CREATE_URL)
@@ -1366,7 +1376,7 @@ __END__
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "GIST" "1" "March 2012" "GITHUB" "Gist Manual"
+.TH "GIST" "1" "February 2013" "GITHUB" "Gist Manual"
.
.SH "NAME"
\fBgist\fR \- gist on the command line
View
13 lib/gist.rb
@@ -46,6 +46,7 @@ def execute(*args)
gist_extension = defaults["extension"]
browse_enabled = defaults["browse"]
description = nil
+ embed_enabled = nil
opts = OptionParser.new do |opts|
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -68,6 +69,10 @@ def execute(*args)
browse_enabled = o
end
+ opts.on('-e', '--embed', 'Print javascript embed code') do |o|
+ embed_enabled = o
+ end
+
opts.on('-m', '--man', 'Print manual') do
Gist::Manpage.display("gist")
end
@@ -115,13 +120,19 @@ def execute(*args)
url = write(files, private_gist, description)
browse(url) if browse_enabled
- puts copy(url)
+ puts copy(to_embed(url)) if embed_enabled
+ puts copy(url) unless embed_enabled
rescue => e
warn e
puts opts
end
end
+ # Create a javascript embed code
+ def to_embed(url)
+ %Q[<script src="#{url}.js"></script>]
+ end
+
# Create a gist on gist.github.com
def write(files, private_gist = false, description = nil)
url = URI.parse(CREATE_URL)
View
2 man/gist.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "GIST" "1" "November 2012" "GITHUB" "Gist Manual"
+.TH "GIST" "1" "February 2013" "GITHUB" "Gist Manual"
.
.SH "NAME"
\fBgist\fR \- gist on the command line
View
2 man/gist.1.html
@@ -200,7 +200,7 @@ <h2 id="SEE-ALSO">SEE ALSO</h2>
<ol class='man-decor man-foot man foot'>
<li class='tl'>GITHUB</li>
- <li class='tc'>November 2012</li>
+ <li class='tc'>February 2013</li>
<li class='tr'>gist(1)</li>
</ol>

0 comments on commit a8e17d2

Please sign in to comment.