module Dry::View::Tilt

@api private

Public Class Methods

[](path, mapping, **options) click to toggle source
# File lib/dry/view/tilt.rb, line 13
def [](path, mapping, **options)
  ext = File.extname(path).sub(/^./, "").to_sym
  activate_adapter ext

  with_mapping(mapping).new(path, **options)
end
default_mapping() click to toggle source
# File lib/dry/view/tilt.rb, line 20
def default_mapping
  ::Tilt.default_mapping
end
deregister_adapter(ext) click to toggle source
# File lib/dry/view/tilt.rb, line 28
def deregister_adapter(ext)
  adapters.delete(ext)
end
register_adapter(ext, adapter) click to toggle source
# File lib/dry/view/tilt.rb, line 24
def register_adapter(ext, adapter)
  adapters[ext] = adapter
end

Private Class Methods

activate_adapter(ext) click to toggle source
# File lib/dry/view/tilt.rb, line 38
def activate_adapter(ext)
  fetch_or_store(:adapter, ext) {
    adapter = adapters[ext]
    return unless adapter

    *requires, error_message = adapter.requirements

    begin
      requires.each(&method(:require))
    rescue LoadError => e
      raise e, "#{e.message}\n\n#{error_message}"
    end

    adapter.activate
  }
end
adapters() click to toggle source
# File lib/dry/view/tilt.rb, line 34
def adapters
  @adapters ||= {}
end
build_mapping(mapping) click to toggle source
# File lib/dry/view/tilt.rb, line 65
def build_mapping(mapping)
  default_mapping.dup.tap do |new_mapping|
    mapping.each do |extension, template_class|
      new_mapping.register template_class, extension
    end
  end
end
with_mapping(mapping) click to toggle source
# File lib/dry/view/tilt.rb, line 55
def with_mapping(mapping)
  fetch_or_store(:mapping, mapping) {
    if mapping.any?
      build_mapping(mapping)
    else
      default_mapping
    end
  }
end