sidekick 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -17,5 +17,6 @@ tmtags
17
17
  coverage
18
18
  rdoc
19
19
  pkg
20
+ test/output
20
21
 
21
22
  ## PROJECT::SPECIFIC
data/.sidekick CHANGED
@@ -1,13 +1,17 @@
1
-
2
1
  # This is an example sidekick file that i use for testing
3
2
  # by doing. Proper tests are welcome.
4
3
 
5
- watch '**/*.rb' do |paths|
6
- log 'files updated'
7
- end
8
4
 
9
- every(20) do
10
- notify sh('fortune')
11
- end
5
+
6
+
7
+ # watch '**/*.rb' {|paths| log 'made edits' }
8
+
9
+ # every(20) { notify sh 'fortune' }
10
+
11
+ auto_compile 'test/fixtures/*.haml', 'test/output/:name.html'
12
+
13
+ auto_compile 'test/fixtures/*.sass', 'test/output/:name.css'
14
+
15
+ auto_compile 'test/fixtures/*.coffee', 'test/output/:name.js'
12
16
 
13
17
  # vim:ft=ruby
data/README.textile CHANGED
@@ -1,47 +1,48 @@
1
1
  h1. Sidekick
2
2
 
3
- Sidekick is a command line tool to automatically trigger certain tasks following certain events, as defined in a @.sidekick@ file in your project folder.
4
3
 
5
- You would typically run it in the background while coding, to automatize things like restarting development servers on file changes, recompiling assets, continously running tests or periodically running commands.
4
+ Sidekick is a command line tool to automatically trigger running tasks on certain events, such as when you make updates. This is defined per project, in a local @.sidekick@ file in your project folder.
6
5
 
6
+ h3. Features
7
7
 
8
- h2. Basic usage
8
+ * Simple, powerful dsl. "Examples here.":http://github.com/jbe/sidekick/blob/master/lib/template
9
+ * Pre-defined triggers.
10
+ * Pre-defined helpers for common tasks.
11
+ * Easy to write new triggers and helpers.
12
+ * Esily compiles most languages thanks to "Tilt":http://github.com/rtomayko/tilt.
13
+
14
+ h3. Use cases
9
15
 
10
- Install with @gem install sidekick@ and invoke it using the @sidekick@ shell command in your project folder. You should have a @.sidekick@ file in it. Here is a sample:
16
+ * Triggering server restart when code is changed
17
+ * Automatically compiling sass, CoffeeScript, etc.
18
+ * Continuous testing with notifications or hooks
19
+ * Periodically running commands
11
20
 
12
- <pre>
13
- <code lang='ruby'>
14
21
 
15
- # restarts passenger on file changes and
16
- # notifies via growl or libnotify
17
- watch '**/*.rb' do |paths|
18
- restart_passenger
19
- notify 'Are you tired of being notified yet?'
20
- end
22
+ You would typically run it in the background while coding, to automatize things like restarting development servers on file changes, recompiling assets, continously running tests or periodically running commands.
21
23
 
22
- # keeps the developers mind agile
23
- every(10) do
24
- notify sh('fortune')
25
- end
26
24
 
27
- </code>
28
- </pre>
25
+ h2. Basic usage
29
26
 
30
- The @watch@ and @every@ commands above are are triggers, while @notify@, @sh@, and @restart_passenger@ are helper methods.
27
+ Install with @gem install sidekick@ and invoke it using the @sidekick@ shell command in your project folder. If you do not have a @.sidekick@ file, you will be offered a template.
28
+
29
+ I recommend "reading the template":http://github.com/jbe/sidekick/blob/master/lib/template.
30
+
31
+ The @watch@ and @every@ commands you see in it are triggers, while @notify@, @sh@, and @restart_passenger@ are helper methods. Some helpers, like @auto_compile@ set up both triggers and actions for you.
31
32
 
32
33
  h3. Currently available triggers:
33
34
 
34
- |@watch(glob)@|run on file changes matching @glob@. Globs like Dir[]. |
35
+ |@watch(glob)@|run on file changes matching @glob@. Globs like @Dir[]@. |
35
36
  |@every(duration)@|run every @duration@ seconds|
36
37
 
37
38
  h3. Currently available helpers:
38
39
 
39
- |@sh@|run shell command, showing output, like in rake|
40
- |@log@|log events to screen. cleaner than puts.|
40
+ |@sh(cmd)@|run shell command, showing output, like in rake|
41
+ |@log(str)@|log events to screen. cleaner than puts.|
41
42
  |@notify@|notify user via growl, libnotify etc|
42
- |@running?(platform)@|os can be one of @[:linux, :darwin, :other]@|
43
- |@load_gem?(name)@|tries to load gem, true if success. otherwise false. informs user that more functions are available if they make it available|
43
+ |@auto_compile(source_glob, target_path)@|compile using tilt on file changes (language automatically detected -- see template examples and tilt documentation)|
44
44
  |@restart_passenger@|restart passenger based environments by touching tmp/restart.txt|
45
+ |@load_gem?(name)@|tries to load gem, true if success. otherwise false. informs user that more functions are available if they install it|
45
46
 
46
47
  h2. Writing extensions
47
48
 
@@ -59,12 +60,12 @@ To add more helpers, simply add methods to @Sidekick::Helpers@, like this:
59
60
  </code>
60
61
  </pre>
61
62
 
62
- When adding a group of methods it may be cleaner to use a separate module under @Sidekick::Helpers@, and then include it.
63
+ When adding a group of methods it may be cleaner to use a separate module under @Sidekick::Helpers@, and then including it.
63
64
 
64
65
 
65
66
  h3. Writing new triggers
66
67
 
67
- To add new triggers, you have two options: block or class interface. Blocks are best for simple stuff, while classes are good for more complex code. This is how you set up a new trigger using a block:
68
+ To add new triggers, you have two options: blocks, and classes. Blocks are best for simple stuff, while classes are good for more complex code. This is how you set up a new trigger using a block:
68
69
 
69
70
  <pre>
70
71
  <code lang='ruby'>
@@ -78,9 +79,9 @@ end
78
79
  </code>
79
80
  </pre>
80
81
 
81
- This is the internal implementation of the @every@ function mentioned earlier. The @timeshare@ method is provided by Sidekick to all extensions, and will call the supplied block each @duration@ seconds. This is also useful for polling something without blocking or forking.
82
+ This is the internal implementation of the @every@ function seen earlier. The @timeshare@ method is provided by Sidekick to all extensions, and will call the supplied block every @duration@ seconds. This is also useful for polling something without blocking or forking.
82
83
 
83
- Triggers can also be written as a class interface. Here is an example of the above, translated as a class:
84
+ Next, here is an example of the above written as a class:
84
85
 
85
86
  <pre>
86
87
  <code lang='ruby'>
@@ -106,15 +107,17 @@ Sidekick::Triggers.register_class(:watch, Watch)
106
107
  </code>
107
108
  </pre>
108
109
 
109
- Here, the optional @poll@ method functions like the callback block in the previous example. The @poll_freq@ method is also optional, and determines the frequency in seconds with which to call @poll@. Finally, notice the last statement, which registers the class.
110
+ The @poll@ and @poll_freq@ methods are optional. @poll@ functions like the callback block in the previous example, while @poll_freq@ functions like the @duration@ argument, specifying how often to call @poll@ in seconds. Only integers are accepted. Finally, notice the last statement, which registers the class.
110
111
 
111
112
  h2. Final lines...
112
113
 
113
- The main code chunk is just under 100 lines including documentation, excluding the default triggers and helpers. Why not read it..?
114
+ The main code chunk of Sidekick is just under 100 lines, including documentation, excluding the default triggers and helpers. Why not read it..?
115
+
116
+ You can keep your extensions in the @.sidekick@ file itself, or package them in gems, or ask me to merge them into the main repository.
114
117
 
115
- You can keep your extensions in the @.sidekick@ file itself, or package in a separate gem, or ask me to merge them into the main repository.
118
+ Similar projects:
116
119
 
117
- I got a bit of inspiration from the somewhat similar project "Guard":http://github.com/guard/guard
120
+ * "Guard":http://github.com/guard/guard (too enterprisey for me)
118
121
 
119
122
 
120
123
  h3. Copyright
data/Rakefile CHANGED
@@ -5,13 +5,12 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "sidekick"
8
- gem.summary = %Q{Automatically run common project tasks according to triggers defined in .sidekick}
9
- gem.description = %Q{Automatically run common project tasks according to triggers defined in a .sidekick file. Easy, powerful configuration per project. Provides pre-defined sidekicks for things like watching for file changes, and allows easy definition of new ones. Contains helpers for common tasks such as compiling assets or triggering development server restarts.}
8
+ gem.summary = %Q{Automatically run common development tasks on events, as defined by a local .sidekick file.}
9
+ gem.description = %Q{Automatically run common development tasks on events, as defined by a local .sidekick file. Easy, powerful dsl. Several pre-defined triggers. Helper methods for common tasks. Easy to extend with new triggers and helpers.}
10
10
  gem.email = "post@jostein.be"
11
11
  gem.homepage = "http://github.com/jbe/sidekick"
12
12
  gem.authors = ["Jostein Berre Eliassen,"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ gem.add_dependency "tilt", ">= 1"
15
14
  end
16
15
  Jeweler::GemcutterTasks.new
17
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
data/bin/sidekick CHANGED
@@ -7,4 +7,7 @@ rescue LoadError
7
7
  require 'sidekick'
8
8
  end
9
9
 
10
+ puts ' ^ ^ ^ ^ '
11
+ puts ' == SIDEKICK == ^ ctrl-c to exit ^'
12
+ puts ' '
10
13
  Sidekick.run!
data/lib/sidekick.rb CHANGED
@@ -1,4 +1,4 @@
1
-
1
+ require 'fileutils'
2
2
 
3
3
  module Sidekick
4
4
 
@@ -6,7 +6,14 @@ module Sidekick
6
6
  # evaluates the .sidekick config file within
7
7
  # its own scope
8
8
  def self.run!(conf_path='.sidekick')
9
- abort('No .sidekick file!') unless File.exists?(conf_path)
9
+ unless File.exists?(conf_path)
10
+ puts 'Generate new sidekick file? (Y/n)'
11
+ unless gets =~ /^N|n/ # 1.8 and 1.9 compatibility
12
+ FileUtils.cp(File.expand_path('../template', __FILE__), conf_path)
13
+ else
14
+ exit
15
+ end
16
+ end
10
17
  Context.new(conf_path)
11
18
  Triggers.enter_loop
12
19
  end
@@ -93,4 +100,3 @@ end
93
100
 
94
101
  require 'sidekick/helpers'
95
102
  require 'sidekick/triggers'
96
-
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'rbconfig'
3
+ require 'tilt'
3
4
 
4
5
 
5
6
  # default helpers
@@ -68,4 +69,29 @@ module Sidekick::Helpers
68
69
  log 'restarted passenger'
69
70
  end
70
71
 
72
+
73
+
74
+
75
+ # watches for changes matching the source glob,
76
+ # compiles using the tilt gem, and saves to
77
+ # target. Target is interpolated for :name
78
+ def auto_compile(source, target)
79
+ watch(source) do |files|
80
+ files.each do |file|
81
+ begin
82
+ target.gsub! ':name', File.basename(file, '.*')
83
+ File.open(target, 'w') do |f|
84
+ f.write(Tilt.new(file).render)
85
+ end
86
+ log "rendered #{file} => #{target}"
87
+ rescue Exception => e
88
+ notify "Error in #{file}:\n#{e}"
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+
95
+
96
+
71
97
  end
data/lib/template ADDED
@@ -0,0 +1,26 @@
1
+
2
+
3
+
4
+
5
+ abort "A new .sidekick file was generated -- now you just have to edit it."
6
+
7
+
8
+ # now delete the above, and tell me what to do.
9
+ # here are some samples:
10
+
11
+ # watch('**/*.rb') { restart_passenger }
12
+ #
13
+ # auto_compile 'assets/css/*.sass', 'public/css/:name.css'
14
+ #
15
+ # auto_compile 'assets/js/*.coffee', 'public/js/:name.js'
16
+ #
17
+ # every(60) { notify 'You are now one minute older.' }
18
+ #
19
+ # every(60*15) { notify sh fortune }
20
+
21
+
22
+
23
+
24
+
25
+
26
+ # vim:ft=ruby
data/sidekick.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sidekick}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jostein Berre Eliassen,"]
12
- s.date = %q{2010-10-24}
12
+ s.date = %q{2010-10-25}
13
13
  s.default_executable = %q{sidekick}
14
- s.description = %q{Automatically run common project tasks according to triggers defined in a .sidekick file. Easy, powerful configuration per project. Provides pre-defined sidekicks for things like watching for file changes, and allows easy definition of new ones. Contains helpers for common tasks such as compiling assets or triggering development server restarts.}
14
+ s.description = %q{Automatically run common development tasks on events, as defined by a local .sidekick file. Easy, powerful dsl. Several pre-defined triggers. Helper methods for common tasks. Easy to extend with new triggers and helpers.}
15
15
  s.email = %q{post@jostein.be}
16
16
  s.executables = ["sidekick"]
17
17
  s.extra_rdoc_files = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/sidekick/helpers.rb",
32
32
  "lib/sidekick/triggers.rb",
33
33
  "lib/sidekick/triggers/watch.rb",
34
+ "lib/template",
34
35
  "sidekick.gemspec",
35
36
  "test/helper.rb",
36
37
  "test/test_sidekick.rb"
@@ -39,7 +40,7 @@ Gem::Specification.new do |s|
39
40
  s.rdoc_options = ["--charset=UTF-8"]
40
41
  s.require_paths = ["lib"]
41
42
  s.rubygems_version = %q{1.3.7}
42
- s.summary = %q{Automatically run common project tasks according to triggers defined in .sidekick}
43
+ s.summary = %q{Automatically run common development tasks on events, as defined by a local .sidekick file.}
43
44
  s.test_files = [
44
45
  "test/helper.rb",
45
46
  "test/test_sidekick.rb"
@@ -50,12 +51,12 @@ Gem::Specification.new do |s|
50
51
  s.specification_version = 3
51
52
 
52
53
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_runtime_dependency(%q<tilt>, [">= 1"])
54
55
  else
55
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
56
+ s.add_dependency(%q<tilt>, [">= 1"])
56
57
  end
57
58
  else
58
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
59
+ s.add_dependency(%q<tilt>, [">= 1"])
59
60
  end
60
61
  end
61
62
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 1
9
- version: 0.2.1
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jostein Berre Eliassen,
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-24 00:00:00 +02:00
17
+ date: 2010-10-25 00:00:00 +02:00
18
18
  default_executable: sidekick
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
21
+ name: tilt
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
@@ -26,11 +26,11 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
- - 0
30
- version: "0"
31
- type: :development
29
+ - 1
30
+ version: "1"
31
+ type: :runtime
32
32
  version_requirements: *id001
33
- description: Automatically run common project tasks according to triggers defined in a .sidekick file. Easy, powerful configuration per project. Provides pre-defined sidekicks for things like watching for file changes, and allows easy definition of new ones. Contains helpers for common tasks such as compiling assets or triggering development server restarts.
33
+ description: Automatically run common development tasks on events, as defined by a local .sidekick file. Easy, powerful dsl. Several pre-defined triggers. Helper methods for common tasks. Easy to extend with new triggers and helpers.
34
34
  email: post@jostein.be
35
35
  executables:
36
36
  - sidekick
@@ -52,6 +52,7 @@ files:
52
52
  - lib/sidekick/helpers.rb
53
53
  - lib/sidekick/triggers.rb
54
54
  - lib/sidekick/triggers/watch.rb
55
+ - lib/template
55
56
  - sidekick.gemspec
56
57
  - test/helper.rb
57
58
  - test/test_sidekick.rb
@@ -86,7 +87,7 @@ rubyforge_project:
86
87
  rubygems_version: 1.3.7
87
88
  signing_key:
88
89
  specification_version: 3
89
- summary: Automatically run common project tasks according to triggers defined in .sidekick
90
+ summary: Automatically run common development tasks on events, as defined by a local .sidekick file.
90
91
  test_files:
91
92
  - test/helper.rb
92
93
  - test/test_sidekick.rb