class Rote::Filters::Sass

Post filter that runs Sass on the laid-out page to compile CSS from either SCSS (the default) or SASS syntax.

Note that this filter requires the ‘sass’ command, and should be added to the post_filters array, in contrast to most of the other filters which are page filters.

If ‘sass’ isn’t in your path you’ll need to specify it here or via a SASSCMD environment variable.

Attributes

format[RW]
sasscmd[RW]
sassopts[RW]

Public Class Methods

new(format = :scss, sasscmd = ENV['SASSCMD'], sassopts = '') click to toggle source

Create a new filter instance, using the specified output format, and optionally a custom ‘tidy’ command and options.

# File lib/rote/filters/sass.rb, line 26
def initialize(format = :scss, sasscmd = ENV['SASSCMD'], sassopts = '') 
  @sasscmd = sasscmd || (RUBY_PLATFORM =~ /mswin/ ? 'sass.bat' : 'sass')
    # TODO windows 'sass.bat' correct?
    
  @sassopts = sassopts
  @format = format
end

Public Instance Methods

filter(text, page) click to toggle source
# File lib/rote/filters/sass.rb, line 36
def filter(text, page)
  # TODO need to properly capture and log warnings here
  result = IO.popen("#{@sasscmd} #{self.sassopts} #{'--scss' if @format.eql? :scss} --stdin","r+") do |fp|
     Thread.new { fp.write(text); fp.close_write }
     fp.read
  end
  
  if $?.exitstatus < 2
    result
  else
    warn 'sass command failed (exitstatus: $?)'
    text
  end
end