Module: LocoMotion::Helpers
- Defined in:
- lib/loco_motion/helpers.rb
Class Method Summary collapse
-
.component_example_path(component_name) ⇒ String
The demo app's example route for a component, keyed by its full class name.
-
.component_partial_path(component_name) ⇒ String
The demo app's partial path for a component's example view, derived from its full class name and COMPONENTS entry.
-
.new_component?(component_name) ⇒ Boolean
Whether a component was added in the current (or upcoming) minor release.
Class Method Details
.component_example_path(component_name) ⇒ String
The demo app's example route for a component, keyed by its full class name.
191 192 193 |
# File 'lib/loco_motion/helpers.rb', line 191 def component_example_path(component_name) "/examples/#{component_name}" end |
.component_partial_path(component_name) ⇒ String
The demo app's partial path for a component's example view, derived
from its full class name and COMPONENTS entry. The class
name's first segment (Daisy/Loco) becomes the framework
directory; for 3-segment names (e.g. Daisy::Layout::AuraComponent)
the middle segment becomes an additional section directory (e.g.
layout/), while 2-segment names (e.g. Loco::IconComponent) have no
section directory.
209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/loco_motion/helpers.rb', line 209 def component_partial_path(component_name) comp = COMPONENTS[component_name] comp_split = component_name.split("::") framework = comp_split.first.underscore section = comp_split.length == 3 ? comp_split[1] : nil example = comp[:example] section_path = section ? "#{section.underscore}/" : "" "/examples/#{framework}/#{section_path}#{example}" end |
.new_component?(component_name) ⇒ Boolean
Whether a component was added in the current (or upcoming) minor
release. Powers the "New" badges in the demo nav: registry entries opt
in with an added: "MAJOR.MINOR" key, and the badge expires on its own
once LocoMotion::VERSION moves past that series.
174 175 176 177 178 179 180 |
# File 'lib/loco_motion/helpers.rb', line 174 def new_component?(component_name) added = COMPONENTS.dig(component_name, :added) return false if added.nil? current_series = Gem::Version.new(LocoMotion::VERSION).segments[0..1].join(".") Gem::Version.new(added) >= Gem::Version.new(current_series) end |