Class: SemiStatic::Stylesheet

Inherits:
Base
  • Object
show all
Defined in:
lib/semi-static/stylesheet.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#full_source_path, #site, #source_content, #source_ext, #source_metadata, #source_path

Instance Method Summary collapse

Methods inherited from Base

#source_mtime

Constructor Details

#initialize(site, name, options = {}) ⇒ Stylesheet

Returns a new instance of Stylesheet.



5
6
7
8
9
10
11
12
13
# File 'lib/semi-static/stylesheet.rb', line 5

def initialize(site, name, options={})
    path = "#{name}.sass"
    path = "#{name}.css" unless File.file?(path)
    super(site, path)
    
    @name, @options = name, options
    @output_dir = 'css'
    @output_path = "#{output_dir}/#{name}.css"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SemiStatic::Base

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/semi-static/stylesheet.rb', line 3

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/semi-static/stylesheet.rb', line 3

def options
  @options
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



3
4
5
# File 'lib/semi-static/stylesheet.rb', line 3

def output_dir
  @output_dir
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



3
4
5
# File 'lib/semi-static/stylesheet.rb', line 3

def output_path
  @output_path
end

Instance Method Details

#loadObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/semi-static/stylesheet.rb', line 15

def load
    super
    Dir.chdir(File.dirname(full_source_path)) do
        @content = case source_ext
        when '.sass'
            Sass::Engine.new(source_content, :filename => source_path).render
        when '.css'
            source_content
        else
            raise ArgumentError, "Unsupported format: #{self.source_path}"
        end
    end
end

#renderObject



29
30
31
# File 'lib/semi-static/stylesheet.rb', line 29

def render
    @content
end