Module: Mint::Layout

Defined in:
lib/mint/layout.rb

Constant Summary collapse

HTML_EXTENSIONS =
["html", "erb"]

Class Method Summary collapse

Class Method Details

.find_by_name(name) ⇒ Pathname

Returns the layout file for the given template name

Parameters:

  • name (String)

    the template name or directory path to look up

Returns:

  • (Pathname)

    path to the layout file



19
20
21
# File 'lib/mint/layout.rb', line 19

def self.find_by_name(name)
  find_in_directory Template.find_directory_by_name(name)
end

.find_in_directory(directory) ⇒ Pathname

Finds the layout file in a specific directory

Parameters:

  • directory (Pathname)

    the directory to look in

Returns:

  • (Pathname)

    path to the layout file



27
28
29
# File 'lib/mint/layout.rb', line 27

def self.find_in_directory(directory)
  directory&.children&.select(&:file?)&.select(&method(:valid?))&.first
end

.valid?(pathname) ⇒ Boolean

Indicates whether the file is a valid layout file

Parameters:

  • pathname (Pathname)

    the pathname to check

Returns:

  • (Boolean)

    true if the file is a valid layout file



11
12
13
# File 'lib/mint/layout.rb', line 11

def self.valid?(pathname)
  HTML_EXTENSIONS.map {|ext| "layout.#{ext}" }.include? pathname.basename.to_s
end