Permalink
Browse files

Almost passing tests

  • Loading branch information...
1 parent e15526d commit 5e15c5c3be3bf7377761eada5de4ea7682ce3343 @quirkey committed Oct 2, 2011
View
@@ -1,6 +1,7 @@
module Soca
class Plugin
attr_reader :pusher
+ attr_accessor :options
def self.name(plugin_name)
@@plugins ||= {}
@@ -11,8 +12,9 @@ def self.plugins
@@plugins ||= {}
end
- def initialize(pusher)
+ def initialize(pusher, options = {})
@pusher = pusher
+ @options = options
end
def logger
@@ -14,7 +14,7 @@ class CoffeeScript < Soca::Plugin
# * :vars - Additional variables to interpolate. By default the `env` and
# `config` are interpolated.
#
- def run(options = {})
+ def before_build
file_patterns = options[:files] || '**/*.coffee'
files = Dir[*[file_patterns].flatten]
vars = {
@@ -8,27 +8,25 @@ class Compass < Soca::Plugin
name 'compass'
- def run(options = {})
- @options = options
-
+ def before_build
Soca.logger.info "compiling compass"
unless Soca.debug
- options = {:logger => ::Compass::NullLogger.new}.merge(options)
-
+ options = {:logger => ::Compass::NullLogger.new}.merge(self.options)
end
+
compass = ::Compass::Compiler.new(app_dir, compass_from, compass_to, ::Compass.sass_engine_options.merge(options || {}))
Soca.logger.debug "compass: #{compass.inspect}"
compass.run
end
private
def compass_from
- @options.has_key?(:from) ? File.join(app_dir, @options[:from]) : File.join(app_dir, 'sass')
+ options.has_key?(:from) ? File.join(app_dir, options[:from]) : File.join(app_dir, 'sass')
end
def compass_to
- @options.has_key?(:to) ? File.join(app_dir, @options[:to]) : File.join(app_dir, 'css')
+ options.has_key?(:to) ? File.join(app_dir, options[:to]) : File.join(app_dir, 'css')
end
end
end
View
@@ -6,7 +6,7 @@ class Jim < Soca::Plugin
name 'jim'
- def run(options = {})
+ def before_build
jimfile = File.join(app_dir, 'Jimfile')
::Jim.logger = logger
logger.debug "bundling js"
@@ -7,16 +7,17 @@ class Macro < Soca::Plugin
name 'macro'
- def run(options = {})
+ def before_push
@pusher.document['views'].each do |view,code|
['map','reduce'].each{|part| macro_expand_on(part,code) if code[part]}
end
end
+ private
def macro_expand_on(part,code)
code[part] = code[part].split("\n").inject(" ") do |res,line|
if line =~ /\/\/ !code (.*)/
- res += "\n#{File.read($1)}\n"
+ res += "\n#{File.read(File.join(pusher.app_dir, $1))}\n"
else
res += "#{line}\n"
end
@@ -14,7 +14,7 @@ class Mustache < Soca::Plugin
# * :vars - Additional variables to interpolate. By default the `env` and
# `config` are interpolated.
#
- def run(options = {})
+ def before_build
file_patterns = options[:files] || '*.mustache'
files = Dir[*[file_patterns].flatten]
vars = {
View
@@ -30,13 +30,13 @@ def load_couchapprc
def build
@document = {}
- run_hook_file!(:before_build)
+ run_hooks!(:before_build)
logger.debug "building app JSON"
Dir.glob(app_dir + '**/**') do |path|
next if File.directory?(path)
@document = map_file(path, @document)
end
- run_hook_file!(:after_build)
+ run_hooks!(:after_build)
@document
end
@@ -81,13 +81,13 @@ def get_current_revision
def push!
create_db!
build
- run_hook_file!(:before_push)
+ run_hooks!(:before_push)
get_current_revision
document['_rev'] = revision if revision
post_body = JSON.generate(document)
logger.debug "pushing document to #{push_url}"
put!(push_url, post_body)
- run_hook_file!(:after_push)
+ run_hooks!(:after_push)
end
def purge!
@@ -107,6 +107,11 @@ def logger
Soca.logger
end
+ def run_hooks!(hook)
+ run_hook_file!(hook)
+ run_plugin_hooks!(hook)
+ end
+
def run_hook_file!(hook)
hook_file_path = File.join(app_dir, 'hooks', "#{hook}.rb")
if File.readable? hook_file_path
@@ -118,10 +123,26 @@ def run_hook_file!(hook)
end
end
- def plugin(plugin_name, options = {})
- require "soca/plugins/#{plugin_name}"
- p = Soca::Plugin.plugins[plugin_name].new(self)
- p.run(options)
+ def run_plugin_hooks!(hook)
+ plugins.each do |plugin_name, plugin|
+ if plugin.respond_to?(hook)
+ plugin.send(hook)
+ end
+ end
+ end
+
+ def plugins
+ return @plugins if @plugins
+ if config['plugins']
+ @plugins = config['plugins'].map do |plugin_config|
+ plugin_name, plugin_options = [plugin_config].flatten
+ require "soca/plugins/#{plugin_name}"
+ [plugin_name, Soca::Plugin.plugins[plugin_name].new(self, plugin_options || {})]
+ end
+ else
+ @plugins = []
+ end
+ @plugins
end
private
@@ -7,8 +7,7 @@ def app_path(relative='')
context 'compass plugin' do
setup do
- pusher = Soca::Pusher.new(app_path)
- @plugin = Soca::Plugins::Compass.new(pusher)
+ @pusher = Soca::Pusher.new(app_path)
end
context 'given no options' do
@@ -17,7 +16,8 @@ def app_path(relative='')
with(@test_app_dir, app_path('sass'), app_path('css'), anything).
returns(mock(:run => true))
- @plugin.run
+ @plugin = Soca::Plugins::Compass.new(@pusher)
+ @plugin.before_build
end
end
@@ -27,7 +27,8 @@ def app_path(relative='')
with(@test_app_dir, app_path('app/sass'), app_path('css'), anything).
returns(mock(:run => true))
- @plugin.run :from => 'app/sass'
+ @plugin = Soca::Plugins::Compass.new(@pusher, :from => 'app/sass')
+ @plugin.before_build
end
end
@@ -37,7 +38,8 @@ def app_path(relative='')
with(@test_app_dir, app_path('sass'), app_path('snoop_dogg/css'), anything).
returns(mock(:run => true))
- @plugin.run :to => 'snoop_dogg/css'
+ @plugin = Soca::Plugins::Compass.new(@pusher, :to => 'snoop_dogg/css')
+ @plugin.before_build
end
end
@@ -47,7 +49,8 @@ def app_path(relative='')
with(@test_app_dir, app_path('app/sass'), app_path('app/css'), anything).
returns(mock(:run => true))
- @plugin.run :from => 'app/sass', :to => 'app/css'
+ @plugin = Soca::Plugins::Compass.new(@pusher, :from => 'app/sass', :to => 'app/css')
+ @plugin.before_build
end
end
end

0 comments on commit 5e15c5c

Please sign in to comment.