Fixed a bug in the configuration parser.
Added Compass#sass_engine_options method to emit sass options suitable for passing to Sass::Engine#new. Added require tracking in the configuration parser and serializer.
This commit is contained in:
parent
e865d91dd2
commit
39a4b48b5e
@ -3,25 +3,54 @@ require 'singleton'
|
||||
module Compass
|
||||
class Configuration
|
||||
include Singleton
|
||||
attr_accessor :project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir
|
||||
attr_accessor :project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir, :required_libraries
|
||||
|
||||
def initialize
|
||||
self.required_libraries = []
|
||||
end
|
||||
|
||||
# parses a manifest file which is a ruby script
|
||||
# evaluated in a Manifest instance context
|
||||
def parse(config_file)
|
||||
open(config_file) do |f|
|
||||
eval(f.read, instance_binding, config_file)
|
||||
parse_string(f.read, config_file)
|
||||
end
|
||||
end
|
||||
|
||||
def parse_string(contents, filename)
|
||||
eval(contents, binding, filename)
|
||||
[:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |prop|
|
||||
value = eval(prop.to_s, binding) rescue nil
|
||||
self.send("#{prop}=", value) if value
|
||||
end
|
||||
end
|
||||
|
||||
def serialize
|
||||
contents = ""
|
||||
required_libraries.each do |lib|
|
||||
contents << %Q{require '#{lib}'\n}
|
||||
end
|
||||
contents << "\n" if required_libraries.any?
|
||||
[:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |prop|
|
||||
value = send(prop)
|
||||
contents << %Q(#{prop} = "#{value}"\n) if value
|
||||
end
|
||||
contents
|
||||
end
|
||||
|
||||
# Support for testing.
|
||||
def reset!
|
||||
[:project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |attr|
|
||||
send("#{attr}=", nil)
|
||||
end
|
||||
self.required_libraries = []
|
||||
end
|
||||
|
||||
def instance_binding
|
||||
binding
|
||||
def require(lib)
|
||||
required_libraries << lib
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
module ConfigHelpers
|
||||
@ -45,6 +74,17 @@ module Compass
|
||||
def configure_sass_plugin!
|
||||
Sass::Plugin.options.merge!(sass_plugin_configuration)
|
||||
end
|
||||
|
||||
def sass_engine_options
|
||||
load_paths = []
|
||||
if configuration.project_path && configuration.sass_dir
|
||||
load_paths << File.join(configuration.project_path, configuration.sass_dir)
|
||||
end
|
||||
Compass::Frameworks::ALL.each do |framework|
|
||||
load_paths << framework.stylesheets_directory
|
||||
end
|
||||
{:load_paths => load_paths}
|
||||
end
|
||||
end
|
||||
|
||||
extend ConfigHelpers
|
||||
|
28
test/configuration_test.rb
Normal file
28
test/configuration_test.rb
Normal file
@ -0,0 +1,28 @@
|
||||
require File.dirname(__FILE__)+'/test_helper'
|
||||
require 'compass'
|
||||
|
||||
class ConfigurationTest < Test::Unit::TestCase
|
||||
def test_parse_and_serialize
|
||||
contents = <<-CONFIG
|
||||
require 'compass'
|
||||
require 'sass'
|
||||
|
||||
css_dir = "css"
|
||||
sass_dir = "sass"
|
||||
images_dir = "img"
|
||||
javascripts_dir = "js"
|
||||
CONFIG
|
||||
|
||||
Compass.configuration.parse_string(contents, "test_parse")
|
||||
|
||||
assert_equal 'sass', Compass.configuration.sass_dir
|
||||
assert_equal 'css', Compass.configuration.css_dir
|
||||
assert_equal 'img', Compass.configuration.images_dir
|
||||
assert_equal 'js', Compass.configuration.javascripts_dir
|
||||
|
||||
expected_lines = contents.split("\n").map{|l|l.strip}
|
||||
actual_lines = Compass.configuration.serialize.split("\n").map{|l|l.strip}
|
||||
assert_equal expected_lines, actual_lines
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user