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
|
module Compass
|
||||||
class Configuration
|
class Configuration
|
||||||
include Singleton
|
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
|
# parses a manifest file which is a ruby script
|
||||||
# evaluated in a Manifest instance context
|
# evaluated in a Manifest instance context
|
||||||
def parse(config_file)
|
def parse(config_file)
|
||||||
open(config_file) do |f|
|
open(config_file) do |f|
|
||||||
eval(f.read, instance_binding, config_file)
|
parse_string(f.read, config_file)
|
||||||
end
|
end
|
||||||
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!
|
def reset!
|
||||||
[:project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |attr|
|
[:project_path, :css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |attr|
|
||||||
send("#{attr}=", nil)
|
send("#{attr}=", nil)
|
||||||
end
|
end
|
||||||
|
self.required_libraries = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def instance_binding
|
def require(lib)
|
||||||
binding
|
required_libraries << lib
|
||||||
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
module ConfigHelpers
|
module ConfigHelpers
|
||||||
@ -45,6 +74,17 @@ module Compass
|
|||||||
def configure_sass_plugin!
|
def configure_sass_plugin!
|
||||||
Sass::Plugin.options.merge!(sass_plugin_configuration)
|
Sass::Plugin.options.merge!(sass_plugin_configuration)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
extend ConfigHelpers
|
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