Friday, September 20, 2024 12:16:17 AM
> settings

Customize


Authenticate

> application_helper.rb
# frozen_string_literal: true

module ApplicationHelper
  READING_FONTS = [
    {name: "Barecast (stylized)", family: "Barecast"},
    {name: "Quicksand (sans serif)", family: "Quicksand"},
    {name: "Atkinson Hyperlegible", family: "Atkinson Hyperlegible"},
    {name: "Comic Neue", family: "Comic Neue Angular"},
    {name: "JetBrains Mono", family: "JetBrains Mono"},
    {name: "Nunito", family: "Nunito"}
  ].freeze

  START_YEAR = 2024

  include ViewComponentsHelper

  def reading_fonts
    READING_FONTS.map { |f| [f[:name], f[:family]] }
  end

  def copyright
    year = START_YEAR
    current_year = Time.zone.today.year
    year = "#{year} - #{current_year}" if current_year != year

    "#{year} itsthedevman"
  end

  def create_toast(body, title: "", subtitle: "")
    turbo_stream.append("toast-container") do
      concat(
        render(
          view_component(
            ToastComponent,
            title: title, subtitle: subtitle, body: body
          )
        )
      )
    end
  end

  def js_timestamp(timestamp, format: "")
    tag.span data: {controller: "timestamp", timestamp:, format:} do
      timestamp
    end
  end

  def window_html_options(locals)
    locals.merge(class: "window #{locals[:class]}")
  end

  def update_turbo_modal(&block)
    turbo_frame_tag "turbo_modal" do
      yield

      concat <<~HTML.html_safe
        <script>
          bootstrap.Modal.getOrCreateInstance(document.getElementById("turbo-modal")).show();
        </script>
      HTML
    end
  end

  def hide_turbo_modal
    turbo_stream.append("turbo_modal") do
      <<~HTML.html_safe
        <script>
          bootstrap.Modal.getOrCreateInstance(document.getElementById("turbo-modal")).hide();
        </script>
      HTML
    end
  end
end
All opinions represented herein are my own
- © 2024 itsthedevman
- build 340fbb8