Sha256: 6404a60ec8606d9ab5a24ddb79da885b6126c3c8abea50db4577ce70692c436c

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module SassC
  class Engine
    class NotRenderedError < StandardError; end

    def initialize(template, options = {})
      @template = template
      @options = options
    end

    def render
      data_context = Native.make_data_context(@template)
      context = Native.data_context_get_context(data_context)
      native_options = Native.context_get_options(context)

      Native.option_set_is_indented_syntax_src(native_options, true) if sass?
      Native.option_set_input_path(native_options, filename) if filename
      Native.option_set_include_path(native_options, load_paths)

      importer.setup(native_options) if importer

      status = Script.setup_custom_functions(native_options, @options) do
        Native.compile_data_context(data_context)
      end

      css = Native.context_get_output_string(context)

      if status != 0
        message = SassC::Native.context_get_error_message(context)
        raise SyntaxError.new(message)
      end

      @dependencies = Native.context_get_included_files(context)

      Native.delete_data_context(data_context)

      return css unless quiet?
    end

    def dependencies
      raise NotRenderedError unless @dependencies
      Dependency.from_filenames(@dependencies)
    end

    private

    def quiet?
      @options[:quiet]
    end

    def filename
      @options[:filename]
    end

    def sass?
      @options[:syntax] && @options[:syntax].to_sym == :sass
    end

    def importer
      @importer ||= begin
        if @options[:importer]
          @options[:importer].new(@options)
        else
          nil
        end
      end
    end

    def load_paths
      paths = @options[:load_paths]
      paths.join(":") if paths
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sassc-0.0.10 lib/sassc/engine.rb
sassc-0.0.9 lib/sassc/engine.rb