blindgaenger-glitter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/bin/glitter +3 -51
- data/glitter.gemspec +5 -3
- data/lib/commands/commit.rb +1 -1
- data/lib/commands/init.rb +1 -1
- data/lib/commands/log.rb +11 -16
- data/lib/glitter.rb +53 -0
- data/lib/template.rb +52 -0
- metadata +4 -2
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg/
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/bin/glitter
CHANGED
@@ -1,53 +1,5 @@
|
|
1
|
-
#!/usr/bin/ruby
|
2
|
-
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
3
|
-
|
1
|
+
#!/usr/bin/env ruby
|
4
2
|
require 'rubygems'
|
5
|
-
require '
|
6
|
-
require 'yaml'
|
7
|
-
require 'highline/import'
|
8
|
-
require 'ftools'
|
9
|
-
require 'gli'
|
10
|
-
require 'twitter'
|
11
|
-
require 'twitter_app'
|
12
|
-
|
13
|
-
include GLI
|
14
|
-
|
15
|
-
CONFIG_FILE = "~/.twitter/glitter.yml"
|
16
|
-
|
17
|
-
Dir['lib/commands/*.rb'].each {|file| load file}
|
18
|
-
|
19
|
-
pre do |global_options,command,options,args|
|
20
|
-
@config = TwitterConfig.new(CONFIG_FILE)
|
21
|
-
|
22
|
-
if command.nil?
|
23
|
-
commands[:help].execute(global_options,options,args)
|
24
|
-
false
|
25
|
-
elsif command && command.name == :help
|
26
|
-
true # always help
|
27
|
-
elsif @config.atoken.nil?
|
28
|
-
if command && command.name == :init
|
29
|
-
true
|
30
|
-
else
|
31
|
-
puts "Sorry, but you need to initialize first. Try this:"
|
32
|
-
puts "\n"
|
33
|
-
puts " $ glitter init"
|
34
|
-
puts "\n"
|
35
|
-
false
|
36
|
-
end
|
37
|
-
else
|
38
|
-
@twitter = TwitterApp.new(@config)
|
39
|
-
true # already init
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
post do |global_options,command,options,args|
|
44
|
-
end
|
45
|
-
|
46
|
-
on_error do |ex|
|
47
|
-
warn ex.message
|
48
|
-
warn ex.backtrace
|
49
|
-
true
|
50
|
-
end
|
51
|
-
|
3
|
+
require 'glitter'
|
52
4
|
GLI.run(ARGV)
|
53
|
-
|
5
|
+
|
data/glitter.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{glitter}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["blindgaenger"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-28}
|
10
10
|
s.default_executable = %q{glitter}
|
11
11
|
s.email = %q{blindgaenger@gmail.com}
|
12
12
|
s.executables = ["glitter"]
|
@@ -16,7 +16,8 @@ Gem::Specification.new do |s|
|
|
16
16
|
"glitter.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
"
|
19
|
+
".gitignore",
|
20
|
+
"LICENSE",
|
20
21
|
"README.rdoc",
|
21
22
|
"Rakefile",
|
22
23
|
"VERSION",
|
@@ -28,6 +29,7 @@ Gem::Specification.new do |s|
|
|
28
29
|
"lib/commands/init.rb",
|
29
30
|
"lib/commands/log.rb",
|
30
31
|
"lib/glitter.rb",
|
32
|
+
"lib/template.rb",
|
31
33
|
"lib/twitter_app.rb",
|
32
34
|
"test/glitter_test.rb",
|
33
35
|
"test/test_helper.rb"
|
data/lib/commands/commit.rb
CHANGED
@@ -4,7 +4,7 @@ command :commit do |c|
|
|
4
4
|
c.desc "The text of your status update. Statuses over 140 characters will be forceably truncated."
|
5
5
|
c.flag :message, :m
|
6
6
|
|
7
|
-
c.action do |
|
7
|
+
c.action do |globals, options, args|
|
8
8
|
unless options.message
|
9
9
|
say "Aborting commit due to empty commit message."
|
10
10
|
else
|
data/lib/commands/init.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
desc "Registers glitter with your twitter account"
|
2
2
|
command [:init] do |c|
|
3
3
|
|
4
|
-
c.action do |
|
4
|
+
c.action do |globals, options, args|
|
5
5
|
#TODO: check for global --force option, not a git parameter but useful
|
6
6
|
if @config.atoken
|
7
7
|
puts "You already initialized glitter. Find out what else you can do:"
|
data/lib/commands/log.rb
CHANGED
@@ -5,31 +5,26 @@ command :log do |c|
|
|
5
5
|
c.default_value 20
|
6
6
|
c.flag :n, :'max-count'
|
7
7
|
|
8
|
-
c.
|
9
|
-
|
10
|
-
"<%= color('#{text}', BOLD) %>"
|
11
|
-
end
|
12
|
-
|
13
|
-
def color(text, color)
|
14
|
-
"<%= color('#{text}', :#{color.to_s}) %>"
|
15
|
-
end
|
8
|
+
c.desc "Show colored diff."
|
9
|
+
c.switch :color
|
16
10
|
|
17
|
-
|
18
|
-
|
19
|
-
end
|
11
|
+
c.desc "Turn off colored diff."
|
12
|
+
c.switch :"no-color"
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
c.action do |globals, options, args|
|
15
|
+
template = Template.new(options) do |status|
|
16
|
+
<<-EOL
|
24
17
|
#{color "commit #{status.id}", :yellow}
|
25
18
|
Author: #{status.user.screen_name} <#{status.user.name}>
|
26
19
|
Date: #{status.created_at}
|
27
20
|
|
28
21
|
#{indent(status.text)}
|
29
22
|
|
30
|
-
|
31
|
-
|
23
|
+
EOL
|
24
|
+
end
|
32
25
|
|
26
|
+
statuses = @twitter.friends_timeline({:count => options.n})
|
27
|
+
template.print_each statuses
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
data/lib/glitter.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__)
|
2
|
+
%w[rubygems ostruct yaml highline/import ftools gli twitter].each { |f| require f }
|
3
|
+
RUBY_PLATFORM = PLATFORM unless defined? RUBY_PLATFORM # Ruby 1.8 compatibility
|
4
|
+
|
5
|
+
require 'twitter_app'
|
6
|
+
load 'lib/template.rb'
|
7
|
+
include GLI
|
8
|
+
Dir['lib/commands/*.rb'].each {|file| load file}
|
9
|
+
|
10
|
+
CONFIG_FILE = "~/.twitter/glitter.yml"
|
11
|
+
|
12
|
+
desc 'Show the current version'
|
13
|
+
switch :version
|
14
|
+
|
15
|
+
pre do |globals,command,options,args|
|
16
|
+
@config = TwitterConfig.new(CONFIG_FILE)
|
17
|
+
|
18
|
+
if command.nil?
|
19
|
+
if globals.version
|
20
|
+
puts "glitter version #{File.read 'VERSION'}"
|
21
|
+
else
|
22
|
+
commands[:help].execute(globals,options,args)
|
23
|
+
end
|
24
|
+
false
|
25
|
+
elsif command && command.name == :help
|
26
|
+
true # always help
|
27
|
+
elsif @config.atoken.nil?
|
28
|
+
if command && command.name == :init
|
29
|
+
true
|
30
|
+
else
|
31
|
+
puts "Sorry, but you need to initialize first. Try this:"
|
32
|
+
puts "\n"
|
33
|
+
puts " $ glitter init"
|
34
|
+
puts "\n"
|
35
|
+
false
|
36
|
+
end
|
37
|
+
else
|
38
|
+
@twitter = TwitterApp.new(@config)
|
39
|
+
true # already init
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
post do |globals,command,options,args|
|
44
|
+
end
|
45
|
+
|
46
|
+
on_error do |ex|
|
47
|
+
puts ex.message
|
48
|
+
puts ex.backtrace.join("\n")
|
49
|
+
true
|
50
|
+
end
|
51
|
+
|
52
|
+
GLI.run(ARGV) if __FILE__ == $0
|
53
|
+
|
data/lib/template.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
class Object
|
2
|
+
module InstanceExecHelper; end
|
3
|
+
include InstanceExecHelper
|
4
|
+
def instance_exec(*args, &block)
|
5
|
+
begin
|
6
|
+
old_critical, Thread.critical = Thread.critical, true
|
7
|
+
n = 0
|
8
|
+
n += 1 while respond_to?(mname="__instance_exec#{n}")
|
9
|
+
InstanceExecHelper.module_eval{ define_method(mname, &block) }
|
10
|
+
ensure
|
11
|
+
Thread.critical = old_critical
|
12
|
+
end
|
13
|
+
begin
|
14
|
+
ret = send(mname, *args)
|
15
|
+
ensure
|
16
|
+
InstanceExecHelper.module_eval{ remove_method(mname) } rescue nil
|
17
|
+
end
|
18
|
+
ret
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
class Template
|
24
|
+
def initialize(globals, &block)
|
25
|
+
@color = !globals['no-color']
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def print(args)
|
30
|
+
say instance_exec(args, &@block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_each(list)
|
34
|
+
list.each {|item|
|
35
|
+
print item
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def bold(text)
|
40
|
+
return text unless @color
|
41
|
+
"<%= color('#{text}', BOLD) %>"
|
42
|
+
end
|
43
|
+
|
44
|
+
def color(text, color)
|
45
|
+
return text unless @color
|
46
|
+
"<%= color('#{text}', :#{color.to_s}) %>"
|
47
|
+
end
|
48
|
+
|
49
|
+
def indent(text, length=4)
|
50
|
+
' '*length + wrap(text, length, 80)
|
51
|
+
end
|
52
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blindgaenger-glitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- blindgaenger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-28 00:00:00 -07:00
|
13
13
|
default_executable: glitter
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,7 @@ extra_rdoc_files:
|
|
43
43
|
- README.rdoc
|
44
44
|
- glitter.rdoc
|
45
45
|
files:
|
46
|
+
- .gitignore
|
46
47
|
- LICENSE
|
47
48
|
- README.rdoc
|
48
49
|
- Rakefile
|
@@ -55,6 +56,7 @@ files:
|
|
55
56
|
- lib/commands/init.rb
|
56
57
|
- lib/commands/log.rb
|
57
58
|
- lib/glitter.rb
|
59
|
+
- lib/template.rb
|
58
60
|
- lib/twitter_app.rb
|
59
61
|
- test/glitter_test.rb
|
60
62
|
- test/test_helper.rb
|