Sha256: 43e62112b7cc77c80384839a325cbda5c69cd7d7427ee8221a2a20de65d541bd

Contents?: true

Size: 860 Bytes

Versions: 4

Compression:

Stored size: 860 Bytes

Contents

# frozen_string_literal: true

module Maquina
  module Navbar
    class MenuItemLink < Phlex::HTML
      include ApplicationView
      delegate :t, :active_menu_option?, to: :helpers

      def initialize(option, path, desktop: true, active: false)
        @option = option
        @path = path
        @active = active
        @desktop = desktop
      end

      def view_template
        a(href: @path, **classes("#{link_type}-menu-item", active?: "#{link_type}-menu-item__active")) { t("menu.main.#{@option}") }
      end

      private

      def active?
        active_menu_option?(@path)
      rescue NoMethodError => ex
        Rails.logger.error "[#{self.class}] Please implement helper method :active_menu_option?(path) :: #{ex.message}"
        false
      end

      def link_type
        @desktop ? "desktop" : "mobile"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
maquina-0.7.2 app/views/maquina/navbar/menu_item_link.rb
maquina-0.7.1 app/views/maquina/navbar/menu_item_link.rb
maquina-0.5.2 app/views/maquina/navbar/menu_item_link.rb
maquina-0.5.1 app/views/maquina/navbar/menu_item_link.rb