termtter 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency("json_pure", ">= 1.1.3")
27
27
  s.add_dependency("highline", ">= 1.5.0")
28
28
  s.add_dependency("termcolor", ">= 0.3.1")
29
- s.add_dependency("rubytter", ">= 0.5.0")
29
+ s.add_dependency("rubytter", ">= 0.6.3")
30
30
  s.add_dependency("sqlite3-ruby", ">= 1.2.4")
31
31
  s.authors = %w(jugyo ujihisa)
32
32
  s.email = 'jugyo.org@gmail.com'
@@ -0,0 +1,27 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ config.plugins.addspace.set_default( :before, [ %r{https?://} ] )
4
+ config.plugins.addspace.set_default( :after, %w{ ★ ☆ △ ▽})
5
+
6
+ module Termtter::Client
7
+ add_filter do |statuses, event|
8
+ statuses.each do |s|
9
+ config.plugins.addspace.before.each do |c|
10
+ s.text.gsub!(/(\S)(#{c})/, '\1 \2' )
11
+ end
12
+ end
13
+ statuses.each do |s|
14
+ config.plugins.addspace.after.each do |c|
15
+ s.text.gsub!(/(#{c})(\S)/, '\1 \2' )
16
+ end
17
+ statuses
18
+ end
19
+ end
20
+ end
21
+ # addspace
22
+ # add space before or after specified words.
23
+ # example:
24
+ # before: ABCDEhttp://~~~
25
+ # after: ABCDE http://~~~
26
+ # before: ★★★
27
+ # after: ★ ★ ★
data/lib/plugins/growl.rb CHANGED
@@ -54,8 +54,8 @@ Thread.new do
54
54
  end
55
55
 
56
56
  Termtter::Client.register_hook(:name => :growl,
57
- :points => [:post_exec__update_timeline],
58
- :exec_proc => lambda { |cmd, arg, result|
59
- result.reverse.each { |s| queue << s }
57
+ :points => [:post_filter],
58
+ :exec_proc => lambda {|statuses, event|
59
+ statuses.each {|s| queue << s} if event == :update_friends_timeline
60
60
  }
61
61
  )
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Termtter::Client
4
4
 
5
- public_storage[:plugins] = Dir["#{File.dirname(__FILE__)}/*.rb"].map do |f|
5
+ public_storage[:plugins] = (Dir["#{File.dirname(__FILE__)}/*.rb"] + Dir["#{Termtter::CONF_DIR}/plugins/*.rb"]).map do |f|
6
6
  f.match(%r|([^/]+).rb$|)[1]
7
7
  end
8
8
 
@@ -246,8 +246,7 @@ module Termtter::Client
246
246
  ["search,s TEXT", "Search for Twitter"],
247
247
  ["show ID", "Show a single status"]
248
248
  ]
249
- helps += @@helps
250
- helps += @@new_commands.map {|name, command| command.help}
249
+ helps += @commands.map {|name, command| command.help}
251
250
  helps.compact!
252
251
  puts formatted_help(helps)
253
252
  }
@@ -17,12 +17,12 @@ module Termtter
17
17
  super(:name => :stdout, :points => [:output])
18
18
  end
19
19
 
20
- def execute(statuses, event)
20
+ def call(statuses, event)
21
21
  print_statuses(statuses)
22
22
  end
23
23
 
24
24
  def print_statuses(statuses, sort = true, time_format = nil)
25
- return unless statuses
25
+ return unless statuses and statuses.first
26
26
  unless time_format
27
27
  # 最初と最後の日付がちがうとき日付も出す
28
28
  t1 = Time.parse(statuses.first[:created_at])
@@ -3,7 +3,7 @@
3
3
  module Termtter::Client
4
4
  add_filter do |statuses, event|
5
5
  statuses.each do |s|
6
- s[:post_text].gsub!(/(\S)(https?:\/\/)/, '\1 \2')
6
+ s.text.gsub!(/(\S)(https?:\/\/)/, '\1 \2')
7
7
  end
8
8
  statuses
9
9
  end
data/lib/termtter.rb CHANGED
@@ -25,3 +25,14 @@ require 'termtter/task_manager'
25
25
  require 'termtter/client'
26
26
  require 'termtter/api'
27
27
  require 'termtter/system_extensions'
28
+
29
+ module Termtter
30
+ APP_NAME = 'termtter'
31
+
32
+ config.system.set_default :conf_dir, File.expand_path('~/.termtter')
33
+ CONF_DIR = config.system.conf_dir
34
+
35
+ config.system.set_default :conf_file, CONF_DIR + '/config'
36
+ CONF_FILE = config.system.conf_file
37
+ $:.unshift(Termtter::CONF_DIR)
38
+ end
@@ -3,14 +3,6 @@ require 'fileutils'
3
3
  require 'logger'
4
4
 
5
5
  module Termtter
6
- APP_NAME = 'termtter'
7
-
8
- config.system.set_default :conf_dir, File.expand_path('~/.termtter')
9
- CONF_DIR = config.system.conf_dir
10
-
11
- config.system.set_default :conf_file, CONF_DIR + '/config'
12
- CONF_FILE = config.system.conf_file
13
- $:.unshift(Termtter::CONF_DIR)
14
6
 
15
7
  class CommandNotFound < StandardError; end
16
8
 
@@ -38,11 +30,11 @@ module Termtter
38
30
  end
39
31
 
40
32
  def add_filter(&b)
41
- filters << b
33
+ @filters << b
42
34
  end
43
35
 
44
36
  def clear_filter
45
- filters.clear
37
+ @filters.clear
46
38
  end
47
39
 
48
40
  def register_hook(arg)
@@ -128,7 +120,7 @@ module Termtter
128
120
  result = nil
129
121
  get_hooks(point).each {|hook|
130
122
  break if result == false # interrupt if hook return false
131
- result = hook.execute(*args)
123
+ result = hook.call(*args)
132
124
  }
133
125
  result
134
126
  rescue => e
@@ -159,7 +151,7 @@ module Termtter
159
151
  pre_exec_hook_result = call_hooks("pre_exec_#{command.name.to_s}", command_str, modified_arg)
160
152
  next if pre_exec_hook_result == false
161
153
  # exec command
162
- result = command.execute(modified_arg)
154
+ result = command.call(modified_arg)
163
155
  if result
164
156
  call_hooks("post_exec_#{command.name.to_s}", command_str, modified_arg, result)
165
157
  end
@@ -337,7 +329,7 @@ module Termtter
337
329
 
338
330
  def handle_error(e)
339
331
  call_hooks("on_error", e)
340
- rescue => e
332
+ rescue Exception => e
341
333
  puts "Error: #{e}"
342
334
  puts e.backtrace.join("\n")
343
335
  end
@@ -14,6 +14,10 @@ module Termtter
14
14
  # help: help text for the command (Optional)
15
15
  def initialize(args)
16
16
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
17
+ args[:exec_proc] ||= args[:exec]
18
+ args[:completion_proc] ||= args[:completion]
19
+ args[:aliases] ||= [args[:alias]].compact
20
+
17
21
  cfg = {
18
22
  :aliases => [],
19
23
  :exec_proc => lambda {|arg| },
@@ -44,7 +48,7 @@ module Termtter
44
48
  end
45
49
  end
46
50
 
47
- def execute(arg)
51
+ def call(arg)
48
52
  arg = case arg
49
53
  when nil
50
54
  ''
data/lib/termtter/hook.rb CHANGED
@@ -7,8 +7,8 @@ module Termtter
7
7
  def initialize(args)
8
8
  raise ArgumentError, ":name is not given." unless args.has_key?(:name)
9
9
  @name = args[:name].to_sym
10
- @points = args[:points] ? args[:points].map {|i| i } : []
11
- @exec_proc = args[:exec_proc] || lambda {}
10
+ @points = args[:points] || [args[:point]].compact
11
+ @exec_proc = args[:exec_proc] || args[:exec] || lambda {}
12
12
  end
13
13
 
14
14
  def match?(point)
@@ -25,7 +25,7 @@ module Termtter
25
25
  end
26
26
 
27
27
  # TODO: need spec
28
- def execute(*args)
28
+ def call(*args)
29
29
  self.exec_proc.call(*args)
30
30
  end
31
31
  end
@@ -6,13 +6,8 @@ def plugin(name, init = {})
6
6
  config.plugins.__refer__(name.to_sym).__assign__(key.to_sym, value)
7
7
  end
8
8
  end
9
- # FIXME: below path should be replaced by optparsed path
10
- if File.exist?(path = File.expand_path("~/.termtter/plugins/#{name}"))
11
- require path
12
- else
13
- require "plugins/#{name}"
14
- end
15
- rescue LoadError => e
9
+ load "plugins/#{name}.rb"
10
+ rescue Exception => e
16
11
  Termtter::Client.handle_error(e)
17
12
  end
18
13
 
@@ -1,4 +1,4 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Termtter
3
- VERSION = '1.0.4'
3
+ VERSION = '1.0.5'
4
4
  end
@@ -6,7 +6,7 @@ module Termtter
6
6
 
7
7
  describe Client do
8
8
 
9
- it 'should take new_command' do
9
+ it 'should take command' do
10
10
  command = Command.new(:name => :test)
11
11
  Client.register_command(command)
12
12
  Client.get_command(:test).should == command
@@ -17,7 +17,7 @@ module Termtter
17
17
  Client.get_command(:test).name.should == :test
18
18
  end
19
19
 
20
- it 'should call new_command' do
20
+ it 'should call command' do
21
21
  command_arg = nil
22
22
  command = Command.new(:name => :test, :exec_proc => lambda {|arg| command_arg = arg})
23
23
  Client.register_command(command)
@@ -49,7 +49,7 @@ module Termtter
49
49
  hook_called = false
50
50
  Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {hook_called = true})
51
51
  hook_called.should == false
52
- Client.call_new_hooks(:point1)
52
+ Client.call_hooks(:point1)
53
53
  hook_called.should == true
54
54
  end
55
55
 
@@ -59,7 +59,7 @@ module Termtter
59
59
  Client.register_hook(:name => :test1, :points => [:point1], :exec_proc => lambda {|a1, a2| arg1 = a1; arg2 = a2})
60
60
  arg1.should == nil
61
61
  arg2.should == nil
62
- Client.call_new_hooks(:point1, 'foo', 'bar')
62
+ Client.call_hooks(:point1, 'foo', 'bar')
63
63
  arg1.should == 'foo'
64
64
  arg2.should == 'bar'
65
65
  end
@@ -180,7 +180,7 @@ module Termtter
180
180
  Client.should_receive(:load_config)
181
181
  Termtter::API.should_receive(:setup)
182
182
  Client.should_receive(:post_config_load)
183
- Client.should_receive(:call_new_hooks)
183
+ Client.should_receive(:call_hooks)
184
184
  Client.should_receive(:setup_update_timeline_task)
185
185
  Client.should_receive(:start_input_thread)
186
186
  Client.run
@@ -81,18 +81,18 @@ module Termtter
81
81
  lambda { Command.new(:aliases => ['u']) }.should raise_error(ArgumentError)
82
82
  end
83
83
 
84
- it 'should call exec_proc when call method "execute"' do
85
- @command.execute('test').should == 'test'
86
- @command.execute(' test').should == ' test'
87
- @command.execute(' test ').should == ' test '
88
- @command.execute('test test').should == 'test test'
84
+ it 'should call exec_proc when call method "call"' do
85
+ @command.call('test').should == 'test'
86
+ @command.call(' test').should == ' test'
87
+ @command.call(' test ').should == ' test '
88
+ @command.call('test test').should == 'test test'
89
89
  end
90
90
 
91
- it 'should raise ArgumentError at execute' do
92
- lambda { @command.execute(nil) }.should_not raise_error(ArgumentError)
93
- lambda { @command.execute('foo') }.should_not raise_error(ArgumentError)
94
- lambda { @command.execute(false) }.should raise_error(ArgumentError)
95
- lambda { @command.execute(Array.new) }.should raise_error(ArgumentError)
91
+ it 'should raise ArgumentError at call' do
92
+ lambda { @command.call(nil) }.should_not raise_error(ArgumentError)
93
+ lambda { @command.call('foo') }.should_not raise_error(ArgumentError)
94
+ lambda { @command.call(false) }.should raise_error(ArgumentError)
95
+ lambda { @command.call(Array.new) }.should raise_error(ArgumentError)
96
96
  end
97
97
  end
98
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termtter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-03-21 00:00:00 +09:00
13
+ date: 2009-03-22 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.5.0
54
+ version: 0.6.3
55
55
  version:
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: sqlite3-ruby
@@ -74,6 +74,7 @@ extra_rdoc_files:
74
74
  - README.rdoc
75
75
  - History.txt
76
76
  files:
77
+ - lib/plugins/addspace.rb
77
78
  - lib/plugins/april_fool.rb
78
79
  - lib/plugins/bomb.rb
79
80
  - lib/plugins/clear.rb