Class: Stylish::Image

Inherits:
Object
  • Object
show all
Includes:
Formattable
Defined in:
lib/stylish/extended.rb

Overview

Instances of the Image class are used to represent paths to images, generally background images.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Formattable

included

Constructor Details

#initialize(path) ⇒ Image

Image instances are serialised to URI values. The path to the image file can be surrounded by either single quotes, double quotes or neither; single quotes are the default in Stylish.



14
15
16
# File 'lib/stylish/extended.rb', line 14

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/stylish/extended.rb', line 8

def path
  @path
end

Instance Method Details

#to_sObject

Serialising Image objects to a string produces the URI values seen in background-image declarations, e.g.

image = Image.new("test.png")
image.to_s # => "url('test.png')"

background = Stylish::Background.new(:image => "test.png")
background.to_s # => "background-image:url('test.png');"


27
28
29
# File 'lib/stylish/extended.rb', line 27

def to_s
  sprintf(self.class.format, path.to_s)
end