Method: Docks::Helpers::Path#docks_path

Defined in:
lib/docks/helpers/path_helper.rb

#docks_path(symbol, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/docks/helpers/path_helper.rb', line 4

def docks_path(symbol, options = {})
  @path_cache ||= {}

  postfixed_symbol = "#{symbol}#{"-#{options[:language]}" if options.fetch(:language, false)}"
  return @path_cache[postfixed_symbol] unless @path_cache[postfixed_symbol].nil?

  if search_result = @pattern.find(symbol)
    @path_cache[postfixed_symbol] = "##{search_result.symbol_id}"
  elsif search_result = @pattern_library.find(symbol)
    @path_cache[postfixed_symbol] = relative_pattern_path(search_result.pattern.name, anchor: search_result.symbol.nil? ? nil : search_result.symbol.symbol_id)
  elsif path = Docks::SymbolSources.path_for(symbol, options)
    @path_cache[postfixed_symbol] = path
  end

  @path_cache[postfixed_symbol]
end