Module: BitClust::VersionBadges

Included in:
RDCompiler, TemplateScreen
Defined in:
lib/bitclust/version_badges.rb

Overview

Renders the small "since"/"until" version badges shown next to a method's signature (bitclust#132 phase P3). The version data comes from MethodEntry's per-name since_map/until_map (bitclust#132 phase P2); an empty map means "no badge", which keeps the output byte-identical to what it was before this feature existed.

Included by both RDCompiler (the

emitted for RD/Markdown method pages) and TemplateScreen (the default server template's method table rows), so it only relies on the _ (Translatable) and escape_html (HTMLUtils) methods that both hosts already provide.

Constant Summary collapse

SINCE_CSS_CLASS =
'method-since-badge'
UNTIL_CSS_CLASS =
'method-until-badge'
SINCE_CATALOG_KEY =
'since Ruby %s'
UNTIL_CATALOG_KEY =
'removed in Ruby %s'

Instance Method Summary collapse

Instance Method Details

#heading_version_badges(entry, name, first) ⇒ Object

HTML for the badges attached to the

heading of one of +entry+'s signature lines (RDCompiler#method_signature). since/until are decided independently: when every one of entry's names maps to the very same version, the badge is rendered once, on the first signature's
(+first+ true), instead of being repeated on every alias's
; otherwise (mixed/partial) it is looked up per name.



34
35
36
37
38
39
40
41
42
# File 'lib/bitclust/version_badges.rb', line 34

def heading_version_badges(entry, name, first)
  name = badge_lookup_name(name)
  join_badge_spans(
    heading_badge_span(entry, name, first, entry.since_map,
                        SINCE_CSS_CLASS, SINCE_CATALOG_KEY),
    heading_badge_span(entry, name, first, entry.until_map,
                        UNTIL_CSS_CLASS, UNTIL_CATALOG_KEY)
  )
end

#row_version_badges(entry, name) ⇒ Object

HTML for the badges attached to a single signature line in the default (server) template's method table (data/bitclust/template/class). Each row already lists every alias on its own line, so this always looks the version up by name directly -- no uniform-across-all-names aggregation, unlike heading_version_badges.



49
50
51
52
53
54
55
# File 'lib/bitclust/version_badges.rb', line 49

def row_version_badges(entry, name)
  name = badge_lookup_name(name)
  join_badge_spans(
    badge_span(entry.since_map[name], SINCE_CSS_CLASS, SINCE_CATALOG_KEY),
    badge_span(entry.until_map[name], UNTIL_CSS_CLASS, UNTIL_CATALOG_KEY)
  )
end