Class: DocsKit::DocVersion
- Inherits:
-
Data
- Object
- Data
- DocsKit::DocVersion
- 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
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#noindex ⇒ Object
readonly
Returns the value of attribute noindex.
-
#ref ⇒ Object
readonly
Returns the value of attribute ref.
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
- #archived? ⇒ Boolean
- #current? ⇒ Boolean
-
#initialize(id:, label: nil, ref: nil, current: false, noindex: nil) ⇒ DocVersion
constructor
A new instance of DocVersion.
-
#path_prefix ⇒ Object
The root URL segment this version contributes: "" for the current version (existing sites and their SEO untouched), "/##id" for an archived one.
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
#current ⇒ Object (readonly)
Returns the value of attribute current
22 23 24 |
# File 'lib/docs_kit/doc_version.rb', line 22 def current @current end |
#id ⇒ Object (readonly)
Returns the value of attribute id
22 23 24 |
# File 'lib/docs_kit/doc_version.rb', line 22 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label
22 23 24 |
# File 'lib/docs_kit/doc_version.rb', line 22 def label @label end |
#noindex ⇒ Object (readonly)
Returns the value of attribute noindex
22 23 24 |
# File 'lib/docs_kit/doc_version.rb', line 22 def noindex @noindex end |
#ref ⇒ Object (readonly)
Returns the value of attribute 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
50 |
# File 'lib/docs_kit/doc_version.rb', line 50 def archived? = !current? |
#current? ⇒ Boolean
48 |
# File 'lib/docs_kit/doc_version.rb', line 48 def current? = !!current |
#path_prefix ⇒ Object
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 |