[Command Line] Ability to create a bare project with no stylesheets provided.

This commit is contained in:
Chris Eppstein 2009-10-22 09:46:46 -07:00
parent 563c4cf43e
commit 853e97f2e4
12 changed files with 139 additions and 57 deletions

View File

@ -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

View File

@ -51,3 +51,25 @@ end
Then /I am told how to conditionally link "([^"]+)" to ([^ ]+) for media "([^"]+)"/ do |condition, stylesheet, media|
@last_result.should =~ %r{<!--\[if #{condition}\]>\s+<link href="#{stylesheet}" media="#{media}" rel="stylesheet" type="text/css" />\s+<!\[endif\]-->}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

View File

@ -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)

View File

@ -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("")

View File

@ -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

View File

@ -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

View File

@ -3,6 +3,7 @@ require 'optparse'
require 'compass/logger'
require 'compass/errors'
require 'compass/actions'
require 'compass/installers'
require 'compass/commands'
module Compass::Exec

View File

@ -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

View File

@ -0,0 +1,13 @@
module Compass
module Installers
class BareInstaller < Base
def prepare
end
def install
# directory
end
end
end
end

View File

@ -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_<type> 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 = "<head>\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{ <link href="#{http_stylesheets_path}/#{stylesheet.to.sub(/\.sass$/,'.css')}"#{media} rel="stylesheet" type="text/css" />}
if stylesheet.options[:condition]
ss_line = " <!--[if #{stylesheet.options[:condition]}]>\n #{ss_line}\n <![endif]-->"
end
html << ss_line + "\n"
end
html << "</head>"
""
end
end
end
end
require 'compass/installers/bare_installer'
require 'compass/installers/manifest_installer'

View File

@ -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_<type> 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 = "<head>\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{ <link href="#{http_stylesheets_path}/#{stylesheet.to.sub(/\.sass$/,'.css')}"#{media} rel="stylesheet" type="text/css" />}
if stylesheet.options[:condition]
ss_line = " <!--[if #{stylesheet.options[:condition]}]>\n #{ss_line}\n <![endif]-->"
end
html << ss_line + "\n"
end
html << "</head>"
end
end
end
end

View File

@ -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