Sha256: b8b8aa4d01b5c03bbd144b692002a4e06b520d6524cf96c9724d3c41c6e8d3ac
Contents?: true
Size: 1.11 KB
Versions: 13
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module Nanoc::Filters # @api private class Haml < Nanoc::Filter identifier :haml requires 'haml' # Runs the content through [Haml](http://haml-lang.com/). # Parameters passed to this filter will be passed on to Haml. # # @param [String] content The content to filter # # @return [String] The filtered content def run(content, params = {}) # Get options options = params.merge(filename: filename) # Create context context = ::Nanoc::Core::Context.new(assigns) # Get result proc = assigns[:content] ? -> { assigns[:content] } : nil # Render haml_major_version = ::Haml::VERSION[0] case haml_major_version when '5' ::Haml::Engine.new(content, options).render(context, assigns, &proc) when '6' template = Tilt::HamlTemplate.new(options) { content } template.render(context, assigns, &proc) else raise Nanoc::Core::TrivialError.new( "Cannot run Haml filter: unsupported Haml major version: #{haml_major_version}", ) end end end end
Version data entries
13 entries across 13 versions & 1 rubygems