module RapperLite::Config

Public Instance Methods

compress?( type ) click to toggle source

True if we should compress files of the given type.

# File lib/rapper_lite/config.rb, line 14
def compress?( type )
  self.config_or_default( "compress", type, false )
end
destination( type ) click to toggle source

Destination path for files of the given type.

# File lib/rapper_lite/config.rb, line 9
def destination( type )
  self.config_or_default( "destination", type, "." )
end
destination_path( type, name ) click to toggle source
# File lib/rapper_lite/config.rb, line 45
def destination_path( type, name )
  File.join( self.destination( type ), "#{name}.#{type}" )
end
file_paths( type, name ) click to toggle source

Array of source files for the given asset package.

# File lib/rapper_lite/config.rb, line 28
def file_paths( type, name )
  @definitions[type][name]["files"].map do |file|
    if file[0] == "+"
      # Include other asset package
      self.file_paths( type, file[1..-1] )
    elsif type == :js
      coffee_path = File.join( self.root( type ), "#{file}.coffee" )
      js_path = File.join( self.root( type ), "#{file}.js" )
      File.exists?( coffee_path ) ? coffee_path : js_path
    else # CSS
      sass_path = File.join( self.root( type ), "#{file}.sass" )
      css_path = File.join( self.root( type ), "#{file}.css" )
      File.exists?( sass_path ) ? sass_path : css_path
    end
  end.flatten
end
root( type ) click to toggle source

Source path for files of the given type.

# File lib/rapper_lite/config.rb, line 4
def root( type )
  self.config_or_default( "root", type, "." )
end
yui_config() click to toggle source
# File lib/rapper_lite/config.rb, line 18
def yui_config
  @yui_config ||= {
    "line_break" => 2000,
    "munge" => false,
    "optimize" => true,
    "preserve_semicolons" => false
  }.merge( @config["yui_compressor"] || {} )
end

Protected Instance Methods

config_or_default( key, type, default ) click to toggle source
# File lib/rapper_lite/config.rb, line 67
def config_or_default( key, type, default )
  if @definitions[type].key?( key )
    @definitions[type][key]
  else
    @config.key?( key ) ? @config[key] : default
  end
end
load_config( config_path ) click to toggle source
# File lib/rapper_lite/config.rb, line 51
def load_config( config_path )
  @config_path = config_path
  @config = YAML.load_file( @config_path )
  @definitions = {
    :css => @config["css"],
    :js => @config["js"]
  }
end
save_config() click to toggle source

Write in-memory config to file (i.e. just update version strings).

# File lib/rapper_lite/config.rb, line 61
def save_config
  File.open( @config_path, "w" ) do |file|
    file.puts( @config.to_yaml )
  end
end