Class: Statique::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/statique/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, statique) ⇒ Document

Returns a new instance of Document.



9
10
11
12
# File 'lib/statique/document.rb', line 9

def initialize(file, statique)
  parsed = FrontMatterParser::Parser.parse_file(file)
  @file, @meta, @content, @statique = file.freeze, Hashie::Mash.new(parsed.front_matter).freeze, parsed.content.freeze, statique
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/statique/document.rb', line 7

def content
  @content
end

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/statique/document.rb', line 7

def file
  @file
end

#metaObject (readonly)

Returns the value of attribute meta.



7
8
9
# File 'lib/statique/document.rb', line 7

def meta
  @meta
end

Instance Method Details

#bodyObject



39
40
41
# File 'lib/statique/document.rb', line 39

def body
  content
end

#engine_nameObject



27
28
29
# File 'lib/statique/document.rb', line 27

def engine_name
  extname.delete_prefix(".").freeze
end

#layout_nameObject



31
32
33
# File 'lib/statique/document.rb', line 31

def layout_name
  meta.fetch("layout") { "layout" }.freeze
end

#pagination_pagesObject



43
44
45
46
47
# File 'lib/statique/document.rb', line 43

def pagination_pages
  return unless @statique.discover.collections.key?(meta.paginates)
  collection = @statique.discover.collections[meta.paginates]
  (collection.size.to_f / Paginator.per_page).ceil
end

#pathObject



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

def path
  case basename
  when "index.slim" then "/"
  when "index.md" then "/"
  else
    "/#{meta.permalink || basename.delete_suffix(extname).delete_prefix(@statique.configuration.paths.content.to_s)}"
  end.freeze
end

#published_atObject



49
50
51
# File 'lib/statique/document.rb', line 49

def published_at
  @published_at ||= file.ctime.freeze
end

#titleObject



35
36
37
# File 'lib/statique/document.rb', line 35

def title
  meta.title.freeze
end

#view_nameObject



23
24
25
# File 'lib/statique/document.rb', line 23

def view_name
  basename.delete_suffix(extname).freeze
end