Class: Stylish::Image

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

Overview

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

Instance Attribute Summary collapse

Attributes included from Formattable

#format

Instance Method Summary collapse

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.



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

def initialize(path)
  accept_format(/^url\(\s*('|")?%s\1\s*\)$/, "url('%s')")
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/stylish/image.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/image.rb', line 27

def to_s
  sprintf(@format, path.to_s)
end