Class: Tramway::NativeTextComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/tramway/native_text_component.rb

Overview

Displays text with size-based utility classes.

Constant Summary collapse

URL_REGEX =
%r{https?://[^\s<]+}
MAX_URL_LENGTH =
41
HEADER_REGEX =
/\A(#{Regexp.escape('#')}{1,6})\s+(.+)\z/
LIST_ITEM_REGEX =
/\A[-*]\s+(.+)\z/
HEADER_CLASSES =
{
  1 => 'text-4xl font-bold leading-tight mt-4 mb-2',
  2 => 'text-3xl font-bold leading-tight mt-4 mb-2',
  3 => 'text-2xl font-semibold leading-snug mt-3 mb-2',
  4 => 'text-xl font-semibold leading-snug mt-3 mb-2',
  5 => 'text-lg font-semibold leading-snug mt-2 mb-1',
  6 => 'text-base font-semibold leading-snug mt-2 mb-1'
}.freeze

Constants included from Helpers::ViewsHelper

Helpers::ViewsHelper::FORM_SIZES

Instance Method Summary collapse

Methods included from Helpers::ViewsHelper

#tramway_back_button, #tramway_badge, #tramway_button, #tramway_cell, #tramway_chat, #tramway_container, #tramway_flash, #tramway_form_for, #tramway_header, #tramway_main_container, #tramway_row, #tramway_table, #tramway_title

Methods included from Helpers::ComponentHelper

#component

Methods included from Helpers::DecorateHelper

#tramway_decorate

Instance Method Details

#rendered_htmlObject



25
26
27
28
29
30
# File 'app/components/tramway/native_text_component.rb', line 25

def rendered_html
  # Safe because this is an empty static string literal, not user-controlled content.
  return ''.html_safe if text.blank?

  helpers.safe_join(rendered_blocks)
end

#text_classObject



32
33
34
# File 'app/components/tramway/native_text_component.rb', line 32

def text_class
  { small: 'text-sm', large: 'text-lg', middle: 'text-base' }.fetch(size, 'md:text-sm lg:text-base') + " #{klass}"
end