sidekick 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/.sidekick CHANGED
@@ -1,6 +1,9 @@
1
1
 
2
+ on_start { notify 'started..' }
2
3
 
3
- # every(5) { notify sh 'fortune' }
4
+ on_stop { notify 'stopped..' }
5
+
6
+ after(5) { notify sh 'fortune' }
4
7
 
5
8
  watch('lib/**.rb') { rake 'docs' }
6
9
 
@@ -10,4 +13,6 @@ auto_compile 'test/fixtures/*.sass', 'test/output/:name.css'
10
13
 
11
14
  auto_compile 'test/fixtures/*.coffee', 'test/output/:name.js'
12
15
 
16
+ passenger_server 3002
17
+
13
18
  # vim:ft=ruby
data/README.textile CHANGED
@@ -3,7 +3,7 @@ h1. Sidekick
3
3
  "Sidekick":http://ibuildlegobricks.tumblr.com/post/1398895151/automate-common-tasks-with-sidekick is a command line tool to automatically trigger actions on certain events, as defined per project, in a local @.sidekick@ file in your project folder:
4
4
 
5
5
  <pre><code>
6
- watch('**/*.rb') { restart_passenger; rake docs }
6
+ watch('**/*.rb') { restart_passenger; rake 'docs' }
7
7
 
8
8
  auto_compile 'assets/*.sass', 'public/:name.css'
9
9
 
@@ -23,7 +23,7 @@ h3. Features
23
23
  * Easy to extend
24
24
  * Compiles many formats, thanks to "Tilt":http://github.com/rtomayko/tilt.
25
25
  * Powered by "EventMachine":http://github.com/eventmachine/eventmachine
26
- * Short and sweet codebase - core < 100 loc
26
+ * Very brief and concise codebase.
27
27
 
28
28
  You can "read the annotated source code":http://jbe.github.com/sidekick/sidekick.html.
29
29
 
@@ -31,16 +31,11 @@ h2. Basic usage
31
31
 
32
32
  Install with @gem install sidekick@ and invoke the @sidekick@ command in your project folder. If you do not have a @.sidekick@ file, you will be offered a "template":http://github.com/jbe/sidekick/blob/master/lib/template with plenty of examples.
33
33
 
34
- View source:
35
-
36
- * "triggers":http://jbe.github.com/sidekick/triggers.html
37
- * "helpers":http://github.com/jbe/sidekick/tree/master/lib/sidekick/helpers/
38
-
39
34
  h2. Defining new triggers
40
35
 
41
- Have a look at the "existing triggers":http://jbe.github.com/sidekick/triggers.html, and you will get the idea. Basically, you define new triggers by calling @Sidekick::Triggers.register(:trigger_name) { .. }@, and hooking into EventMachine the same way as in @EM.run { .. }@ from there.
36
+ Have a look at the "existing triggers":http://jbe.github.com/sidekick/triggers.html, and you will get the idea. Basically, you define new triggers by writing methods that hook into "EventMachine":http://github.com/eventmachine/eventmachine the same way as in @EM.run { .. }@.
42
37
 
43
- You can keep your extensions in the @.sidekick@ file itself, or package them in gems, or (better) ask me to merge them into the main repository.
38
+ If you write some useful extensions, please ask me to merge them into the main repository.
44
39
 
45
40
  h3. Copyright
46
41
 
data/Rakefile CHANGED
@@ -6,8 +6,8 @@ begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
8
  gem.name = "sidekick"
9
- gem.summary = %Q{Automatically run common development tasks on events, as defined by a local .sidekick file.}
10
- gem.description = %Q{Automatically run common development tasks on events, as defined by a local .sidekick file. Easy, powerful DSL. Powered by EventMachine. Easy to extend.}
9
+ gem.summary = %Q{Automatically run common development tasks on events.}
10
+ gem.description = %Q{Automatically run common development tasks on events, as prescribed in a local .sidekick file. Easy, powerful DSL. Powered by EventMachine.}
11
11
  gem.email = "post@jostein.be"
12
12
  gem.homepage = "http://github.com/jbe/sidekick"
13
13
  gem.authors = ["Jostein Berre Eliassen,"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
data/bin/sidekick CHANGED
@@ -10,4 +10,4 @@ end
10
10
  puts ' ^ ^ ^ ^ '
11
11
  puts ' == SIDEKICK == ^ ctrl-c to exit ^'
12
12
  puts ' '
13
- Sidekick.run!
13
+ Sidekick.run!( ARGV.first || '.sidekick' )
data/lib/sidekick.rb CHANGED
@@ -4,50 +4,16 @@
4
4
  #
5
5
  # ***
6
6
  #
7
- # Sidekick basically helps you do two things:
8
- #
9
- # -- *Define* named triggers, such as saying that `watch(glob)` means doing something when a file matching `glob` changes, or that `every(duration)` means doing something every `duration` seconds.
10
- #
11
- # -- *Use* the defined triggers with callbacks, such as `watch(**.rb) { notify 'Code change' }`
7
+ # The default trigger definitions and helper methods -- commonly referred to as actions -- are automagically required and included from `lib/sidekick/actions/**.rb`.
12
8
 
13
9
  require 'fileutils'
14
10
  require 'eventmachine'
15
11
 
16
12
  module Sidekick
17
13
 
18
- # This core functionality is provided by `Sidekick::Triggers`.
19
- #
20
- # New triggers can be defined by calling `Sidekick::Triggers.register(:trigger_name) { ... }`.
21
- #
22
- #Basically, the job of a trigger definition is to take the parameters and the block from a directive in the `.sidekick` file, and then hook into EventMachine in some way to set up the trigger. -- Just have a look at the [default trigger library](http://jbe.github.com/sidekick/triggers.html).
23
- #
24
- # By using Ruby's `method_missing`, we can forward method calls to the registered trigger definitions. Any module can thereby extend the `Sidekick::Triggers` module in order to expose the defined triggers as if they were methods.
25
- module Triggers
26
- @@triggers = {}
27
-
28
- def self.register(name, &block)
29
- @@triggers[name] = block
30
- end
31
-
32
- def self.log(str) # used by triggers
33
- puts str
34
- end
35
-
36
- def method_missing(name, *args, &blk)
37
- @@triggers[name] ?
38
- @@triggers[name].call(blk, *args) : super
39
- end
40
-
41
- def respond_to?(method)
42
- super || !!@@triggers[method]
43
- end
44
-
45
- end
46
-
47
- # This part includes the default trigger definitions and helper methods. `Sidekick::Helpers` automagically loads the code in `sidekick/helpers` and then includes its sub-modules.
48
-
49
- module Sidekick::Helpers
50
- Dir[File.dirname(__FILE__) + '/sidekick/helpers/**.rb'
14
+ module Sidekick::Actions
15
+ Dir[
16
+ File.join File.dirname(__FILE__), *%w{sidekick actions **.rb}
51
17
  ].each {|path| load path }
52
18
 
53
19
  constants.each do |name|
@@ -55,15 +21,10 @@ module Sidekick
55
21
  end
56
22
  end
57
23
 
58
- require 'sidekick/triggers'
59
-
60
- # The `.sidekick` file is evaluated in the `Sidekick::Context` module, which exposes DSL style methods by extending `Sidekick::Triggers` and `Sidekick::Helpers`.
61
- Context = Module.new
62
- Context.extend Triggers
63
- Context.extend Helpers
24
+ STOP_CALLBACKS = [] # called on shutdown
64
25
 
26
+ Context = Module.new.extend(Actions)
65
27
 
66
- # `Sidekick.run!` reads and applies the `.sidekick` file, wrapping the setup phase inside `EM.run { .. }`, thus starting the event loop.
67
28
  def self.run!(path='.sidekick')
68
29
  ensure_config_exists(path)
69
30
 
@@ -71,20 +32,23 @@ module Sidekick
71
32
 
72
33
  EventMachine.run do
73
34
  Context.module_eval(
74
- open(path) {|f| f.read }, path )
35
+ open(path) {|f| f.read },
36
+ path
37
+ )
75
38
  end
76
39
  end
77
40
 
78
41
  def self.ensure_config_exists(path)
79
42
  unless File.exists?(path)
80
- puts 'Generate new sidekick file? (Y/n)'
81
- gets =~ /^N|n/ ? exit :
43
+ puts "Generate #{path}? (Y/n)"
44
+ STDIN.gets =~ /^N|n/ ? exit :
82
45
  FileUtils.cp(File.expand_path('../template',
83
46
  __FILE__), path)
84
47
  end
85
48
  end
86
49
 
87
50
  def self.stop(msg=nil)
51
+ STOP_CALLBACKS.each {|c| c.call }
88
52
  EventMachine.stop
89
53
  puts "\n#{msg}" if msg
90
54
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- module Sidekick::Helpers::Compile
3
+ module Sidekick::Actions::Compile
4
4
 
5
5
  # Compiles one template using the `tilt` gem.
6
6
 
@@ -0,0 +1,18 @@
1
+
2
+
3
+
4
+
5
+
6
+ module Sidekick::Actions::Passenger
7
+
8
+ def restart_passenger
9
+ FileUtils.touch './tmp/restart.txt'
10
+ log 'restarted passenger'
11
+ end
12
+
13
+ def passenger_server(port=3000)
14
+ sh "passenger start -d -p #{port.to_s}"
15
+ on_stop { sh "passenger stop -p #{port.to_s}" }
16
+ end
17
+
18
+ end
@@ -1,5 +1,5 @@
1
1
 
2
- module Sidekick::Helpers::Compile
2
+ module Sidekick::Actions::Rake
3
3
 
4
4
  def rake(task_name)
5
5
  needs 'rake', 'to invoke rake tasks'
@@ -1,5 +1,5 @@
1
1
 
2
- module Sidekick::Helpers::Shell
2
+ module Sidekick::Actions::Shell
3
3
 
4
4
  def sh(cmd)
5
5
  log cmd; `#{cmd}`
@@ -1,10 +1,14 @@
1
1
 
2
- module Sidekick::Helpers::SidekickItself
2
+ module Sidekick::Actions::SidekickItself
3
3
 
4
4
  def log(str)
5
5
  puts ' -> ' + str
6
6
  end
7
7
 
8
+ def log_trigger(str)
9
+ puts str
10
+ end
11
+
8
12
  def stop(*prms)
9
13
  ::Sidekick.stop(*prms)
10
14
  end
@@ -3,7 +3,7 @@ require 'rbconfig'
3
3
 
4
4
 
5
5
 
6
- module Sidekick::Helpers::System
6
+ module Sidekick::Actions::System
7
7
  def platform
8
8
  {
9
9
  :linux => /linux/,
@@ -0,0 +1,43 @@
1
+
2
+ # Basically, the job of a trigger definition is to take the parameters and the block from a directive in the `.sidekick` file, and then hook into EventMachine in some way to set up the trigger.
3
+ module Sidekick::Actions::Triggers
4
+
5
+
6
+ def watch(glob)
7
+ needs 'em-dir-watcher', 'to watch file changes'
8
+
9
+ EMDirWatcher.watch(
10
+ File.expand_path('.'),
11
+ :include_only => [glob],
12
+ :grace_period => 0.2
13
+ ) do |paths|
14
+ log_trigger "watch #{paths.inspect}"
15
+ yield(paths)
16
+ end
17
+ end
18
+
19
+ def every(duration)
20
+ EventMachine::PeriodicTimer.new(duration) do
21
+ log_trigger "every #{duration} seconds"
22
+ yield
23
+ end
24
+ end
25
+
26
+ def after(duration)
27
+ EventMachine::Timer.new(duration) do
28
+ log_trigger "after #{duration} seconds"
29
+ yield
30
+ end
31
+ end
32
+
33
+ def on_start(&blk)
34
+ after(0, &blk)
35
+ end
36
+
37
+ def on_stop(&blk)
38
+ ::Sidekick::STOP_CALLBACKS << blk
39
+ end
40
+
41
+ end
42
+
43
+
@@ -1,5 +1,5 @@
1
1
 
2
- module Sidekick::Helpers::UserInteraction
2
+ module Sidekick::Actions::UserInteraction
3
3
  def notify(message, title='Sidekick')
4
4
 
5
5
  log "NOTIFY #{title}: #{message}"
data/lib/template CHANGED
@@ -1,31 +1,34 @@
1
1
 
2
- stop "A new .sidekick file was generated -- now you just have to edit it."
2
+ stop "File generated. Now please fill it in."
3
3
 
4
4
  # Now delete the line above, and set up some actions.
5
5
  # Here are some samples:
6
6
 
7
7
 
8
- # auto_compile 'assets/css/*.sass', 'public/css/:name.css'
8
+ # watch('**.rb') do |paths|
9
+ # log 'code change'
10
+ # restart_passenger
11
+ # rake 'docs'
12
+ # end
9
13
 
10
- # auto_compile 'assets/js/*.coffee', 'public/js/:name.js'
14
+ # after(5) { notify sh 'fortune' }
11
15
 
12
16
  # every(60*60) { notify 'You are now one hour older.' }
13
17
 
14
- # every(60*15) { notify sh 'fortune' }
18
+ # on_stop { notify 'Goodbye' }
15
19
 
16
- # watch('**.rb') do |paths|
17
- # log 'code change'
18
- # restart_passenger
19
- # rake 'doc'
20
- # end
20
+ # auto_compile 'assets/css/*.sass', 'public/css/:name.css'
21
+ # auto_compile 'assets/js/*.coffee', 'public/js/:name.js'
21
22
 
23
+ # passenger_server 3002
22
24
 
23
- # more sample actions:
24
25
 
25
- # needs 'httparty', 'to look up your location'
26
- # loc = HTTParty.get('http://ipinfodb.com/ip_query.php')
27
- # notify "You are in #{loc['Response']['City']}"
28
26
 
27
+ # def report_location
28
+ # needs 'httparty', 'to look up your location'
29
+ # loc = HTTParty.get('http://ipinfodb.com/ip_query.php')
30
+ # notify "You are in #{loc['Response']['City']}"
31
+ # end
29
32
 
30
33
 
31
34
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 6
8
- - 2
9
- version: 0.6.2
8
+ - 3
9
+ version: 0.6.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jostein Berre Eliassen,
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-02 00:00:00 +01:00
17
+ date: 2010-11-12 00:00:00 +01:00
18
18
  default_executable: sidekick
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: "0"
57
57
  type: :runtime
58
58
  version_requirements: *id003
59
- description: Automatically run common development tasks on events, as defined by a local .sidekick file. Easy, powerful DSL. Powered by EventMachine. Easy to extend.
59
+ description: Automatically run common development tasks on events, as prescribed in a local .sidekick file. Easy, powerful DSL. Powered by EventMachine.
60
60
  email: post@jostein.be
61
61
  executables:
62
62
  - sidekick
@@ -76,14 +76,14 @@ files:
76
76
  - VERSION
77
77
  - bin/sidekick
78
78
  - lib/sidekick.rb
79
- - lib/sidekick/helpers/compile.rb
80
- - lib/sidekick/helpers/passenger.rb
81
- - lib/sidekick/helpers/rake.rb
82
- - lib/sidekick/helpers/shell.rb
83
- - lib/sidekick/helpers/sidekick_itself.rb
84
- - lib/sidekick/helpers/system.rb
85
- - lib/sidekick/helpers/user_interaction.rb
86
- - lib/sidekick/triggers.rb
79
+ - lib/sidekick/actions/compile.rb
80
+ - lib/sidekick/actions/passenger.rb
81
+ - lib/sidekick/actions/rake.rb
82
+ - lib/sidekick/actions/shell.rb
83
+ - lib/sidekick/actions/sidekick_itself.rb
84
+ - lib/sidekick/actions/system.rb
85
+ - lib/sidekick/actions/triggers.rb
86
+ - lib/sidekick/actions/user_interaction.rb
87
87
  - lib/template
88
88
  - test/fixtures/page.haml
89
89
  - test/fixtures/site.coffee
@@ -121,7 +121,7 @@ rubyforge_project:
121
121
  rubygems_version: 1.3.7
122
122
  signing_key:
123
123
  specification_version: 3
124
- summary: Automatically run common development tasks on events, as defined by a local .sidekick file.
124
+ summary: Automatically run common development tasks on events.
125
125
  test_files:
126
126
  - test/helper.rb
127
127
  - test/test_sidekick.rb
@@ -1,14 +0,0 @@
1
-
2
-
3
-
4
-
5
-
6
- module Sidekick::Helpers::Passenger
7
-
8
- def restart_passenger
9
- FileUtils.touch './tmp/restart.txt'
10
- log 'restarted passenger'
11
- end
12
-
13
-
14
- end
@@ -1,30 +0,0 @@
1
-
2
-
3
- module Sidekick::Triggers
4
-
5
- extend ::Sidekick::Helpers
6
-
7
- register :watch do |callback, glob|
8
- needs 'em-dir-watcher', 'to watch file changes'
9
-
10
- EMDirWatcher.watch(
11
- File.expand_path('.'),
12
- :include_only => [glob],
13
- :grace_period => 0.2
14
- ) do |paths|
15
- log "watch #{paths.inspect}"
16
- callback.call(paths)
17
- end
18
- end
19
-
20
- register :every do |callback, duration|
21
- EventMachine::PeriodicTimer.new(duration) do
22
- log "every #{duration} seconds"
23
- callback.call
24
- end
25
- end
26
-
27
- end
28
-
29
-
30
-