sidekick 0.6.5 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.sidekick CHANGED
@@ -13,5 +13,7 @@ auto_compile 'test/fixtures/*.sass', 'test/output/:name.css'
13
13
 
14
14
  auto_compile 'test/fixtures/*.coffee', 'test/output/:name.js'
15
15
 
16
+ auto_compress 'test/output/package.js', 'test/output/site.js'
17
+
16
18
 
17
19
  # vim:ft=ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.5
1
+ 0.7.0
@@ -2,21 +2,42 @@
2
2
 
3
3
  module Sidekick::Actions::Compile
4
4
 
5
- # Compiles one template using the `tilt` gem.
5
+ # write a file to disk
6
+ def write_file(path, data)
7
+ File.open(path, 'w') {|f| f.write(data) }
8
+ end
6
9
 
10
+ # Compile a template using the `tilt` gem.
7
11
  def compile(source, target)
8
12
  needs 'tilt', 'to compile templates'
9
13
  handling Exception, source do
10
- File.open(target, 'w') do |f|
11
- f.write(Tilt.new(source).render)
14
+ write_file target, Tilt.new(source).render
15
+ end
16
+ end
17
+
18
+ # compress a file using a suitable compressor for that
19
+ # file type.
20
+ def compress(source, target, opts={})
21
+ handling Exception, source do
22
+ case fmt = source.match(/\.[^\.]+$/).to_s
23
+ when '.js'
24
+ needs 'uglifier', 'to compress javascript'
25
+ write_file target, Uglifier.new(opts).compile(File.read(source))
26
+ else raise "Does not know how to compress #{fmt} files."
12
27
  end
13
28
  end
14
29
  end
15
30
 
31
+ # Concatenate a bunch of files, preserving order
32
+ def concat(target, *sources)
33
+ write_file target, sources.map {|p| File.read(p) }.join("\n")
34
+ end
35
+
16
36
 
17
- # watches for changes matching the `source` glob, and compiles to `target`, replacing ':name' in `target` with the basename of the changed file.
37
+ # watches for changes matching the `source` glob, and compiles to
38
+ # `target`, replacing ':name' in `target` with the basename of the
39
+ # changed file.
18
40
  def auto_compile(source, target)
19
-
20
41
  watch(source) do |files|
21
42
  files.each do |file|
22
43
  if File.exists?(file)
@@ -28,4 +49,20 @@ module Sidekick::Actions::Compile
28
49
  end
29
50
  end
30
51
 
52
+
53
+
54
+ # Watch for changes to several source files, concatenating to `target_base.concat.type`
55
+ # and then compressing as per file type.
56
+ def auto_compress(target, *sources)
57
+ fmt = target.match(/\.[^\.]+$/).to_s
58
+ cat_path = target.sub(/#{fmt}$/, '.concat' + fmt)
59
+
60
+ watch(*sources) do |files|
61
+ concat(cat_path, *sources)
62
+ compress(cat_path, target)
63
+ log "compress => #{target}"
64
+ end
65
+ end
66
+
67
+
31
68
  end
@@ -3,12 +3,12 @@
3
3
  module Sidekick::Actions::Triggers
4
4
 
5
5
 
6
- def watch(glob)
6
+ def watch(*globs)
7
7
  needs 'em-dir-watcher', 'to watch file changes'
8
8
 
9
9
  EMDirWatcher.watch(
10
10
  File.expand_path('.'),
11
- :include_only => [glob],
11
+ :include_only => globs,
12
12
  :grace_period => 0.2
13
13
  ) do |paths|
14
14
  log_trigger "watch #{paths.inspect}"
@@ -22,6 +22,11 @@ stop "File generated. Now please fill it in."
22
22
  # auto_compile 'assets/css/*.sass', 'public/css/:name.css'
23
23
  # auto_compile 'assets/js/*.coffee', 'public/js/:name.js'
24
24
 
25
+ # auto_compress( 'public/package.js',
26
+ # 'public/vendor/jquery.js',
27
+ # 'public/js/*.js'
28
+ # )
29
+
25
30
  # passenger_server 3002
26
31
 
27
32
 
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 6
8
- - 5
9
- version: 0.6.5
7
+ - 7
8
+ - 0
9
+ version: 0.7.0
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: 2011-04-06 00:00:00 +02:00
17
+ date: 2011-04-11 00:00:00 +02:00
18
18
  default_executable: sidekick
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency