Class: Middleman::Renderers::Sass::SassPlusCSSFilenameTemplate

Inherits:
Tilt::SassTemplate
  • Object
show all
Defined in:
lib/middleman-core/renderers/sass.rb

Overview

A SassTemplate for Tilt which outputs debug messages

Direct Known Subclasses

ScssPlusCSSFilenameTemplate

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ SassPlusCSSFilenameTemplate

Returns a new instance of SassPlusCSSFilenameTemplate.



39
40
41
42
43
# File 'lib/middleman-core/renderers/sass.rb', line 39

def initialize(*args, &block)
  super

  @context = @options[:context] if @options.key?(:context)
end

Instance Method Details

#evaluate(context, _) ⇒ String

Add exception messaging

Parameters:

  • context (Class)

Returns:

  • (String)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/middleman-core/renderers/sass.rb', line 56

def evaluate(context, _)
  @context ||= context

  sass_module = if defined?(::SassC)
    ::SassC
  else
    ::Sass
  end

  @engine = sass_module::Engine.new(data, sass_options)

  begin
    @engine.render
  rescue sass_module::SyntaxError => e
    ::Sass::SyntaxError.exception_to_css(e)
  end
end

#prepareObject



51
# File 'lib/middleman-core/renderers/sass.rb', line 51

def prepare; end

#sass_optionsHash

Change Sass path, for url functions, to the build folder if we're building

Returns:

  • (Hash)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/middleman-core/renderers/sass.rb', line 76

def sass_options
  ctx = @context

  more_opts = {
    load_paths: ::Sass.load_paths | ctx.app.config[:sass_assets_paths],
    filename: eval_file,
    line: line,
    syntax: syntax,
    custom: {}.merge!(options[:custom] || {}).merge!(
      middleman_context: ctx.app,
      current_resource: ctx.current_resource
    )
  }

  if ctx.app.config[:sass_source_maps] || (ctx.app.config[:sass_source_maps].nil? && ctx.app.development?)
    more_opts[:source_map_file] = '.'
    more_opts[:source_map_embed] = true
    more_opts[:source_map_contents] = true
  end

  if ctx.is_a?(::Middleman::TemplateContext) && file
    more_opts[:css_filename] = file.sub(/\.s[ac]ss$/, '')
  end

  {}.merge!(options).merge!(more_opts)
end

#syntaxSymbol

Define the expected syntax for the template

Returns:

  • (Symbol)


47
48
49
# File 'lib/middleman-core/renderers/sass.rb', line 47

def syntax
  :sass
end