Class: DocsKit::Snapshot::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/docs_kit/snapshot/entry.rb

Overview

One snapshot page — the duck type of DocsKit::Registry::Entry (#slug / #title / #group / #icon / #href / #view_class / #renderable), so the enumeration seam (LlmsText.pages) and its consumers treat a frozen Markdown page exactly like a live Ruby one. #view_class is the truthy DocsUI::ArchivedPage constant, so the select(&:view_class) authored-page filter passes unchanged.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs, version:, root:, registry_prefix:) ⇒ Entry

Returns a new instance of Entry.



14
15
16
17
18
19
20
21
22
23
# File 'lib/docs_kit/snapshot/entry.rb', line 14

def initialize(attrs, version:, root:, registry_prefix:)
  @slug = attrs["slug"]
  @title = attrs["title"]
  @group = attrs["group"]
  @icon = attrs["icon"]
  @file = attrs["file"]
  @digest = attrs["digest"]
  @root = root
  @href = "#{version.path_prefix}#{registry_prefix}/#{@slug}"
end

Instance Attribute Details

#digestObject (readonly)

Returns the value of attribute digest.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def digest
  @digest
end

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def file
  @file
end

#groupObject (readonly)

Returns the value of attribute group.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def group
  @group
end

#hrefObject (readonly)

Returns the value of attribute href.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def icon
  @icon
end

#slugObject (readonly)

Returns the value of attribute slug.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def slug
  @slug
end

#titleObject (readonly)

Returns the value of attribute title.



12
13
14
# File 'lib/docs_kit/snapshot/entry.rb', line 12

def title
  @title
end

Instance Method Details

#markdownObject

The raw Markdown body from the snapshot file. A missing/unreadable file degrades to "" — the page renders empty rather than 500ing.



39
40
41
42
43
44
45
# File 'lib/docs_kit/snapshot/entry.rb', line 39

def markdown
  return "" if @root.nil? || @file.nil?

  @root.join(@file).read
rescue SystemCallError
  ""
end

#renderableObject

The renderable the controllers hand to Phlex — an ArchivedPage carrying this entry, where a live Registry::Entry builds view_class.new.



33
34
35
# File 'lib/docs_kit/snapshot/entry.rb', line 33

def renderable
  DocsUI::ArchivedPage.new(entry: self)
end

#view_classObject

The renderer for every archived page. Truthy (never nil): a snapshot page is by definition authored — its content is the committed .md file.



27
28
29
# File 'lib/docs_kit/snapshot/entry.rb', line 27

def view_class
  DocsUI::ArchivedPage
end