Sha256: a2257b1ad4c1bcd436c406b9aaa9c93f84d94015e08bb5972075f853c0266833

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

require 'sprockets'
require 'uglifier'
require 'sass'

module Spontaneous::Asset
  # Takes assets from a source directory & compiles them to some destination directory.
  # This is deliberatly dumb about the path to the gem and destination
  class AppCompiler
    attr_reader :environment, :manifest

    def initialize(gem_path, dest_path, options = {})
      @options     = {:compress => true}.merge(options)
      @gem_path    = gem_path
      @dest_path   = dest_path
      @environment = Sprockets::Environment.new(gem_path / "application" )
      @manifest    = Sprockets::Manifest.new(@environment, @dest_path / "public/@spontaneous/assets")

      @environment.append_path(gem_path / "application/js")
      @environment.append_path(gem_path / "application/css")

      if @options[:compress]
        @environment.register_bundle_processor "application/javascript", :uglifier do |context, data|
          Uglifier.compile(data)
        end

        @environment.register_bundle_processor "text/css", :sass_compressor do |context, css|
          # By this point the SCSS has already been compiled, so SASS is merely a CSS compressor
          # and I can ignore crap around loadpaths or filenames.
          engine = ::Sass::Engine.new(css, :style => :compressed, :syntax => :scss, :quiet => true, :custom => { :resolver => self })
          engine.render
        end
      end
    end


    def compile
      @manifest.compile("spontaneous.js", "login.js", "require.js", "vendor/jquery.js", "spontaneous.css")
    end

    def image_path(path)
      path
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta9 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta8 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta7 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta6 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta5 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta4 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta3 lib/spontaneous/asset/app_compiler.rb
spontaneous-0.2.0.beta2 lib/spontaneous/asset/app_compiler.rb