code2gist 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code2gist (0.0.4)
4
+ code2gist (0.0.5)
5
5
 
6
6
  GEM
7
7
  specs:
data/README.md CHANGED
@@ -25,12 +25,12 @@ Or:
25
25
  new_text = Code2Gist.replace(your_text, "another example description")
26
26
 
27
27
  ### Options
28
- When replacing, there is one option available: `:html` (default:
29
- `false`).
28
+ When replacing, there are two options available: `:html` (default:
29
+ `false`) and `:anonymous` (default: `false`).
30
30
 
31
31
  Quick example:
32
32
 
33
- Code2Gist.replace(your_markdown_text, "yad", :html => true)
33
+ Code2Gist.replace(your_markdown_text, "yay!", :html => true)
34
34
 
35
35
  This is specially useful if you're using markdown/textile and would like
36
36
  to have all your code blocks in a gist and embeded in your HTML. For
@@ -38,6 +38,12 @@ example:
38
38
 
39
39
  html = Markdown.new(Code2Gist.replace(text, "Code snippets from article X", :html => true)).to_html
40
40
 
41
+ You can use the `:anonymous` option to avoid authenticating that code
42
+ upload, even if the credentials are available (see next section):
43
+
44
+ Code2Gist.replace(your_markdown_text, "anonymous!", :anonymous =>
45
+ true)
46
+
41
47
  ### I want to be the owner of the gist!
42
48
 
43
49
  It's okay, just specify your username and API token before uploading any
data/bin/code2gist CHANGED
@@ -27,14 +27,16 @@ end
27
27
  login = options.delete(:login)
28
28
  token = options.delete(:token)
29
29
  substitute = options.delete(:substitute)
30
+ anonymous = true
30
31
 
31
32
  if login && options
32
33
  Code2Gist::Config.github_login = login
33
34
  Code2Gist::Config.github_token = token
35
+ anonymous = false
34
36
  end
35
37
 
36
38
  if action == "upload"
37
- puts Code2Gist.upload(File.read(path), description)
39
+ puts Code2Gist.upload(File.read(path), description, anonymous)
38
40
  elsif action == "replace"
39
41
  new_text = Code2Gist.replace(File.read(path), description, options)
40
42
 
data/code2gist.gemspec CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "code2gist"
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
6
6
  s.platform = Gem::Platform::RUBY
7
- s.authors = ["Gonçalo Silva"]
7
+ s.authors = ["Goncalo Silva"]
8
8
  s.email = ["goncalossilva@gmail.com"]
9
9
  s.homepage = "http://github.com/goncalossilva/code2gist"
10
10
  s.summary = "Parse text files (markdown/textile/whatever) for code blocks and gist them"
data/lib/code2gist.rb CHANGED
@@ -22,7 +22,7 @@ module Code2Gist
22
22
  end
23
23
  end
24
24
 
25
- def upload(text, description = nil)
25
+ def upload(text, description = nil, anonymous = false)
26
26
  new_text = name_nameless_code_blocks(text)
27
27
 
28
28
  code_blocks = Hash[*new_text.scan(CODE_REGEX).flatten]
@@ -31,15 +31,15 @@ module Code2Gist
31
31
  return nil
32
32
  end
33
33
 
34
- get_gist(code_blocks, description)
34
+ get_gist(code_blocks, description, anonymous)
35
35
  end
36
36
 
37
37
  def replace(text, description = nil, opts = {})
38
- options = {:html => false}.merge(opts)
38
+ options = {:html => false, :anonymous => false}.merge(opts)
39
39
 
40
40
  new_text = name_nameless_code_blocks(text)
41
41
 
42
- gist_url = upload(new_text, description)
42
+ gist_url = upload(new_text, description, options[:anonymous])
43
43
 
44
44
  if options[:html]
45
45
  new_text.gsub(CODE_REGEX, "<script src=\"#{gist_url}.js?file=\\1\"></script>")
@@ -64,7 +64,7 @@ module Code2Gist
64
64
  new_text
65
65
  end
66
66
 
67
- def get_gist(data, description)
67
+ def get_gist(data, description, anonymous)
68
68
  post_data = {}
69
69
  data.each_with_index do |(filename, content), index|
70
70
  post_data.merge!("files[#{filename}]" => content)
@@ -73,7 +73,7 @@ module Code2Gist
73
73
  post_data.merge!(
74
74
  "login" => Code2Gist::Config.github_login,
75
75
  "token" => Code2Gist::Config.github_token
76
- ) unless Code2Gist::Config.github_login.nil? || Code2Gist::Config.github_token.nil?
76
+ ) unless anonymous || Code2Gist::Config.github_login.nil? || Code2Gist::Config.github_token.nil?
77
77
 
78
78
  post_data.merge!("description" => description)
79
79
 
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code2gist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Gonçalo Silva
8
+ - Goncalo Silva
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-23 00:00:00.000000000Z
12
+ date: 2011-09-03 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Parse text files (markdown/textile/whatever) for code blocks and gist
15
15
  them
@@ -42,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
42
  version: '0'
43
43
  segments:
44
44
  - 0
45
- hash: -3615808291212224038
45
+ hash: -3600356913606737563
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  none: false
48
48
  requirements: