barista 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -40,19 +40,38 @@ is you can then manage js dependencies using existing tools like bundler.
40
40
  In your `Barista.configure` block, you can also configure on a per-application basis the output directory
41
41
  for individual frameworks (e.g. put shuriken into vendor/shuriken, bhm-google-maps into vendor/bhm-google-maps):
42
42
 
43
- Barista.configure do |config|
44
- config.change_output_prefix! 'shuriken', 'vendor/shuriken'
45
- config.change_output_prefix! 'bhm-google-maps', 'vendor/bhm-google-maps'
43
+ Barista.configure do |c|
44
+ c.change_output_prefix! 'shuriken', 'vendor/shuriken'
45
+ c.change_output_prefix! 'bhm-google-maps', 'vendor/bhm-google-maps'
46
46
  end
47
47
 
48
48
  Alternatively, to prefix all, you can use `Barista.each_framework` (if you pass true, it includes the 'default' framework
49
49
  which is your application root).
50
50
 
51
- Barista.configure do |config|
52
- config.each_framework do |framework|
53
- config.change_output_prefix! framework.name, "vendor/#{framework.name}"
51
+ Barista.configure do |c|
52
+ c.each_framework do |framework|
53
+ c.change_output_prefix! framework.name, "vendor/#{framework.name}"
54
54
  end
55
55
  end
56
+
57
+ ## Hooks ##
58
+
59
+ Barista lets you hook into the compilation at several stages. Namely:
60
+
61
+ * before compilation
62
+ * after compilation
63
+ * after compilation fails
64
+
65
+ To hook into these hooks, you can use like so:
66
+
67
+ * `Barista.before_compilation { |path| puts "Barista: Compiling #{path}" }`
68
+ * `Barista.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }`
69
+ * `Barista.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }`
70
+ * `Barista.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }`
71
+
72
+
73
+ These allow you to do things such as notify on compilation, automatically
74
+ perform compression post compilation and a variety of other cool things.
56
75
 
57
76
  ## Configuration ##
58
77
 
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ begin
13
13
  gem.homepage = "http://github.com/Sutto/barista"
14
14
  gem.version = Barista::Version::STRING
15
15
  gem.authors = ["Darcy Laycock"]
16
+ gem.add_dependency 'open4'
16
17
  end
17
18
  Jeweler::GemcutterTasks.new
18
19
  rescue LoadError
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{barista}
8
- s.version = "0.4.3"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Darcy Laycock"]
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  "lib/barista/compiler.rb",
30
30
  "lib/barista/filter.rb",
31
31
  "lib/barista/framework.rb",
32
+ "lib/barista/hooks.rb",
32
33
  "lib/barista/tasks/barista.rake",
33
34
  "lib/barista/version.rb",
34
35
  "lib/generators/barista_install/USAGE",
@@ -46,9 +47,12 @@ Gem::Specification.new do |s|
46
47
  s.specification_version = 3
47
48
 
48
49
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<open4>, [">= 0"])
49
51
  else
52
+ s.add_dependency(%q<open4>, [">= 0"])
50
53
  end
51
54
  else
55
+ s.add_dependency(%q<open4>, [">= 0"])
52
56
  end
53
57
  end
54
58
 
@@ -10,9 +10,38 @@ module Barista
10
10
  autoload :Compiler, 'barista/compiler'
11
11
  autoload :Filter, 'barista/filter'
12
12
  autoload :Framework, 'barista/framework'
13
+ autoload :Hooks, 'barista/hooks'
13
14
 
14
15
  class << self
15
16
 
17
+ def hooks
18
+ @hooks ||= Hooks.new
19
+ end
20
+
21
+ def on_hook(name, *args, &blk)
22
+ hooks.on(name, *args, &blk)
23
+ end
24
+
25
+ def invoke_hook(name, *args)
26
+ hooks.invoke(name, *args)
27
+ end
28
+
29
+ def on_compilation_error(&blk)
30
+ on_hook :compilation_failed, &blk
31
+ end
32
+
33
+ def on_compilation(&blk)
34
+ on_hook :compiled, &blk
35
+ end
36
+
37
+ def on_compilation_with_warning(&blk)
38
+ on_hook :compiled_with_warning, &blk
39
+ end
40
+
41
+ def before_compilation(&blk)
42
+ on_hook :before_compilation, &blk
43
+ end
44
+
16
45
  def configure
17
46
  yield self if block_given?
18
47
  end
@@ -1,4 +1,5 @@
1
1
  require 'digest/sha2'
2
+ require 'open4'
2
3
 
3
4
  module Barista
4
5
  class Compiler
@@ -53,19 +54,27 @@ module Barista
53
54
 
54
55
  def invoke_coffee(path)
55
56
  command = "#{self.class.bin_path} #{coffee_options} '#{path}'".squeeze(' ')
56
- result = %x(#{command}).to_s
57
- if !$?.success?
57
+ Barista.invoke_hook :before_compilation, path
58
+ pid, stdin, stdout, stderr = Open4.popen4(command)
59
+ stdin.close
60
+ _, status = Process.waitpid2(pid)
61
+ out = stdout.read.strip
62
+ err = stderr.read.strip
63
+ if status.success?
64
+ if err.blank?
65
+ Barista.invoke_hook :compiled, path
66
+ else
67
+ Barista.invoke_hook :compiled_with_warning, path, err
68
+ end
69
+ else
70
+ Barista.invoke_hook :compilation_failed, path, err
58
71
  if Barista.exception_on_error? && !@options[:silence]
59
72
  raise CompilationError, "\"#{command}\" exited with a non-zero status."
60
73
  else
61
- result = nil
74
+ out = nil
62
75
  end
63
76
  end
64
- result
65
- end
66
-
67
- def content_hash
68
- @content_hash ||= Digest::SHA256.hexdigest(@content)
77
+ out
69
78
  end
70
79
 
71
80
  end
@@ -0,0 +1,20 @@
1
+ module Barista
2
+ class Hooks
3
+
4
+ def initialize
5
+ @callbacks = Hash.new { |h,k| h[k] = [] }
6
+ end
7
+
8
+ def on(name, &blk)
9
+ @callbacks[name.to_sym] << blk
10
+ end
11
+
12
+ def invoke(name, *args)
13
+ @callbacks[name.to_sym].each do |callback|
14
+ break if callback.call(*args) == false
15
+ end
16
+ nil
17
+ end
18
+
19
+ end
20
+ end
@@ -1,8 +1,8 @@
1
1
  module Barista
2
2
  module Version
3
3
  MAJOR = 0
4
- MINOR = 4
5
- PATCH = 3
4
+ MINOR = 5
5
+ PATCH = 0
6
6
  STRING = [MAJOR, MINOR, PATCH].join(".")
7
7
  end
8
8
  end
@@ -24,6 +24,13 @@ Barista.configure do |c|
24
24
 
25
25
  # or, prefix the path for the app files:
26
26
 
27
- # c.change_output_prefix! :default, 'my-app-name'
27
+ # c.change_output_prefix! :default, 'my-app-name'
28
+
29
+ # or, hook into the compilation:
30
+
31
+ # c.before_compilation { |path| puts "Barista: Compiling #{path}" }
32
+ # c.on_compilation { |path| puts "Barista: Successfully compiled #{path}" }
33
+ # c.on_compilation_error { |path, output| puts "Barista: Compilation of #{path} failed with:\n#{output}" }
34
+ # c.on_compilation_with_warning { |path, output| puts "Barista: Compilation of #{path} had a warning:\n#{output}" }
28
35
 
29
36
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barista
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 4
9
- - 3
10
- version: 0.4.3
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Darcy Laycock
@@ -17,8 +17,21 @@ cert_chain: []
17
17
 
18
18
  date: 2010-07-18 00:00:00 +08:00
19
19
  default_executable:
20
- dependencies: []
21
-
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: open4
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
22
35
  description: Automatically compiles app/scripts/*.coffee to javascript for rails awesomesauce.
23
36
  email: sutto@sutto.net
24
37
  executables: []
@@ -41,6 +54,7 @@ files:
41
54
  - lib/barista/compiler.rb
42
55
  - lib/barista/filter.rb
43
56
  - lib/barista/framework.rb
57
+ - lib/barista/hooks.rb
44
58
  - lib/barista/tasks/barista.rake
45
59
  - lib/barista/version.rb
46
60
  - lib/generators/barista_install/USAGE