module Docks::Helpers::Path

Public Instance Methods

compiled_script_tags() click to toggle source
# File lib/docks/helpers/path_helper.rb, line 68
def compiled_script_tags
  content = Array(Docks.config.compiled_assets)
    .select { |asset| Docks::Languages.language_for(asset).kind_of?(Docks::Languages::JavaScript) }
    .map { |asset| javascript_include_tag(asset) }
    .join("\n")

  content.strip.empty? ? nil : content
end
compiled_style_tags() click to toggle source
# File lib/docks/helpers/path_helper.rb, line 59
def compiled_style_tags
  content = Array(Docks.config.compiled_assets)
    .select { |asset| Docks::Languages.language_for(asset).kind_of?(Docks::Languages::CSS) }
    .map { |asset| stylesheet_link_tag(asset) }
    .join("\n")

  content.strip.empty? ? nil : content
end
docks_javascript(script = :main) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 42
def docks_javascript(script = :main)
  return unless Docks.config.has_theme?
  postfix = (script.to_sym == :main ? "" : "_#{script.to_s}")
  javascript_include_tag("docks#{postfix}.js")
end
docks_path(symbol, options = {}) click to toggle source
# 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
docks_stylesheet(stylesheet = :main) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 36
def docks_stylesheet(stylesheet = :main)
  return unless Docks.config.has_theme?
  postfix = (stylesheet.to_sym == :main ? "" : "-#{stylesheet.to_s}")
  stylesheet_link_tag("docks#{postfix}.css")
end
javascript_include_tag(script) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 48
def javascript_include_tag(script)
  pathname = Pathname.new(script)
  path = if pathname.absolute?
    pathname.to_path
  else
    relative_asset_path(File.join(Docks.config.asset_folders.scripts, "#{pathname.extname.length > 0 ? script.sub(/#{pathname.extname}$/, "") : script}.js"))
  end

  "<script src='#{path}'></script>"
end
pattern_path(pattern, options = {}) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 77
def pattern_path(pattern, options = {})
  pattern = pattern.name if pattern.kind_of?(Containers::Pattern)

  file = "index.html"
  file << "##{options[:anchor]}" if options.fetch(:anchor, false)

  Docks.config.destination + File.join(Docks.config.mount_at, pattern.to_s, file)
end
relative_asset_path(asset) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 21
def relative_asset_path(asset)
  (Docks.config.destination + asset).relative_path_from(Docks.current_render_destination)
end

Private Instance Methods

relative_pattern_path(pattern, options = {}) click to toggle source
# File lib/docks/helpers/path_helper.rb, line 88
def relative_pattern_path(pattern, options = {})
  path = relative_asset_path(pattern_path(pattern, options)).to_s
  path
end