Sha256: 58ed71ffe07e66a5c23b84545cffce3ba4087463edbf8bbc4290609eda646891

Contents?: true

Size: 1.77 KB

Versions: 4

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

require "pakyow/support/extension"

require "pakyow/assets/external"

module Pakyow
  class Application
    module Behavior
      module Assets
        module Externals
          extend Support::Extension

          def external_script(name, version = nil, package: nil, files: nil)
            assets_config = if is_a?(Plugin)
              parent.config.assets
            else
              config.assets
            end

            assets_config.externals.scripts << Pakyow::Assets::External.new(
              name, version: version, package: package, files: files, config: assets_config
            )
          end

          private def pakyow_js_version
            "^1.0.0"
          end

          apply_extension do
            after "boot", "fetch.assets.externals" do
              if config.assets.externals.pakyow
                external_script :pakyow, pakyow_js_version, package: "@pakyow/js", files: [
                  "dist/pakyow.js",
                  "dist/components/confirmable.js",
                  "dist/components/form.js",
                  "dist/components/freshener.js",
                  "dist/components/navigator.js",
                  "dist/components/socket.js",
                  "dist/components/submittable.js"
                ]
              end

              if config.assets.externals.fetch
                fetched = false

                config.assets.externals.scripts.each do |external_script|
                  unless external_script.exist?
                    external_script.fetch!
                    fetched = true
                  end
                end

                if fetched
                  touch_restart
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pakyow-assets-1.0.6 lib/pakyow/application/behavior/assets/externals.rb
pakyow-assets-1.0.5 lib/pakyow/application/behavior/assets/externals.rb
pakyow-assets-1.0.4 lib/pakyow/application/behavior/assets/externals.rb
pakyow-assets-1.0.3 lib/pakyow/application/behavior/assets/externals.rb