From 853e97f2e4c147d8042bb8be7f7ad8f857bcc626 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Thu, 22 Oct 2009 09:46:46 -0700 Subject: [PATCH] [Command Line] Ability to create a bare project with no stylesheets provided. --- features/command_line.feature | 14 +++++ .../step_definitions/command_line_steps.rb | 22 +++++++ .../app_integration/rails/installer.rb | 4 +- .../app_integration/stand_alone/installer.rb | 4 +- lib/compass/commands/create_project.rb | 7 +++ lib/compass/commands/installer_command.rb | 8 ++- lib/compass/exec.rb | 1 + lib/compass/installers.rb | 2 +- lib/compass/installers/bare_installer.rb | 13 ++++ lib/compass/installers/base.rb | 56 ++---------------- lib/compass/installers/manifest_installer.rb | 59 +++++++++++++++++++ test/command_line_helper.rb | 6 +- 12 files changed, 139 insertions(+), 57 deletions(-) create mode 100644 lib/compass/installers/bare_installer.rb create mode 100644 lib/compass/installers/manifest_installer.rb diff --git a/features/command_line.feature b/features/command_line.feature index e121fcb2..9a978c27 100644 --- a/features/command_line.feature +++ b/features/command_line.feature @@ -59,3 +59,17 @@ Feature: Command Line And I am told how to link to /stylesheets/print.css for media "print" And I am told how to conditionally link "IE" to /stylesheets/ie.css for media "screen, projection" + Scenario: Creating a bare project + When I run: compass create bare_project --bare + Then a directory bare_project/ is created + And a configuration file bare_project/config.rb is created + And a directory custom_project/src/ is created + And a directory custom_project/stylesheets/ is not created + And I am congratulated + And I am told where to place stylesheets + And how to compile them + + Scenario: Creating a bare project with a framework + When I run: compass create bare_project --using blueprint --bare + Then an error message is printed out: A bare project cannot be created when a framework is specified. + And the command exits with a non-zero error code diff --git a/features/step_definitions/command_line_steps.rb b/features/step_definitions/command_line_steps.rb index 2d784a10..765be60e 100644 --- a/features/step_definitions/command_line_steps.rb +++ b/features/step_definitions/command_line_steps.rb @@ -51,3 +51,25 @@ end Then /I am told how to conditionally link "([^"]+)" to ([^ ]+) for media "([^"]+)"/ do |condition, stylesheet, media| @last_result.should =~ %r{}mi end + +Then /^an error message is printed out: (.+)$/ do |error_message| + @last_error.should =~ Regexp.new(Regexp.escape(error_message)) +end + +Then /^the command exits with a non\-zero error code$/ do + @last_exit_code.should_not == 0 +end + + +Then /^I am congratulated$/ do + pending +end + +Then /^I am told where to place stylesheets$/ do + pending +end + +Then /^how to compile them$/ do + pending +end + diff --git a/lib/compass/app_integration/rails/installer.rb b/lib/compass/app_integration/rails/installer.rb index 3023c33f..863ad3ff 100644 --- a/lib/compass/app_integration/rails/installer.rb +++ b/lib/compass/app_integration/rails/installer.rb @@ -2,11 +2,13 @@ module Compass module Installers class Base end + class ManifestInstaller < Base + end end module AppIntegration module Rails - class Installer < Compass::Installers::Base + class Installer < Compass::Installers::ManifestInstaller def default_configuration Compass::Configuration::Data.new.extend(ConfigurationDefaults) diff --git a/lib/compass/app_integration/stand_alone/installer.rb b/lib/compass/app_integration/stand_alone/installer.rb index 4480cc46..cebcb51c 100644 --- a/lib/compass/app_integration/stand_alone/installer.rb +++ b/lib/compass/app_integration/stand_alone/installer.rb @@ -2,11 +2,13 @@ module Compass module Installers class Base end + class ManifestInstaller < Base + end end module AppIntegration module StandAlone - class Installer < Compass::Installers::Base + class Installer < Compass::Installers::ManifestInstaller def init directory targetize("") diff --git a/lib/compass/commands/create_project.rb b/lib/compass/commands/create_project.rb index 57cd8a47..b1f14133 100644 --- a/lib/compass/commands/create_project.rb +++ b/lib/compass/commands/create_project.rb @@ -15,6 +15,10 @@ module Compass Options: }.split("\n").map{|l| l.gsub(/^ */,'')}.join("\n") + + opts.on_tail("--bare", "Don't generate any Sass or CSS files.") do + self.options[:bare] = true + end else opts.banner = %Q{ Usage: compass init project_type path/to/project [options] @@ -68,6 +72,9 @@ module Compass parser = option_parser(arguments) parse_options!(parser, arguments) parse_arguments!(parser, arguments) + if parser.options[:framework] && parser.options[:bare] + raise Compass::Error, "A bare project cannot be created when a framework is specified." + end set_default_arguments(parser) parser.options end diff --git a/lib/compass/commands/installer_command.rb b/lib/compass/commands/installer_command.rb index 6069f593..982294a3 100644 --- a/lib/compass/commands/installer_command.rb +++ b/lib/compass/commands/installer_command.rb @@ -16,8 +16,12 @@ module Compass end def installer - project_type = options[:project_type] || Compass.configuration.project_type - installer_class = "Compass::AppIntegration::#{camelize(project_type)}::Installer" + installer_class = if options[:bare] + "Compass::Installers::BareInstaller" + else + project_type = options[:project_type] || Compass.configuration.project_type + "Compass::AppIntegration::#{camelize(project_type)}::Installer" + end @installer = eval("#{installer_class}.new *installer_args") end diff --git a/lib/compass/exec.rb b/lib/compass/exec.rb index ee489695..2547d376 100644 --- a/lib/compass/exec.rb +++ b/lib/compass/exec.rb @@ -3,6 +3,7 @@ require 'optparse' require 'compass/logger' require 'compass/errors' require 'compass/actions' +require 'compass/installers' require 'compass/commands' module Compass::Exec diff --git a/lib/compass/installers.rb b/lib/compass/installers.rb index 84598af7..70b87cc8 100644 --- a/lib/compass/installers.rb +++ b/lib/compass/installers.rb @@ -1,3 +1,3 @@ -%w(manifest template_context base).each do |f| +%w(manifest template_context base manifest_installer bare_installer).each do |f| require "compass/installers/#{f}" end diff --git a/lib/compass/installers/bare_installer.rb b/lib/compass/installers/bare_installer.rb new file mode 100644 index 00000000..6c04eff1 --- /dev/null +++ b/lib/compass/installers/bare_installer.rb @@ -0,0 +1,13 @@ +module Compass + module Installers + + class BareInstaller < Base + def prepare + + end + def install + # directory + end + end + end +end diff --git a/lib/compass/installers/base.rb b/lib/compass/installers/base.rb index 2261fdd5..fd72b3f1 100644 --- a/lib/compass/installers/base.rb +++ b/lib/compass/installers/base.rb @@ -7,21 +7,15 @@ module Compass attr_accessor :template_path, :target_path, :working_path attr_accessor :options - attr_accessor :manifest def initialize(template_path, target_path, options = {}) @template_path = template_path @target_path = target_path @working_path = Dir.getwd @options = options - @manifest = Manifest.new(manifest_file, options) if template_path self.logger = options[:logger] end - def manifest_file - @manifest_file ||= File.join(template_path, "manifest.rb") - end - [:css_dir, :sass_dir, :images_dir, :javascripts_dir, :http_stylesheets_path].each do |dir| define_method dir do Compass.configuration.send(dir) @@ -31,23 +25,6 @@ module Compass end end - # 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 - - if manifest.has_stylesheet? - dirs << sass_dir - dirs << css_dir - end - - dirs.uniq.sort.each do |dir| - directory targetize(dir) - end - end - # Runs the installer. # Every installer must conform to the installation strategy of prepare, install, and then finalize. # A default implementation is provided for each step. @@ -62,20 +39,9 @@ module Compass def prepare end - def configure_option_with_default(opt) - value = options[opt] - value ||= begin - default_method = "default_#{opt}".to_sym - send(default_method) if respond_to?(default_method) - end - send("#{opt}=", value) - end - - # The default install method. Calls install_ methods in the order specified by the manifest. + # The install method override this to install def install - manifest.each do |entry| - send("install_#{entry.type}", entry.from, entry.to, entry.options) - end + raise "Not Yet Implemented" end # The default finalize method -- it is a no-op. @@ -165,22 +131,12 @@ module Compass strip_trailing_separator File.join(template_path, separate(path)) end + # Emits an HTML fragment that can be used to link to the compiled css files def stylesheet_links - html = "\n" - manifest.each_stylesheet do |stylesheet| - # Skip partials. - next if File.basename(stylesheet.from)[0..0] == "_" - media = if stylesheet.options[:media] - %Q{ media="#{stylesheet.options[:media]}"} - end - ss_line = %Q{ } - if stylesheet.options[:condition] - ss_line = " " - end - html << ss_line + "\n" - end - html << "" + "" end end end end +require 'compass/installers/bare_installer' +require 'compass/installers/manifest_installer' diff --git a/lib/compass/installers/manifest_installer.rb b/lib/compass/installers/manifest_installer.rb new file mode 100644 index 00000000..d48ff5ad --- /dev/null +++ b/lib/compass/installers/manifest_installer.rb @@ -0,0 +1,59 @@ +module Compass + module Installers + + class ManifestInstaller < Base + + attr_accessor :manifest + + def initialize(template_path, target_path, options = {}) + super + @manifest = Manifest.new(manifest_file, options) if template_path + end + + def manifest_file + @manifest_file ||= File.join(template_path, "manifest.rb") + end + + # 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 + + if manifest.has_stylesheet? + dirs << sass_dir + dirs << css_dir + end + + dirs.uniq.sort.each do |dir| + directory targetize(dir) + end + end + + # The default install method. Calls install_ methods in the order specified by the manifest. + def install + manifest.each do |entry| + send("install_#{entry.type}", entry.from, entry.to, entry.options) + end + end + + def stylesheet_links + html = "\n" + manifest.each_stylesheet do |stylesheet| + # Skip partials. + next if File.basename(stylesheet.from)[0..0] == "_" + media = if stylesheet.options[:media] + %Q{ media="#{stylesheet.options[:media]}"} + end + ss_line = %Q{ } + if stylesheet.options[:condition] + ss_line = " " + end + html << ss_line + "\n" + end + html << "" + end + end + end +end diff --git a/test/command_line_helper.rb b/test/command_line_helper.rb index 89d5b986..9db130ed 100644 --- a/test/command_line_helper.rb +++ b/test/command_line_helper.rb @@ -35,8 +35,10 @@ module Compass::CommandLineHelper end end else - @last_result = capture_output do - execute *arguments + @last_error = capture_warning do + @last_result = capture_output do + @last_exit_code = execute *arguments + end end end rescue Timeout::Error