New framework discovery mechanism: Compass can now load any number of

frameworks by passing a directory that contains those frameworks. Each
framework can choose to adhere to the naming convention of providing a
'stylesheets' directory and a 'templates' directory, or it can register
itself by providing a ruby file at one of the following locations:

<plugin>/compass_init.rb
<plugin>/lib/<plugin>.rb
<plugin>/<plugin>.rb

The first file found in the above order will be required. The framework
should register itself there using the Compass::Frameworks.register method.
This commit is contained in:
Chris Eppstein 2009-07-26 18:10:07 -07:00
parent a0036ec0f1
commit bc27541378
4 changed files with 30 additions and 10 deletions

View File

@ -1,2 +0,0 @@
blueprint_dir = File.join(Compass.base_directory, 'frameworks', 'blueprint')
Compass::Frameworks.register('blueprint', blueprint_dir)

View File

@ -1,2 +0,0 @@
compass_dir = File.join(Compass.base_directory, 'frameworks', 'compass')
Compass::Frameworks.register('compass', compass_dir)

View File

@ -1,6 +1,10 @@
module Compass
module Frameworks
extend self
ALL = []
DEFAULT_FRAMEWORKS_PATH = File.join(Compass.base_directory, 'frameworks')
class Framework
attr_accessor :name
attr_accessor :templates_directory, :stylesheets_directory
@ -12,18 +16,38 @@ module Compass
@stylesheets_directory = options[:stylesheets_directory] || File.join(path, 'stylesheets')
end
end
def register(name, *arguments)
ALL << Framework.new(name, *arguments)
end
def [](name)
ALL.detect{|f| f.name.to_s == name.to_s}
end
module_function :register, :[]
def discover(frameworks_directory)
frameworks_directory = DEFAULT_FRAMEWORKS_PATH if frameworks_directory == :defaults
frameworks_directory = Dir.new(frameworks_directory) unless frameworks_directory.is_a?(Dir)
frameworks_directory.entries.reject{|e| e[0] == ?.}.each do |framework|
register_directory File.join(frameworks_directory.path, framework)
end
end
def register_directory(directory)
loaders = [
File.join(directory, "compass_init.rb"),
File.join(directory, 'lib', File.basename(directory)+".rb"),
File.join(directory, File.basename(directory)+".rb")
]
loader = loaders.detect{|l| File.exists?(l)}
if loader
require loader
else
register File.basename(directory), directory
end
end
end
end
# Import all of the default frameworks.
default_frameworks_directory = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'frameworks'))
Dir.glob(File.join(default_frameworks_directory, "*.rb")).each do |framework|
require framework
end
Compass::Frameworks.discover(:defaults)