From 755b9a3a11baffa773284afcb071e7bfab128c28 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 23 Jul 2010 20:41:52 -0700 Subject: [PATCH] [Extensions] Make it possible for extensions to create empty directories. Closes GH-173. --- doc-src/content/tutorials/extensions.markdown | 12 +++++++++++- lib/compass/installers/base.rb | 13 +++++++++++++ lib/compass/installers/manifest.rb | 1 + lib/compass/installers/manifest_installer.rb | 8 +++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/doc-src/content/tutorials/extensions.markdown b/doc-src/content/tutorials/extensions.markdown index 969142a0..2e25f05b 100644 --- a/doc-src/content/tutorials/extensions.markdown +++ b/doc-src/content/tutorials/extensions.markdown @@ -165,13 +165,14 @@ You may also see some real manifest files here: ### Manifest Declarations -There are five kinds of manifest declarations: +There are six kinds of manifest declarations: 1. `stylesheet` - Declares a sass file. 2. `image` - Declares an image. 3. `javascript` - Declares a javascript file. 4. `html` - Declares an html file. 5. `file` - Declares a random file. +6. `directory` - Declares a directory should be created. All declarations take the path to the file as their first argument. Note that the normal slash `/` can and should be used in a manifest. Compass will take care of @@ -196,6 +197,15 @@ Stylesheet options: * `:condition` - this is used to hint the user that a conditional comment should be used to import the stylesheet with the given condition. +Directory options: + +* `:within` - where the directory should be created. If omitted, the directory + will be relative to the project directory. Can be one of: the following + * `sass_dir` + * `javascripts_dir` + * `fonts_dir` + * `images_dir` + HTML files: You can provide html as haml or as plain html. If you provide haml, the haml will be diff --git a/lib/compass/installers/base.rb b/lib/compass/installers/base.rb index 36c5f3ab..e5c7a345 100644 --- a/lib/compass/installers/base.rb +++ b/lib/compass/installers/base.rb @@ -116,6 +116,19 @@ module Compass "#{pattern_name_as_dir}#{to}" end + def install_directory(from, to, options) + d = if within = options[:within] + if respond_to?(within) + targetize("#{send(within)}/#{to}") + else + raise Compass::Error, "Unrecognized location: #{within}" + end + else + targetize(to) + end + directory d + end + alias install_html_without_haml install_html def install_html(from, to, options) if to =~ /\.haml$/ diff --git a/lib/compass/installers/manifest.rb b/lib/compass/installers/manifest.rb index 4324be66..4b2ea19e 100644 --- a/lib/compass/installers/manifest.rb +++ b/lib/compass/installers/manifest.rb @@ -40,6 +40,7 @@ module Compass type :font type :file type :html + type :directory def help(value = nil) if value diff --git a/lib/compass/installers/manifest_installer.rb b/lib/compass/installers/manifest_installer.rb index d48ff5ad..04e1d909 100644 --- a/lib/compass/installers/manifest_installer.rb +++ b/lib/compass/installers/manifest_installer.rb @@ -17,9 +17,11 @@ module Compass # Initializes the project to work with compass def init dirs = manifest.map do |entry| - loc = send("install_location_for_#{entry.type}", entry.to, entry.options) - File.dirname(loc) - end + unless entry.type == :directory + loc = send("install_location_for_#{entry.type}", entry.to, entry.options) + File.dirname(loc) + end + end.compact if manifest.has_stylesheet? dirs << sass_dir