module Loaf::ViewExtensions
A mixin to define view extensions
Public Class Methods
new(*)
click to toggle source
Calls superclass method
# File lib/loaf/view_extensions.rb, line 13 def initialize(*) @_breadcrumbs ||= [] super end
Public Instance Methods
current_crumb?(path, pattern = :inclusive)
click to toggle source
Check if breadcrumb is current based on the pattern
@param [String] path @param [Object] pattern
the pattern to match on
@api public
# File lib/loaf/view_extensions.rb, line 68 def current_crumb?(path, pattern = :inclusive) return false unless request.get? || request.head? origin_path = URI::DEFAULT_PARSER.unescape(path).force_encoding(Encoding::BINARY) request_uri = request.fullpath request_uri = URI::DEFAULT_PARSER.unescape(request_uri) request_uri.force_encoding(Encoding::BINARY) # strip away trailing slash if origin_path.start_with?('/') && origin_path != '/' origin_path.chomp!('/') request_uri.chomp!('/') end if %r{^\w+://} =~ origin_path origin_path.chomp!('/') request_uri.insert(0, "#{request.protocol}#{request.host_with_port}") end case pattern when :inclusive !request_uri.match(/^#{Regexp.escape(origin_path)}(\/.*|\?.*)?$/).nil? when :exclusive !request_uri.match(/^#{Regexp.escape(origin_path)}\/?(\?.*)?$/).nil? when :exact request_uri == origin_path when :force true when Regexp !request_uri.match(pattern).nil? when Hash query_params = URI.encode_www_form(pattern) !request_uri.match(/^#{Regexp.escape(origin_path)}\/?(\?.*)?.*?#{query_params}.*$/).nil? else raise ArgumentError, "Unknown `:#{pattern}` match option!" end end
Private Instance Methods
_expand_url(url)
click to toggle source
Expand url in the current context of the view
@api private
# File lib/loaf/view_extensions.rb, line 121 def _expand_url(url) case url when String, Symbol respond_to?(url) ? send(url) : url when Proc url.call(self) else url end end
title_for(name)
click to toggle source
Find title translation for a crumb name
@return [String]
@api private
# File lib/loaf/view_extensions.rb, line 114 def title_for(name) Translation.find_title(name) end