Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use an around filter for coffeescript
  • Loading branch information
Sutto committed Apr 24, 2010
1 parent 762266f commit 591a9ba
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/barista_controller.rb
Expand Up @@ -2,6 +2,7 @@ class BaristaController < ActionController::Base

caches_page :show if Rails.env.production?

# Used for rendering on the fly.
def show
headers['Content-Type'] = "application/javascript"
path = normalize_path(params[:js_path])
Expand Down
14 changes: 13 additions & 1 deletion lib/barista.rb
Expand Up @@ -3,7 +3,8 @@

module Barista

autoload :Compiler, 'barista/compiler'
autoload :Compiler, 'barista/compiler'
autoload :AroundFilter, 'barista/around_filter'

class << self

Expand Down Expand Up @@ -53,13 +54,24 @@ def compile_all!(force = false)
true
end

# By default, only add it in dev / test
def add_filter?
Rails.env.test? || Rails.env.development?
end

end

if defined?(Rails::Engine)
class Engine < Rails::Engine

rake_tasks do
load File.expand_path('./barista/tasks/barista.rake', File.dirname(__FILE__))
end

initializer "barista.wrap_filter" do
ApplicationController.around_filter(Barista::AroundFilter) if Barista.add_filter?
end

end
end

Expand Down
10 changes: 10 additions & 0 deletions lib/barista/around_filter.rb
@@ -0,0 +1,10 @@
module Barista
class AroundFilter

def self.filter(controller)
Barista.compile_all!
yield if block_given?
end

end
end
2 changes: 1 addition & 1 deletion lib/barista/version.rb
Expand Up @@ -2,7 +2,7 @@ module Barista
module Version
MAJOR = 0
MINOR = 1
PATCH = 0
PATCH = 1
STRING = [MAJOR, MINOR, PATCH].join(".")
end
end

0 comments on commit 591a9ba

Please sign in to comment.