Skip to content
Browse files

Added mustache plugin for interpolating files on push

  • Loading branch information...
1 parent a4f071e commit db9cfff73f809104a5dce828b1d8b6ab8e66cc85 @quirkey quirkey committed Oct 26, 2010
Showing with 43 additions and 6 deletions.
  1. +1 −1 lib/soca/plugin.rb
  2. +1 −1 lib/soca/plugins/compass.rb
  3. +1 −1 lib/soca/plugins/jim.rb
  4. +37 −0 lib/soca/plugins/mustache.rb
  5. +2 −2 lib/soca/pusher.rb
  6. +1 −1 soca.gemspec
View
2 lib/soca/plugin.rb
@@ -15,7 +15,7 @@ def initialize(pusher)
@pusher = pusher
end
- def run
+ def run(options = {})
raise "you need to subclass plugin and provide your own logic, please"
end
View
2 lib/soca/plugins/compass.rb
@@ -8,7 +8,7 @@ class Compass < Soca::Plugin
name 'compass'
- def run
+ def run(options = {})
Soca.logger.info "compiling compass"
compass_from = File.join(app_dir, 'sass')
compass_to = File.join(app_dir, 'css')
View
2 lib/soca/plugins/jim.rb
@@ -6,7 +6,7 @@ class Jim < Soca::Plugin
name 'jim'
- def run
+ def run(options = {})
jimfile = File.join(app_dir, 'Jimfile')
::Jim.logger = logger
logger.debug "bundling js"
View
37 lib/soca/plugins/mustache.rb
@@ -0,0 +1,37 @@
+require 'mustache'
+
+module Soca
+ module Plugins
+ class Mustache < Soca::Plugin
+
+ name 'mustache'
+
+ # Run the mustache plugin.
+ # Available options:
+ #
+ # * :files - Run these files through mustache. Can be an array of patterns
+ # or a single file. The default is '*.mustache'.
+ # * :vars - Additional variables to interpolate. By default the `env` and
+ # `config` are interpolated.
+ #
+ def run(options = {})
+ file_patterns = options[:files] || '*.mustache'
+ files = Dir[*[file_patterns].flatten]
+ vars = {:env => pusher.env, :config => pusher.config}.merge(options[:vars])
+ Soca.logger.debug "Mustache vars: #{vars}"
+ files.each do |file|
+ Soca.logger.debug "Running #{file} through mustache."
+ basename = File.basename(file)
+ dir = File.dirname(file)
+ parts = basename.split(/\./)
+ new_file = parts.length > 2 ? parts[0..-2].join('.') : basename[0] + ".html"
+ File.open(File.join(dir, new_file), 'w') do |f|
+ f << Mustache.render(File.read(file), vars)
+ end
+ Soca.logger.debug "Wrote to #{new_file}"
+ end
+ end
+
+ end
+ end
+end
View
4 lib/soca/pusher.rb
@@ -118,10 +118,10 @@ def run_hook_file!(hook)
end
end
- def plugin(plugin_name)
+ def plugin(plugin_name, options = {})
require "soca/plugins/#{plugin_name}"
p = Soca::Plugin.plugins[plugin_name].new(self)
- p.run
+ p.run(options)
end
private
View
2 soca.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Aaron Quint"]
- s.date = %q{2010-10-11}
+ s.date = %q{2010-10-26}
s.default_executable = %q{soca}
s.description = %q{soca is a different way of writing apps for CouchDB. The structure is up to you.}
s.email = %q{aaron@quirkey.com}

0 comments on commit db9cfff

Please sign in to comment.
Something went wrong with that request. Please try again.