Sha256: efd06ab295ebc582ce65aef3b011205b5dc2fb92cdae0d7d52ba2ebdd9ea620f

Contents?: true

Size: 1.94 KB

Versions: 4

Compression:

Stored size: 1.94 KB

Contents

require 'rubygems'
require 'sass'
require 'fileutils'
require 'pathname'
require File.join(File.dirname(__FILE__), 'base')

module Compass
  module Commands
    class ProjectBase < Base
      attr_accessor :project_directory, :project_name, :options

      def initialize(working_path, options = {})
        super(working_path, options)
        self.project_name = determine_project_name(working_path, options)
        Compass.configuration.project_path = determine_project_directory(working_path, options)
      end

      protected

      def projectize(path)
        File.join(project_directory, separate(path))
      end

      def project_directory
        Compass.configuration.project_path
      end

      def project_css_subdirectory
        Compass.configuration.css_dir
      end

      def project_src_subdirectory
        Compass.configuration.sass_dir
      end

      # Read the configuration file for this project
      def read_project_configuration
        if File.exists?(projectize('config.rb'))
          Compass.configuration.parse(projectize('config.rb'))
        elsif File.exists?(projectize('src/config.rb'))
          Compass.configuration.parse(projectize('src/config.rb'))
        end
      end

      private

      def determine_project_name(working_path, options)
        if options[:project_name]
          File.basename(strip_trailing_separator(options[:project_name]))
        else
          File.basename(working_path)
        end
      end

      def determine_project_directory(working_path, options)
        if options[:project_name]
          if absolute_path?(options[:project_name])
            options[:project_name]
          else
            File.join(working_path, options[:project_name])
          end
        else
          working_path
        end
      end

      def absolute_path?(path)
        # This is only going to work on unix, gonna need a better implementation.
        path.index(File::SEPARATOR) == 0
      end

    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
chriseppstein-compass-0.4.0 lib/compass/commands/project_base.rb
chriseppstein-compass-0.4.1 lib/compass/commands/project_base.rb
chriseppstein-compass-0.4.2 lib/compass/commands/project_base.rb
jsmestad-compass-0.4.2.1 lib/compass/commands/project_base.rb