Sha256: ba5cca6f32dfb114dadc8b1717a00b430ae02a5e417b49db82c514f4bce5c387

Contents?: true

Size: 612 Bytes

Versions: 1

Compression:

Stored size: 612 Bytes

Contents

# frozen_string_literal: true

module Components
	class Nav::Item < Phlex::View
		def initialize(text, to:, active_page:)
			@text = text
			@to = to
			@active_page = active_page
		end

		def template
			li do
				a(**link_classes, href: "/#{link}") { @text }
			end
		end

		def link_classes
			classes("pb-1 block font-medium text-stone-500", active?: "text-red-600 font-bold")
		end

		def link
			path == "index" ? "" : path
		end

		def path
			@to.name.split("::")[1..].map { _1.gsub(/(.)([A-Z])/, '\1-\2') }.map(&:downcase).join("/")
		end

		def active?
			@active_page.instance_of?(@to)
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phlex-0.4.0 docs/components/nav/item.rb