Class: DocsKit::DocVersion

Inherits:
Data
  • Object
show all
Defined in:
lib/docs_kit/doc_version.rb

Overview

One documentation version a site serves. Sites declare these in config as plain Hashes; #versions normalizes each into a DocVersion so the chrome and the AI surfaces stay value-object-driven (like DocsKit::TopbarLink):

c.versions = [
{ id: "1.1", ref: "v1.1.0", current: true },
{ id: "1.0", ref: "v1.0.0" },
]

#id is the URL segment (an archived version serves at "/##id/docs/..."); #label is the switcher text (defaults to the id); #ref is the git ref backing the GitHub compare link (optional); #current marks the version serving unprefixed at /docs (exactly today's URLs); #noindex defaults to the inverse of #current — archived copies are noindex'd so search engines keep pointing at the current docs, overridable per version with noindex: false.

Named DocVersion, not Version — lib/docs_kit/version.rb already owns that file slot and defines DocsKit::VERSION.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, label: nil, ref: nil, current: false, noindex: nil) ⇒ DocVersion

Returns a new instance of DocVersion.



23
24
25
26
27
28
29
30
31
# File 'lib/docs_kit/doc_version.rb', line 23

def initialize(id:, label: nil, ref: nil, current: false, noindex: nil)
  super(
    id: id,
    label: label || id.to_s,
    ref: ref,
    current: current,
    noindex: noindex.nil? ? !current : noindex
  )
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current

Returns:

  • (Object)

    the current value of current



22
23
24
# File 'lib/docs_kit/doc_version.rb', line 22

def current
  @current
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



22
23
24
# File 'lib/docs_kit/doc_version.rb', line 22

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



22
23
24
# File 'lib/docs_kit/doc_version.rb', line 22

def label
  @label
end

#noindexObject (readonly)

Returns the value of attribute noindex

Returns:

  • (Object)

    the current value of noindex



22
23
24
# File 'lib/docs_kit/doc_version.rb', line 22

def noindex
  @noindex
end

#refObject (readonly)

Returns the value of attribute ref

Returns:

  • (Object)

    the current value of ref



22
23
24
# File 'lib/docs_kit/doc_version.rb', line 22

def ref
  @ref
end

Class Method Details

.from(version) ⇒ Object

Build a DocVersion from a Hash (symbol- OR string-keyed, so a YAML/JSON config loads cleanly) or pass an existing DocVersion through unchanged.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/docs_kit/doc_version.rb', line 35

def self.from(version)
  return version if version.is_a?(self)

  attrs = version.to_h.transform_keys(&:to_sym)
  new(
    id: attrs[:id],
    label: attrs[:label],
    ref: attrs[:ref],
    current: attrs.fetch(:current, false),
    noindex: attrs[:noindex]
  )
end

Instance Method Details

#archived?Boolean

Returns:

  • (Boolean)


50
# File 'lib/docs_kit/doc_version.rb', line 50

def archived? = !current?

#current?Boolean

Returns:

  • (Boolean)


48
# File 'lib/docs_kit/doc_version.rb', line 48

def current? = !!current

#path_prefixObject

The root URL segment this version contributes: "" for the current version (existing sites and their SEO untouched), "/##id" for an archived one. Stacks with the i18n locale prefix later ("/de/1.0/docs/...").



55
56
57
# File 'lib/docs_kit/doc_version.rb', line 55

def path_prefix
  current? ? "" : "/#{id}"
end