module RapperLite::Build

Public Instance Methods

build_package( type, name ) click to toggle source
# File lib/rapper_lite/build.rb, line 6
def build_package( type, name )
  source_paths = self.file_paths( type, name )
  destination_file = self.destination_path( type, name )
  tempfiles = []
  
  source_paths.map! do |source_path|
    tempfile, path = self.process( source_path )
    # Keep reference so GC doesn't unlink file
    tempfiles << tempfile if tempfile
    path
  end
  
  # Join files and compress if needed
  self.join_files( source_paths, destination_file )
  self.compress( destination_file ) if self.compress?( type )
  
  # Cleanup
  tempfiles.each{ |tempfile| tempfile.unlink }
end

Protected Instance Methods

conversion_engine( source_path ) click to toggle source
# File lib/rapper_lite/build.rb, line 47
def conversion_engine( source_path )
  {
    ".sass" => Sass,
    ".coffee" => CoffeeScript
  }[File.extname( source_path )]
end
process( source_path ) click to toggle source

Returns tuple: [nil or Tempfile, path to file]

# File lib/rapper_lite/build.rb, line 29
def process( source_path )
  tempfile = nil
  path = source_path
  
  if engine = self.conversion_engine( source_path )
    tempfile = Tempfile.new( "rapper_lite_source" )
    if engine == Sass
      tempfile.write( engine.compile( File.read( source_path ), :syntax => :sass ) )
    else
      tempfile.write( engine.compile( File.read( source_path ) ) )
    end
    tempfile.close
    path = tempfile.path
  end
  
  [tempfile, path]
end