Class: Middleman::Renderers::Sass::SassPlusCSSFilenameTemplate
- Inherits:
-
Tilt::SassTemplate
- Object
- Tilt::SassTemplate
- Middleman::Renderers::Sass::SassPlusCSSFilenameTemplate
- Defined in:
- lib/middleman-core/renderers/sass.rb
Overview
A SassTemplate for Tilt which outputs debug messages
Direct Known Subclasses
Instance Method Summary collapse
-
#evaluate(context, _) ⇒ String
Add exception messaging.
- #exception_to_css(e) ⇒ Object
-
#initialize(*args, &block) ⇒ SassPlusCSSFilenameTemplate
constructor
A new instance of SassPlusCSSFilenameTemplate.
- #prepare ⇒ Object
-
#sass_options ⇒ Hash
Change Sass path, for url functions, to the build folder if we're building.
-
#syntax ⇒ Symbol
Define the expected syntax for the template.
Constructor Details
#initialize(*args, &block) ⇒ SassPlusCSSFilenameTemplate
Returns a new instance of SassPlusCSSFilenameTemplate.
32 33 34 35 36 |
# File 'lib/middleman-core/renderers/sass.rb', line 32 def initialize(*args, &block) super @context = @options[:context] if @options.key?(:context) end |
Instance Method Details
#evaluate(context, _) ⇒ String
Add exception messaging
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/middleman-core/renderers/sass.rb', line 49 def evaluate(context, _) @context ||= context @engine = ::SassC::Engine.new(data, ) begin @engine.render rescue ::SassC::SyntaxError => e raise e if @context.app.build? exception_to_css(e) end end |
#exception_to_css(e) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/middleman-core/renderers/sass.rb', line 63 def exception_to_css(e) header = "#{e.class}: #{e.}" <<~END /* #{header.gsub('*/', '*\\/')} Backtrace:\n#{e.backtrace.join("\n").gsub('*/', '*\\/')} */ body:before { white-space: pre; font-family: monospace; content: "#{header.gsub('"', '\"').gsub("\n", '\\A ')}"; } END end |
#prepare ⇒ Object
44 |
# File 'lib/middleman-core/renderers/sass.rb', line 44 def prepare; end |
#sass_options ⇒ Hash
Change Sass path, for url functions, to the build folder if we're building
81 82 83 84 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 110 111 112 |
# File 'lib/middleman-core/renderers/sass.rb', line 81 def ctx = @context preexisting_load_paths = begin ::Sass.load_paths rescue [] end more_opts = { load_paths: preexisting_load_paths + ctx.app.config[:sass_assets_paths], filename: eval_file, line: line, syntax: syntax, custom: {}.merge!([: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!().merge!(more_opts) end |
#syntax ⇒ Symbol
Define the expected syntax for the template
40 41 42 |
# File 'lib/middleman-core/renderers/sass.rb', line 40 def syntax :sass end |