Sha256: a032815232a66f4cc1e5ed804cfefc4d446faf7401d4fc06c4d5c86e5e175850

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

module Pakyow
  module Presenter
    class Renderer
      module Behavior
        module Assets
          module InstallAssets
            extend Support::Extension

            apply_extension do
              build do |view, app:|
                if head = view.head
                  packs = app.packs(view)

                  if app.is_a?(Plugin)
                    packs = app.parent.packs(view).concat(packs)
                  end

                  packs.uniq { |pack|
                    pack.public_path
                  }.each do |pack|
                    if pack.javascripts?
                      head.object.append_html("<script src=\"#{File.join(app.config.assets.host, pack.public_path)}.js\"></script>\n")
                    end

                    if pack.stylesheets?
                      head.object.append_html("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"#{File.join(app.config.assets.host, pack.public_path)}.css\">\n")
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pakyow-assets-1.0.1 lib/pakyow/presenter/renderer/behavior/assets/install_assets.rb
pakyow-assets-1.0.0 lib/pakyow/presenter/renderer/behavior/assets/install_assets.rb