Class: Compass::Magick::Command

Inherits:
Object
  • Object
show all
Includes:
Scriptable, Utils
Defined in:
lib/magick/command.rb

Overview

A class that executes a block on a Canvas object.

When a function is called in a Sass document, it delays its execution until placed within a canvas. To do so, it must store state and return a valid Sass node.

Examples:


Command.new do |canvas|
  canvas.rect(0, 0, canvas.width - 1, canvas.height - 1, ChunkyPNG::Color::BLACK)
end

Direct Known Subclasses

Effect

Instance Attribute Summary collapse

Attributes included from Scriptable

#context, #options

Instance Method Summary collapse

Methods included from Utils

#assert_one_of, #assert_type, #to_canvas, #to_chunky_color, #value_of

Constructor Details

#initialize(&block) ⇒ Command

Initializes a new Command instance.

Parameters:

  • block (Proc)

    The block to execute.



20
21
22
# File 'lib/magick/command.rb', line 20

def initialize(&block)
  @block = block
end

Instance Attribute Details

#blockProc (readonly)

Returns The block to execute.

Returns:

  • (Proc)

    The block to execute.



25
26
27
# File 'lib/magick/command.rb', line 25

def block
  @block
end

Instance Method Details

#to_s(options = {}) ⇒ Object

Raises an error if the command is used outside of a Compass::Magick::Canvas object.

Raises:



28
29
30
# File 'lib/magick/command.rb', line 28

def to_s(options = {})
  raise NotAllowed.new("#{self.class} cannot be used outside of a Compass::Magick::Canvas object")
end