module Sigmund
  module Liquid
    module Tags
      class ActiveLink < ::Liquid::Tag
        include Locomotive::Liquid::Tags::PathHelper
        include ActionView::Helpers::UrlHelper
        def render(context)
          @page = context.registers[:page] 
          render_path(context) do |page, path|
            if path == '/'
              return  @page.handle == 'index' ? 'active' : ''
            else 
              @page.fullpath =~ /^#{page.fullpath}(\/.*)?$/ ? 'active' : ''
            end
          end
        end
      end
      ::Liquid::Template.register_tag('active_link', ActiveLink)
    end
  end
end