class Slim::Include
Handles inlined includes
Slim
files are compiled, non-Slim files are included as text with ‘#{interpolation}`
@api private
Public Instance Methods
on_html_tag(tag, attributes, content = nil)
click to toggle source
Calls superclass method
# File lib/slim/include.rb, line 13 def on_html_tag(tag, attributes, content = nil) return super if tag != 'include' name = content.to_a.flatten.select {|s| String === s }.join raise ArgumentError, 'Invalid include statement' unless attributes == [:html, :attrs] && !name.empty? unless file = find_file(name) name = "#{name}.slim" if name !~ /\.slim\Z/i file = find_file(name) end raise Temple::FilterError, "'#{name}' not found in #{options[:include_dirs].join(':')}" unless file content = File.read(file) if file =~ /\.slim\Z/i Thread.current[:slim_include_engine].call(content) else [:slim, :interpolate, content] end end
Protected Instance Methods
find_file(name)
click to toggle source
# File lib/slim/include.rb, line 32 def find_file(name) current_dir = File.dirname(File.expand_path(options[:file])) options[:include_dirs].map {|dir| File.expand_path(File.join(dir, name), current_dir) }.find {|file| File.file?(file) } end