Sha256: a7bd09ab167ea15afd8c07e6d3a19f3b0bd71fb7687f55c0abc7bb06935244b2

Contents?: true

Size: 897 Bytes

Versions: 2

Compression:

Stored size: 897 Bytes

Contents

require 'less'

class Assette::Reader::Less < Assette::Reader(:css)

  LESSC = !`which lessc`.empty?

  def compile args={}

    if LESSC
      Assette.logger.info("less running") {"cd #{@file.dirname} && lessc < #{@file.filename}"}
      `cd #{@file.dirname} && lessc #{@file.filename}`
    else
      parser = Less::Parser.new({
        :paths => [File.expand_path(@file.dirname)]|Assette.config.file_paths,
        :filename => @file.filename
      })

      tree = parser.parse(text)

      tree.to_css(options.merge(args))
    end
  end
  
private

  def options
    Assette.config.less
  end

  class << self
    def tag path
      tag = <<-HTML
        <link href="#{path}" rel="stylesheet/less" type="text/css"  media="all" />
      HTML

      tag << %Q{<script src="#{Assette.config.less_js_path}?nodep" type="text/javascript"></script>} if Assette.config.less_js_path
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
assette-0.1.5 lib/assette/readers/less.rb
assette-0.1.4 lib/assette/readers/less.rb