Class: Jekyll::Page

Inherits:
Object
  • Object
show all
Includes:
Convertible
Defined in:
lib/jekyll/page.rb

Direct Known Subclasses

Archive, CategoryIndex

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Convertible

#content_type, #do_layout, #read_yaml, #to_s, #transform

Constructor Details

#initialize(site, base, dir, name) ⇒ Page

Initialize a new Page.

+site+ is the Site
+base+ is the String path to the <source>
+dir+ is the String path between <source> and the file
+name+ is the String filename of the file

Returns <Page>



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll/page.rb', line 17

def initialize(site, base, dir, name)
  @site = site
  @base = base
  @dir = dir
  @name = name

  self.data = {}

  self.process(name)
  self.read_yaml(File.join(base, dir), name)
  #self.transform
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



8
9
10
# File 'lib/jekyll/page.rb', line 8

def content
  @content
end

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/jekyll/page.rb', line 8

def data
  @data
end

#extObject

Returns the value of attribute ext.



7
8
9
# File 'lib/jekyll/page.rb', line 7

def ext
  @ext
end

#outputObject

Returns the value of attribute output.



8
9
10
# File 'lib/jekyll/page.rb', line 8

def output
  @output
end

#siteObject

Returns the value of attribute site.



6
7
8
# File 'lib/jekyll/page.rb', line 6

def site
  @site
end

Instance Method Details

#process(name) ⇒ Object

Extract information from the page filename

+name+ is the String filename of the page file

Returns nothing



34
35
36
# File 'lib/jekyll/page.rb', line 34

def process(name)
  self.ext = File.extname(name)
end

#render(layouts, site_payload) ⇒ Object

Add any necessary layouts to this post

+layouts+ is a Hash of {"name" => "layout"}
+site_payload+ is the site payload hash

Returns nothing



43
44
45
46
# File 'lib/jekyll/page.rb', line 43

def render(layouts, site_payload)
  payload = {"page" => self.data}.deep_merge(site_payload)
  do_layout(payload, layouts)
end

#write(dest) ⇒ Object

Write the generated page file to the destination directory.

+dest+ is the String path to the destination dir

Returns nothing



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/jekyll/page.rb', line 52

def write(dest)
  FileUtils.mkdir_p(File.join(dest, @dir))

  name = @name
  if self.ext != ""
    name = @name.split(".")[0..-2].join('.') + self.ext
  end

  path = File.join(dest, @dir, name)
  File.open(path, 'w') do |f|
    f.write(self.output)
  end
end