Sha256: 26ad6c96fd48523479f28214fbfd50b171950b5376e56701a56340a8d99ec671

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

require 'plezi/render/has_cache' unless defined? ::Plezi::Base::HasStore
module Plezi
  module Base
    module RenderSlim
      extend ::Plezi::Base::HasStore

      module_function

      def call(filename, context, &block)
        return unless defined? ::Slim
        return unless File.exist?(filename)
        engine = load_engine(filename)
        engine.render(context.receiver, &block)
      end
      if ENV['RACK_ENV'.freeze] == 'production'.freeze
        def load_engine(filename)
          engine = self[filename]
          return engine if engine
          self[filename] = (Slim::Template.new { ::Plezi.try_utf8!(IO.binread(filename)) })
        end
      else
        def load_engine(filename)
          engine, tm = self[filename]
          return engine if engine && (tm == File.mtime(filename))
          self[filename] = [(engine = Slim::Template.new { ::Plezi.try_utf8!(IO.binread(filename)) }), File.mtime(filename)]
          engine
        end
      end
    end
  end
end

::Plezi::Renderer.register :slim, ::Plezi::Base::RenderSlim

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
plezi-0.14.4 lib/plezi/render/slim.rb
plezi-0.14.3 lib/plezi/render/slim.rb
plezi-0.14.2 lib/plezi/render/slim.rb
plezi-0.14.1 lib/plezi/render/slim.rb
plezi-0.14.0 lib/plezi/render/slim.rb