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

Inherits:
Tilt::SassTemplate
  • Object
show all
Defined in:
middleman-core/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



43
44
45
46
47
# File 'middleman-core/lib/middleman-core/renderers/sass.rb', line 43

def initialize(*args, &block)
  super

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

Instance Method Details

#dependenciesObject



78
79
80
81
# File 'middleman-core/lib/middleman-core/renderers/sass.rb', line 78

def dependencies
  files = @engine.dependencies.map(&:filename)
  files.empty? ? nil : Set.new(files)
end

#evaluate(context, _) ⇒ String

Add exception messaging



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'middleman-core/lib/middleman-core/renderers/sass.rb', line 60

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



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

def prepare; end

#sass_optionsHash

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



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'middleman-core/lib/middleman-core/renderers/sass.rb', line 85

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,
    cache_location: ctx.app.config[:sass_cache_location],
    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

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

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

#syntaxSymbol

Define the expected syntax for the template



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

def syntax
  :sass
end