Sha256: 9416b202222bb76256ef4b7639598c8b082c9a0c82bfc17d8342c9848ff412ae

Contents?: true

Size: 1.7 KB

Versions: 54

Compression:

Stored size: 1.7 KB

Contents

module Plutonium
  module Helpers
    module ContentHelper
      def timeago(date, format: :long)
        return if date.blank?

        content = I18n.l(date, format:)
        tag.time(
          content,
          title: content,
          data: {
            controller: "timeago",
            timeago_refresh_interval_value: 1000,
            timeago_include_seconds_value: true,
            timeago_add_suffix_value: true,
            timeago_datetime_value: date.iso8601
          }
        )
      end

      def read_more(content, clamp = 4)
        return if content.blank?

        # Stimulus Read More (https://www.stimulus-components.com/docs/stimulus-read-more/)
        style = "overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; " \
                "-webkit-line-clamp: var(--read-more-line-clamp, #{clamp});"

        tag.div(
          data: {
            controller: "read-more",
            read_more_more_text_value: "Read more",
            read_more_less_text_value: "Read less"
          }
        ) do
          concat tag.div(content,
            style:,
            data: {read_more_target: "content"})

          next unless content.lines.size > clamp

          concat tag.button("Read more",
            class: "btn btn-sm btn-link text-decoration-none ps-0",
            data: {action: "read-more#toggle"})
        end
      end

      def quill(content)
        return if content.blank?

        tag.div(
          content,
          class: "ql-viewer",
          data: {
            controller: "quill-viewer"
          }
        )
      end

      def clamp_content(content)
        return if content.blank?

        tag.div content, class: "clamped-content"
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
plutonium-0.15.22 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.21 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.20 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.19 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.18 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.17 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.16 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.15 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.14 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.13 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.12 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.11 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.10 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.9 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.8 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.7 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.6 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.5 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.4 lib/plutonium/helpers/content_helper.rb
plutonium-0.15.3 lib/plutonium/helpers/content_helper.rb