Sha256: 4fe3a938da7c50411150edb764e4c69fd9c55e6556fadcb1caeac1beb9397509

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require "sass"

module Capcode
  module Helpers
    @@__SASS_PATH__ = "."
    
    # Set the path to Sass files. If this path is not set, Capcode will search in the static path.
    def self.sass_path=( p ) #:nodoc:
      @@__SASS_PATH__ = p
    end
    
    def render_sass( f, _ ) #:nodoc:
      if @@__SASS_PATH__.nil?
        @@__SASS_PATH__ = "." + (Capcode.static.nil? == false)?Capcode.static():''
      end
      
      f = f.to_s
      if f.include? '..'
        return [403, {}, '403 - Invalid path']
      end
      
      if /Windows/.match( ENV['OS'] )
        unless( /.:\\/.match( @@__SASS_PATH__[0] ) )
          @@__SASS_PATH__ = File.expand_path( File.join(".", @@__SASS_PATH__) )
        end
      else
        unless( @@__SASS_PATH__[0].chr == "/" )
          @@__SASS_PATH__ = File.expand_path( File.join(".", @@__SASS_PATH__) )
        end
      end
       
      f = f + ".sass" if File.extname( f ) != ".sass"
      file = File.join( @@__SASS_PATH__, f )

      Sass::Engine.new( open( file ).read ).to_css
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
Capcode-0.8.6 lib/capcode/render/sass.rb
Capcode-0.8.5 lib/capcode/render/sass.rb
Capcode-0.8.4 lib/capcode/render/sass.rb