Class: Usmu::Template::Include

Inherits:
Layout show all
Defined in:
lib/usmu/template/include.rb

Overview

Represents a page in the source directory of the website.

Instance Attribute Summary collapse

Attributes inherited from Layout

#helpers, #input_path, #output_extension, #output_filename, #parent, #provider_name, #template_class, #type

Attributes inherited from StaticFile

#input_path, #mtime, #name, #output_filename

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Layout

#[]=, #add_template_defaults, find_layout, #initialize, is_valid_file?, #render, #render_content, search_layout

Methods inherited from StaticFile

#==, #initialize, #inspect, #render

Methods included from Helpers::Indexer

included

Constructor Details

This class inherits a constructor from Usmu::Template::Layout

Instance Attribute Details

#argumentsHash

Returns the arguments associated with this include.

Returns:

  • (Hash)

    the arguments associated with this include



18
19
20
# File 'lib/usmu/template/include.rb', line 18

def arguments
  @arguments
end

#content_pathstring (readonly, protected)

Returns the base path to the files used by this class.

This folder should be the parent folder for the file named by the name attribute.

Returns:

  • (string)

    the base path to the files used by this class.

See Also:



71
72
73
# File 'lib/usmu/template/include.rb', line 71

def content_path
  @configuration.includes_path
end

#metadataHash (readonly)

Returns the metadata associated with this layout.

This will include any metadata from parent templates and default metadata

Returns:

  • (Hash)

    the metadata associated with this layout.



53
54
55
56
57
58
59
# File 'lib/usmu/template/include.rb', line 53

def 
  meta = 
  # Includes must never allow layout inheritance.
  meta['layout'] = nil

  meta
end

Class Method Details

.find_include(configuration, name) ⇒ Usmu::Layout

Static method to create an include for a given configuration by it's name if it exists. This differs from #initialise in that it allows different types of values to be supplied as the name and will not fail if name is nil

Parameters:

  • configuration (Usmu::Configuration)

    The configuration to use for the search

  • name (String)

    If name is a string then search for a template with that name. Name here should not include file extension, eg. body not body.slim. If name is not a string then it will be returned verbatim. This means that name is nilable and can also be passed in as an Usmu::Template::Include already for testing purposes.

Returns:

  • (Usmu::Layout)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/usmu/template/include.rb', line 30

def self.find_include(configuration, name)
  if name === 'none'
    nil
  elsif name.class.name == 'String'
    Dir["#{configuration.includes_path}/#{name}.*"].each do |f|
      filename = File.basename(f)
      if filename != "#{name}.meta.yml"
        path = f[(configuration.includes_path.length + 1)..f.length]
        return new(configuration, path, configuration..(path))
      end
    end
    nil
  else
    name
  end
end

Instance Method Details

#get_variables(variables) ⇒ Hash (private)

Utility function which collates variables to pass to the template engine.

Returns:

  • (Hash)


80
81
82
83
84
85
86
87
# File 'lib/usmu/template/include.rb', line 80

def get_variables(variables)
  args = {}
  arguments.each do |i, value|
    args[i.class.name == 'String' ? i : i.to_s] = value
  end

  {'site' => @configuration}.deep_merge!().deep_merge!(args).deep_merge!(variables)
end

#layout_metadatavoid (private)

Preserved version of the layout metadata logic

See Also:



12
# File 'lib/usmu/template/include.rb', line 12

alias :layout_metadata :metadata