module Pakyow::Application::Behavior::Assets::Packs
Public Instance Methods
packs(view)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 53 def packs(view) (autoloaded_packs + view_packs(view) + component_packs(view)).uniq.each_with_object([]) { |pack_name, packs| if found_pack = state(:pack).find { |pack| pack.name == pack_name.to_sym } packs << found_pack end } end
Private Instance Methods
accessible_pack_path(pack_path)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 63 def accessible_pack_path(pack_path) pack_path_parts = pack_path.split("/") pack_path_parts[-1] = if pack_path_parts[-1].include?("__") pack_path_parts[-1].split("__", 2)[1] elsif pack_path_parts[-1].include?("@") pack_path_parts[-1].split("@", 2)[0] else pack_path_parts[-1] end pack_path_parts.join("/") end
autoloaded_packs()
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 76 def autoloaded_packs config.assets.packs.autoload end
build_layout_packs(template_store)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 92 def build_layout_packs(template_store) template_store.layouts.each do |layout_name, layout| layout_pack = Pakyow::Assets::Pack.new(:"layouts/#{layout_name}", config.assets) register_pack_with_view(layout_pack, layout) Pathname.glob(File.join(template_store.layouts_path, "#{layout_name}.*")) do |potential_asset_path| next if template_store.template?(potential_asset_path) layout_pack << Pakyow::Assets::Asset.new_from_path( potential_asset_path, config: config.assets, related: state(:asset) ) end self.pack << layout_pack.finalize end end
build_page_packs(template_store)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 110 def build_page_packs(template_store) template_store.paths.each do |view_path| template_info = template_store.info(view_path) page_pack = Pakyow::Assets::Pack.new(:"#{template_info[:page].logical_path[1..-1]}", config.assets) register_pack_with_view(page_pack, template_info[:page]) # Find all partials used by the page. # partials = template_info[:page].container_views.each_with_object([]) { |page_container, page_container_partials| page_container_partials.concat(page_container.find_partials(template_info[:partials])) } + template_info[:layout].find_partials(template_info[:partials]) # Include assets for partials used by the page into the page pack. # partials.each do |partial_name| if partial = template_info[:partials][partial_name] Pathname.glob(File.join(config.presenter.path, "#{partial.logical_path}.*")) do |potential_asset_path| next if template_store.template?(potential_asset_path) page_pack << Pakyow::Assets::Asset.new_from_path( potential_asset_path, config: config.assets, related: state(:asset) ) end end end # Include assets defined for the page itself. # Pathname.glob(File.join(template_info[:page].path.dirname, "#{template_info[:page].path.basename(template_info[:page].path.extname)}.*")) do |potential_asset_path| next if template_store.template?(potential_asset_path) page_pack << Pakyow::Assets::Asset.new_from_path( potential_asset_path, config: config.assets, related: state(:asset) ) end self.pack << page_pack.finalize end end
component_packs(view)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 84 def component_packs(view) view.object.each_significant_node(:component, descend: true).flat_map { |node| node.label(:components).map { |component| component[:name] } } end
register_pack_with_view(pack, view)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 153 def register_pack_with_view(pack, view) unless view.info(:packs) view.add_info(packs: []) end view.info(:packs) << pack.name end
view_packs(view)
click to toggle source
# File lib/pakyow/application/behavior/assets/packs.rb, line 80 def view_packs(view) view.info(:packs).to_a end