Class: Yattho::TimeAgoComponent

Inherits:
Component
  • Object
show all
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

Status::Dsl::STATUSES

Constants included from ViewHelper

ViewHelper::HELPERS

Constants included from TestSelectorHelper

Yattho::TestSelectorHelper::TEST_SELECTOR_TAG

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods inherited from Component

deprecated?, generate_id

Methods included from JoinStyleArgumentsHelper

#join_style_arguments

Methods included from TestSelectorHelper

#add_test_selector

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(time:, micro: false, **system_arguments) ⇒ TimeAgoComponent

Returns a new instance of TimeAgoComponent.

Examples:

Default

<%= render(Yattho::TimeAgoComponent.new(time: Time.at(628232400))) %>

Parameters:

  • time (Time)

    The time to be formatted

  • micro (Boolean) (defaults to: false)

    If true then the text will be formatted in “micro” mode, using as few characters as possible

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



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

#callObject



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