Class: Compass::Commands::UpdateProject
- Defined in:
- lib/compass/commands/update_project.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#project_css_subdirectory ⇒ Object
The subdirectory where the css output is kept.
-
#project_directory ⇒ Object
Returns the value of attribute project_directory.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#project_src_subdirectory ⇒ Object
The subdirectory where the sass source is kept.
Attributes inherited from Base
Instance Method Summary collapse
-
#compile(sass_filename, css_filename, options) ⇒ Object
Compile one Sass file.
-
#initialize(working_directory, options = {}) ⇒ UpdateProject
constructor
A new instance of UpdateProject.
- #output_style ⇒ Object
- #perform ⇒ Object
-
#project_src_directory ⇒ Object
The directory where the project source files are located.
-
#sass_load_paths ⇒ Object
where to load sass files from.
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, = {}) super(working_directory, ) if [:project_name] [:project_name] = [:project_name][0..-2] if [:project_name][-1..-1] == File::SEPARATOR self.project_name = File.basename([:project_name]) if [:project_name][0] == File::SEPARATOR self.project_directory = [:project_name] elsif File.directory?(File.join(working_directory, [:project_name])) self.project_directory = File.(File.join(working_directory, [:project_name])) else if File.exists?([:project_name]) or File.exists?(File.join(working_directory, [:project_name])) raise ::Compass::Exec::ExecError.new("#{[:project_name]} is not a directory.") elsif !([:force] || [:dry_run]) raise ::Compass::Exec::ExecError.new("#{[: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
#options ⇒ Object
Returns the value of attribute options.
14 15 16 |
# File 'lib/compass/commands/update_project.rb', line 14 def @options end |
#project_css_subdirectory ⇒ Object
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_directory ⇒ Object
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_name ⇒ Object
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_subdirectory ⇒ Object
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, ) sass_filename = projectize(sass_filename) css_filename = projectize(css_filename) if !File.directory?(File.dirname(css_filename)) directory basename(File.dirname(css_filename)), .merge(:force => true) unless [: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 [:dry_run] engine = ::Sass::Engine.new(open(sass_filename).read, :filename => sass_filename, :line_comments => [: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_style ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/compass/commands/update_project.rb', line 71 def output_style @output_style ||= [:style] || if [:environment] == :development :expanded else :compact end end |
#perform ⇒ Object
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", end end |
#project_src_directory ⇒ Object
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_paths ⇒ Object
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 |