Module: Docks::Helpers::Path
- Defined in:
- lib/docks/helpers/path_helper.rb
Instance Method Summary collapse
- #compiled_script_tags ⇒ Object
- #compiled_style_tags ⇒ Object
- #docks_javascript(script = :main) ⇒ Object
- #docks_path(symbol, options = {}) ⇒ Object
- #docks_stylesheet(stylesheet = :main) ⇒ Object
- #javascript_include_tag(script) ⇒ Object
- #pattern_path(pattern, options = {}) ⇒ Object
- #relative_asset_path(asset) ⇒ Object
- #stylesheet_link_tag(stylesheet) ⇒ Object
Instance Method Details
#compiled_script_tags ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/docks/helpers/path_helper.rb', line 68 def 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 ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/docks/helpers/path_helper.rb', line 59 def 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) ⇒ Object
42 43 44 45 46 |
# 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 = {}) ⇒ 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, = {}) @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, ) @path_cache[postfixed_symbol] = path end @path_cache[postfixed_symbol] end |
#docks_stylesheet(stylesheet = :main) ⇒ Object
36 37 38 39 40 |
# 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) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# 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 = {}) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/docks/helpers/path_helper.rb', line 77 def pattern_path(pattern, = {}) pattern = pattern.name if pattern.kind_of?(Containers::Pattern) file = "index.html" file << "##{options[:anchor]}" if .fetch(:anchor, false) Docks.config.destination + File.join(Docks.config.mount_at, pattern.to_s, file) end |
#relative_asset_path(asset) ⇒ Object
21 22 23 |
# 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) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# 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 |