Class: Compass::Commands::UpdateProject

Inherits:
Base
  • Object
show all
Defined in:
lib/compass/commands/update_project.rb

Direct Known Subclasses

WatchProject

Instance Attribute Summary collapse

Attributes inherited from Base

#working_directory

Instance Method Summary collapse

Constructor Details

#initialize(working_directory, options = {}) ⇒ UpdateProject

Returns a new instance of UpdateProject.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/compass/commands/update_project.rb', line 16

def initialize(working_directory, options = {})
  super(working_directory, options)
  if options[:project_name]
    options[:project_name] = options[:project_name][0..-2] if options[:project_name][-1..-1] == File::SEPARATOR
    self.project_name = File.basename(options[:project_name])
    if options[:project_name][0] == File::SEPARATOR
      self.project_directory = options[:project_name]
    elsif File.directory?(File.join(working_directory, options[:project_name]))
      self.project_directory = File.expand_path(File.join(working_directory, options[:project_name]))
    else
      if File.exists?(options[:project_name]) or File.exists?(File.join(working_directory, options[:project_name]))
        raise ::Compass::Exec::ExecError.new("#{options[:project_name]} is not a directory.")
      elsif !(options[:force] || options[:dry_run])
        raise ::Compass::Exec::ExecError.new("#{options[:project_name]} does not exist.")
      end
    end
  else
    self.project_name = File.basename(working_directory)
    self.project_directory = working_directory          
  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



14
15
16
# File 'lib/compass/commands/update_project.rb', line 14

def options
  @options
end

#project_css_subdirectoryObject

The subdirectory where the css output is kept.



90
91
92
# File 'lib/compass/commands/update_project.rb', line 90

def project_css_subdirectory
  @project_css_subdirectory
end

#project_directoryObject

Returns the value of attribute project_directory.



14
15
16
# File 'lib/compass/commands/update_project.rb', line 14

def project_directory
  @project_directory
end

#project_nameObject

Returns the value of attribute project_name.



14
15
16
# File 'lib/compass/commands/update_project.rb', line 14

def project_name
  @project_name
end

#project_src_subdirectoryObject

The subdirectory where the sass source is kept.



85
86
87
# File 'lib/compass/commands/update_project.rb', line 85

def project_src_subdirectory
  @project_src_subdirectory
end

Instance Method Details

#compile(sass_filename, css_filename, options) ⇒ Object

Compile one Sass file



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/compass/commands/update_project.rb', line 46

def compile(sass_filename, css_filename, options)
  sass_filename = projectize(sass_filename)
  css_filename = projectize(css_filename)
  if !File.directory?(File.dirname(css_filename))
    directory basename(File.dirname(css_filename)), options.merge(:force => true) unless options[:dry_run]
  end
  print_action :compile, basename(sass_filename)
  if File.exists?(css_filename)
    print_action :overwrite, basename(css_filename)
  else
    print_action :create, basename(css_filename)
  end
  unless options[:dry_run]
    engine = ::Sass::Engine.new(open(sass_filename).read,
                                :filename => sass_filename,
                                :line_comments => options[:environment] == :development,
                                :style => output_style,
                                :css_filename => css_filename,
                                :load_paths => sass_load_paths)
    output = open(css_filename,'w')
    output.write(engine.render)
    output.close
  end
end

#output_styleObject



71
72
73
74
75
76
77
# File 'lib/compass/commands/update_project.rb', line 71

def output_style
  @output_style ||= options[:style] || if options[:environment] == :development
    :expanded
  else
    :compact
  end
end

#performObject



38
39
40
41
42
43
# File 'lib/compass/commands/update_project.rb', line 38

def perform
  Dir.glob(separate("#{project_src_directory}/**/[^_]*.sass")).each do |sass_file|
    stylesheet_name = sass_file[("#{project_src_directory}/".length)..-6]
    compile "#{project_src_subdirectory}/#{stylesheet_name}.sass", "#{project_css_subdirectory}/#{stylesheet_name}.css", options
  end
end

#project_src_directoryObject

The directory where the project source files are located.



95
96
97
# File 'lib/compass/commands/update_project.rb', line 95

def project_src_directory
  @project_src_directory ||= separate("#{project_directory}/#{project_src_subdirectory}")
end

#sass_load_pathsObject

where to load sass files from



80
81
82
# File 'lib/compass/commands/update_project.rb', line 80

def sass_load_paths
  @sass_load_paths ||= [project_src_directory] + Compass::Frameworks::ALL.map{|f| f.stylesheets_directory}
end