Class: Yattho::TimeAgoComponent
- Defined in:
- app/components/yattho/time_ago_component.rb
Overview
Use ‘TimeAgo` to display a time relative to how long ago it was. This component requires JavaScript.
Constant Summary
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
Yattho::TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(time:, micro: false, **system_arguments) ⇒ TimeAgoComponent
constructor
A new instance of TimeAgoComponent.
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Constructor Details
#initialize(time:, micro: false, **system_arguments) ⇒ TimeAgoComponent
Returns a new instance of TimeAgoComponent.
14 15 16 17 18 19 20 21 22 23 |
# File 'app/components/yattho/time_ago_component.rb', line 14 def initialize(time:, micro: false, **system_arguments) @system_arguments = deny_tag_argument(**system_arguments) @system_arguments[:datetime] = time.utc.iso8601 @system_arguments[:classes] = class_names("no-wrap", @system_arguments[:classes]) @system_arguments[:tag] = "relative-time" @system_arguments[:tense] = "past" @system_arguments[:format] = "micro" if micro @time = time @micro = micro end |
Instance Method Details
#call ⇒ Object
25 26 27 |
# File 'app/components/yattho/time_ago_component.rb', line 25 def call render(Yattho::BaseComponent.new(**@system_arguments)) { time_in_words } end |