Class: Mint::Style

Inherits:
Resource show all
Defined in:
lib/mint/style.rb

Instance Attribute Summary

Attributes inherited from Resource

#destination, #name, #root, #source, #type

Instance Method Summary collapse

Methods inherited from Resource

#destination_directory, #destination_directory_path, #destination_file, #destination_file_path, #equal?, #renderer=, #root_directory, #root_directory_path, #source_directory, #source_directory_path, #source_file, #source_file_path

Constructor Details

#initialize(source, opts = Mint.default_options) ⇒ Style

Creates a new Layout object using a mandatory source file and optional configuration options.


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mint/style.rb', line 10

def initialize(source, opts=Mint.default_options)
  super(source, opts)
  self.type = :style

  # We want to render final stylesheet to the /css subdirectory if
  # an output directory is not specified and we are dealing with
  # a named template (not a local file). If we don't do this, the rendered
  # CSS file might be picked up next time we look for a named template
  # in this directory, and the (correct) SASS file won't be picked up.
  # However, if a destination directory is already specified, we
  # leave it alone.
  if Mint.template?(self.source_directory) and rendered?
    self.destination ||= "css" 
  end
end

Instance Method Details

#renderString

Renders a Style object if necessary. Otherwise, returns the contents of its source file.


37
38
39
40
41
42
43
# File 'lib/mint/style.rb', line 37

def render
  if rendered?
    super
  else
    File.read source
  end
end

#rendered?Boolean

Determines whether a Style object is supposed to be rendered.


29
30
31
# File 'lib/mint/style.rb', line 29

def rendered?
  source_file_path.extname !~ /\.css$/
end