2012-05-28 22:19:40 +02:00
|
|
|
# Load gem
|
2013-12-28 01:26:31 +01:00
|
|
|
require 'slim'
|
2012-05-28 22:19:40 +02:00
|
|
|
|
2014-02-19 03:30:29 +01:00
|
|
|
module SafeTemplate
|
|
|
|
def render(*)
|
|
|
|
super.html_safe
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-17 01:47:42 +02:00
|
|
|
class ::Slim::Template
|
2014-02-19 03:30:29 +01:00
|
|
|
include SafeTemplate
|
|
|
|
|
2015-06-17 01:47:42 +02:00
|
|
|
def initialize(file, line, opts, &block)
|
|
|
|
if opts.key?(:context)
|
|
|
|
::Slim::Embedded::SassEngine.disable_option_validator!
|
|
|
|
%w(sass scss markdown).each do |engine|
|
2016-05-31 22:15:21 +02:00
|
|
|
(::Slim::Embedded.options[engine.to_sym] ||= {})[:context] = opts[:context]
|
2015-06-17 01:47:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2014-02-19 03:30:29 +01:00
|
|
|
def precompiled_preamble(locals)
|
|
|
|
"__in_slim_template = true\n" << super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-28 22:19:40 +02:00
|
|
|
module Middleman
|
|
|
|
module Renderers
|
|
|
|
# Slim renderer
|
2014-07-05 22:41:59 +02:00
|
|
|
class Slim < ::Middleman::Extension
|
2012-05-28 22:19:40 +02:00
|
|
|
# Setup extension
|
2014-07-05 22:41:59 +02:00
|
|
|
def initialize(_app, _options={}, &_block)
|
2014-07-10 22:30:16 +02:00
|
|
|
super
|
|
|
|
|
2014-07-05 22:41:59 +02:00
|
|
|
# Setup Slim options to work with partials
|
2015-04-26 22:22:58 +02:00
|
|
|
::Slim::Engine.disable_option_validator!
|
2014-12-23 23:54:21 +01:00
|
|
|
::Slim::Engine.set_options(
|
2014-07-05 22:41:59 +02:00
|
|
|
buffer: '@_out_buf',
|
|
|
|
use_html_safe: true,
|
|
|
|
generator: ::Temple::Generators::RailsOutputBuffer,
|
|
|
|
disable_escape: true
|
|
|
|
)
|
|
|
|
end
|
2012-05-28 22:19:40 +02:00
|
|
|
end
|
|
|
|
end
|
2012-08-14 00:39:06 +02:00
|
|
|
end
|