Class: Plate::LessTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/plate/less_template.rb

Overview

Slightly modified from the Tilt default to just use the Less::Parse instead of Engine.

Also adds support for paths

Original source: github.com/rtomayko/tilt/blob/master/lib/tilt/css.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.engine_initialized?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/plate/less_template.rb', line 10

def self.engine_initialized?
  defined? ::Less
end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/plate/less_template.rb', line 21

def evaluate(scope, locals, &block)
  paths = [ scope.pathname, File.join(scope.site.source, 'content') ]

  less_options = options.merge({
    :filename => eval_file,
    :line => line,
    :paths => paths
  })

  partials = data.to_s.scan(/@import\s"(.*?)";/i).flatten.collect { |s| s.split('/').last.gsub(/^_/, '') }
  scope.partials = scope.partials + partials

  parser = ::Less::Parser.new(less_options)
  parser.parse(data).to_css
end

#initialize_engineObject



14
15
16
# File 'lib/plate/less_template.rb', line 14

def initialize_engine
  require_template_library 'less'
end

#prepareObject



18
19
# File 'lib/plate/less_template.rb', line 18

def prepare
end