Sha256: 5ae81d5628d4ad76afcd2678e1b68ef6dca06de5a32c110ca7ebf3f015a471de

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

require 'barista' unless defined?(Barista)
require 'rake'
require 'rake/tasklib'

module Barista
  class RakeTask < ::Rake::TaskLib

    attr_writer :namespace, :task_name
    attr_writer :environment, :input_directory, :output_directory, :rails

    def initialize
      yield self if block_given?
      @namespace ||= :barista
      @task_name ||= :brew
      @task_name = @task_name.to_sym
      @rails     = defined?(Rails) if @rails.nil?

      task_declaration = (@rails ? {@task_name => :environment} : @task_name)

      namespace @namespace do
        desc "Compiles all CoffeeScript sources to JavaScript"
        task task_declaration do
          setup_barista
          check_availability
          puts "Compiling all CoffeeScripts to their JavaScript equivalent."
          Barista.compile_all! true, false
        end
      end
    end

    # Proxy methods for rake tasks

    def respond_to?(method, include_private = false)
      super || Barista.respond_to?(method, include_private)
    end

    def method_missing(method, *args, &blk)
      if Barista.respond_to?(method)
        Barista.send method, *args, &blk
      else
        super
      end
    end

    private

    def setup_barista
      Barista.env = @environment if @environment
      if @input_directory
        Barista.root = File.expand_path(@input_directory, Dir.pwd)
      end
      if @output_directory
        Barista.output_root = File.expand_path(@output_directory, Dir.pwd)
      end
    end

    def check_availability
      if !Barista::Compiler.available?
        if Barista::Compiler.bin_path.nil?
          $stderr.puts "CoffeeScript doesn't appear to be installed on this system and you're not using an embedded compiler."
        else
          $stderr.puts "'#{Barista::Compiler.bin_path}' was unavailable."
        end
        exit 1
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
barista-1.1.0 lib/barista/rake_task.rb
barista-1.1.0.pre1 lib/barista/rake_task.rb