Class: Jekyll::Inclusion

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/inclusion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, base, name) ⇒ Inclusion

Returns a new instance of Inclusion.


8
9
10
11
12
# File 'lib/jekyll/inclusion.rb', line 8

def initialize(site, base, name)
  @site = site
  @name = name
  @path = PathManager.join(base, name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'lib/jekyll/inclusion.rb', line 5

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path


5
6
7
# File 'lib/jekyll/inclusion.rb', line 5

def path
  @path
end

Instance Method Details

#contentObject


23
24
25
# File 'lib/jekyll/inclusion.rb', line 23

def content
  @content ||= File.read(path, **site.file_read_opts)
end

#inspectObject Also known as: to_s


27
28
29
# File 'lib/jekyll/inclusion.rb', line 27

def inspect
  "#{self.class} #{path.inspect}"
end

#render(context) ⇒ Object


14
15
16
17
18
19
20
21
# File 'lib/jekyll/inclusion.rb', line 14

def render(context)
  @template ||= site.liquid_renderer.file(path).parse(content)
  @template.render!(context)
rescue Liquid::Error => e
  e.template_name  = path
  e.markup_context = "included " if e.markup_context.nil?
  raise e
end