module Docks::Helpers::Path
Public Instance Methods
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
stylesheet_link_tag(stylesheet)
click to toggle source
# File lib/docks/helpers/path_helper.rb, line 25 def stylesheet_link_tag(stylesheet) pathname = Pathname.new(stylesheet) path = if pathname.absolute? pathname.to_path else relative_asset_path(File.join(Docks.config.asset_folders.styles, "#{pathname.extname.length > 0 ? stylesheet.sub(/#{pathname.extname}$/, "") : stylesheet}.css")) end "<link rel='stylesheet' type='text/css' href='#{path}'>" 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