Class: Compass::Commands::Sprite

Inherits:
ProjectBase show all
Defined in:
lib/compass/commands/sprite.rb

Instance Attribute Summary

Attributes inherited from ProjectBase

#options, #project_name

Attributes inherited from Base

#options, #working_path

Attributes included from Actions

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProjectBase

#execute

Methods inherited from Base

#execute, #failed!, register, #successful?

Methods included from Actions

#basename, #copy, #directory, #log_action, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_file

Constructor Details

#initialize(working_path, options) ⇒ Sprite

Returns a new instance of Sprite.



35
36
37
38
# File 'lib/compass/commands/sprite.rb', line 35

def initialize(working_path, options)
  super
  assert_project_directory_exists!
end

Class Method Details

.description(command) ⇒ Object



67
68
69
# File 'lib/compass/commands/sprite.rb', line 67

def description(command)
  "Generate an import for your sprites."
end

.option_parser(arguments) ⇒ Object



56
57
58
59
60
61
# File 'lib/compass/commands/sprite.rb', line 56

def option_parser(arguments)
  parser = Compass::Exec::CommandOptionParser.new(arguments)
  parser.extend(Compass::Exec::GlobalOptionsParser)
  parser.extend(Compass::Exec::ProjectOptionsParser)
  parser.extend(SpriteOptionsParser)
end

.parse!(arguments) ⇒ Object



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

def parse!(arguments)
  parser = option_parser(arguments)
  parser.parse!
  parse_arguments!(parser, arguments)
  parser.options
end

.parse_arguments!(parser, arguments) ⇒ Object



78
79
80
81
82
83
# File 'lib/compass/commands/sprite.rb', line 78

def parse_arguments!(parser, arguments)
  parser.options[:uri] = arguments.shift
  unless arguments.size == 0
    raise Compass::Error, "Please specify at least one image to sprite."
  end
end

.usageObject



63
64
65
# File 'lib/compass/commands/sprite.rb', line 63

def usage
  option_parser([]).to_s
end

Instance Method Details

#performObject



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/compass/commands/sprite.rb', line 40

def perform
  relative_uri = options[:uri].gsub(/^#{Compass.configuration.images_dir}\//, '')
  name = Compass::SpriteImporter.sprite_name(relative_uri)
  sprites = Compass::SpriteImporter.new
  options[:output_file] ||= File.join(Compass.configuration.sass_path, "sprites", "_#{name}.#{Compass.configuration.preferred_syntax}")
  options[:skip_overrides] ||= false
  contents = Compass::SpriteImporter.content_for_images(relative_uri, name, options[:skip_overrides])
  if options[:output_file][-4..-1] != "scss"
    contents = Sass::Engine.new(contents, Compass.sass_engine_options.merge(:syntax => :scss)).to_tree.to_sass
  end
  directory File.dirname(options[:output_file])
  write_file options[:output_file], contents
end