File: project_base.rb

package info (click to toggle)
ruby-compass 0.12.2~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 8,308 kB
  • sloc: ruby: 10,474; makefile: 42; xml: 14
file content (97 lines) | stat: -rw-r--r-- 2,621 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'fileutils'
require 'pathname'
require 'compass/commands/base'
require 'compass/commands/installer_command'

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.add_configuration({:project_path => determine_project_directory(working_path, options)}, "implied")
        configure!
      end

      def execute
        super
      end

      protected

      def configure!
        add_project_configuration
        Compass.add_configuration(options, "command_line")
        Compass.discover_extensions! unless skip_extension_discovery?
      end

      def add_project_configuration
        Compass.add_project_configuration(options[:configuration_file], :defaults => Compass.configuration_for(options, "cli_defaults")) do
          options[:project_type]
        end
      end

      def projectize(path)
        Compass.projectize(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

      def project_images_subdirectory
        Compass.configuration.images_dir
      end

      def assert_project_directory_exists!
        if File.exists?(project_directory) && !File.directory?(project_directory)
          raise Compass::FilesystemConflict.new("#{project_directory} is not a directory.")
        elsif !File.directory?(project_directory)
          raise Compass::Error.new("#{project_directory} does not exist.")
        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)
        # Pretty basic implementation
        path.index(File::SEPARATOR) == 0 || path.index(':') == 1
      end

      def skip_extension_discovery?
        false
      end

    end
  end
end