pakyow-assets 1.0.0.rc5 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/lib/pakyow/application/actions/assets/process.rb +65 -0
  4. data/lib/pakyow/application/actions/assets/public.rb +77 -0
  5. data/lib/pakyow/{assets → application}/behavior/assets.rb +2 -2
  6. data/lib/pakyow/application/behavior/assets/externals.rb +61 -0
  7. data/lib/pakyow/application/behavior/assets/packs.rb +164 -0
  8. data/lib/pakyow/application/behavior/assets/prelaunching.rb +21 -0
  9. data/lib/pakyow/application/behavior/assets/processing.rb +29 -0
  10. data/lib/pakyow/application/behavior/assets/silencing.rb +37 -0
  11. data/lib/pakyow/application/behavior/assets/watching.rb +27 -0
  12. data/lib/pakyow/{assets/behavior/config.rb → application/config/assets.rb} +3 -3
  13. data/lib/pakyow/assets.rb +3 -3
  14. data/lib/pakyow/assets/framework.rb +20 -20
  15. data/lib/pakyow/presenter/renderer/behavior/assets/install_assets.rb +41 -0
  16. data/lib/pakyow/{assets/tasks → tasks/assets}/precompile.rake +0 -0
  17. data/lib/pakyow/{assets/tasks → tasks/assets}/update.rake +0 -0
  18. metadata +28 -27
  19. data/lib/pakyow/actions/assets/process.rb +0 -63
  20. data/lib/pakyow/actions/assets/public.rb +0 -75
  21. data/lib/pakyow/assets/behavior/externals.rb +0 -59
  22. data/lib/pakyow/assets/behavior/packs.rb +0 -162
  23. data/lib/pakyow/assets/behavior/prelaunching.rb +0 -19
  24. data/lib/pakyow/assets/behavior/processing.rb +0 -27
  25. data/lib/pakyow/assets/behavior/rendering/install_assets.rb +0 -39
  26. data/lib/pakyow/assets/behavior/silencing.rb +0 -35
  27. data/lib/pakyow/assets/behavior/watching.rb +0 -25
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- require "pakyow/assets/external"
6
-
7
- module Pakyow
8
- module Assets
9
- module Behavior
10
- module Externals
11
- extend Support::Extension
12
-
13
- def external_script(name, version = nil, package: nil, files: nil)
14
- assets_config = if is_a?(Plugin)
15
- parent.config.assets
16
- else
17
- config.assets
18
- end
19
-
20
- assets_config.externals.scripts << External.new(
21
- name, version: version, package: package, files: files, config: assets_config
22
- )
23
- end
24
-
25
- apply_extension do
26
- after "boot", "fetch.assets.externals" do
27
- if config.assets.externals.pakyow
28
- external_script :pakyow, "^1.0.0-rc.2", package: "@pakyow/js", files: [
29
- "dist/pakyow.js",
30
- "dist/components/confirmable.js",
31
- "dist/components/form.js",
32
- "dist/components/freshener.js",
33
- "dist/components/navigator.js",
34
- "dist/components/socket.js",
35
- "dist/components/submittable.js"
36
- ]
37
- end
38
-
39
- if config.assets.externals.fetch
40
- fetched = false
41
-
42
- config.assets.externals.scripts.each do |external_script|
43
- unless external_script.exist?
44
- external_script.fetch!
45
- fetched = true
46
- end
47
- end
48
-
49
- if fetched
50
- FileUtils.mkdir_p "./tmp"
51
- FileUtils.touch "./tmp/restart.txt"
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,162 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- module Packs
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- after "initialize", "initialize.assets.packs", priority: :high do
13
- config.assets.packs.paths.each do |packs_path|
14
- Pathname.glob(File.join(packs_path, "*.*")).group_by { |path|
15
- File.join(File.dirname(path), File.basename(path, File.extname(path)))
16
- }.to_a.sort { |pack_a, pack_b|
17
- pack_b[1] <=> pack_a[1]
18
- }.uniq { |pack_path, _|
19
- accessible_pack_path(pack_path)
20
- }.map { |pack_path, pack_asset_paths|
21
- [accessible_pack_path(pack_path), pack_asset_paths]
22
- }.reverse.each do |pack_path, pack_asset_paths|
23
- prefix = if is_a?(Plugin)
24
- self.class.mount_path
25
- else
26
- "/"
27
- end
28
-
29
- asset_pack = Pack.new(File.basename(pack_path).to_sym, config.assets, prefix: prefix)
30
-
31
- pack_asset_paths.each do |pack_asset_path|
32
- if config.assets.extensions.include?(File.extname(pack_asset_path))
33
- asset_pack << Asset.new_from_path(
34
- pack_asset_path,
35
- config: config.assets,
36
- related: state(:asset)
37
- )
38
- end
39
- end
40
-
41
- self.pack << asset_pack.finalize
42
- end
43
- end
44
-
45
- state(:templates).each do |template_store|
46
- build_layout_packs(template_store)
47
- build_page_packs(template_store)
48
- end
49
- end
50
- end
51
-
52
- def packs(view)
53
- (autoloaded_packs + view_packs(view) + component_packs(view)).uniq.each_with_object([]) { |pack_name, packs|
54
- if found_pack = state(:pack).find { |pack| pack.name == pack_name.to_sym }
55
- packs << found_pack
56
- end
57
- }
58
- end
59
-
60
- private
61
-
62
- def accessible_pack_path(pack_path)
63
- pack_path_parts = pack_path.split("/")
64
- pack_path_parts[-1] = if pack_path_parts[-1].include?("__")
65
- pack_path_parts[-1].split("__", 2)[1]
66
- elsif pack_path_parts[-1].include?("@")
67
- pack_path_parts[-1].split("@", 2)[0]
68
- else
69
- pack_path_parts[-1]
70
- end
71
-
72
- pack_path_parts.join("/")
73
- end
74
-
75
- def autoloaded_packs
76
- config.assets.packs.autoload
77
- end
78
-
79
- def view_packs(view)
80
- view.info(:packs).to_a
81
- end
82
-
83
- def component_packs(view)
84
- view.object.each_significant_node(:component, descend: true).flat_map { |node|
85
- node.label(:components).map { |component|
86
- component[:name]
87
- }
88
- }
89
- end
90
-
91
- def build_layout_packs(template_store)
92
- template_store.layouts.each do |layout_name, layout|
93
- layout_pack = Pack.new(:"layouts/#{layout_name}", config.assets)
94
- register_pack_with_view(layout_pack, layout)
95
-
96
- Pathname.glob(File.join(template_store.layouts_path, "#{layout_name}.*")) do |potential_asset_path|
97
- next if template_store.template?(potential_asset_path)
98
- layout_pack << Asset.new_from_path(
99
- potential_asset_path,
100
- config: config.assets,
101
- related: state(:asset)
102
- )
103
- end
104
-
105
- self.pack << layout_pack.finalize
106
- end
107
- end
108
-
109
- def build_page_packs(template_store)
110
- template_store.paths.each do |view_path|
111
- template_info = template_store.info(view_path)
112
-
113
- page_pack = Pack.new(:"#{template_info[:page].logical_path[1..-1]}", config.assets)
114
- register_pack_with_view(page_pack, template_info[:page])
115
-
116
- # Find all partials used by the page.
117
- #
118
- partials = template_info[:page].container_views.each_with_object([]) { |page_container, page_container_partials|
119
- page_container_partials.concat(page_container.find_partials(template_info[:partials]))
120
- } + template_info[:layout].find_partials(template_info[:partials])
121
-
122
- # Include assets for partials used by the page into the page pack.
123
- #
124
- partials.each do |partial_name|
125
- if partial = template_info[:partials][partial_name]
126
- Pathname.glob(File.join(config.presenter.path, "#{partial.logical_path}.*")) do |potential_asset_path|
127
- next if template_store.template?(potential_asset_path)
128
- page_pack << Asset.new_from_path(
129
- potential_asset_path,
130
- config: config.assets,
131
- related: state(:asset)
132
- )
133
- end
134
- end
135
- end
136
-
137
- # Include assets defined for the page itself.
138
- #
139
- Pathname.glob(File.join(template_info[:page].path.dirname, "#{template_info[:page].path.basename(template_info[:page].path.extname)}.*")) do |potential_asset_path|
140
- next if template_store.template?(potential_asset_path)
141
- page_pack << Asset.new_from_path(
142
- potential_asset_path,
143
- config: config.assets,
144
- related: state(:asset)
145
- )
146
- end
147
-
148
- self.pack << page_pack.finalize
149
- end
150
- end
151
-
152
- def register_pack_with_view(pack, view)
153
- unless view.info(:packs)
154
- view.add_info(packs: [])
155
- end
156
-
157
- view.info(:packs) << pack.name
158
- end
159
- end
160
- end
161
- end
162
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- module Prelaunching
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- on "configure" do
13
- config.tasks.prelaunch << "assets:precompile"
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- module Processing
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- on "load" do
13
- if self.class.includes_framework?(:presenter)
14
- self.class.processor :html do |content|
15
- state(:asset).each do |asset|
16
- content.gsub!(asset.logical_path, File.join(config.assets.host, asset.public_path))
17
- end
18
-
19
- content
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- module Rendering
9
- module InstallAssets
10
- extend Support::Extension
11
-
12
- apply_extension do
13
- build do |view, app:|
14
- if head = view.head
15
- packs = app.packs(view)
16
-
17
- if app.is_a?(Plugin)
18
- packs = app.parent.packs(view).concat(packs)
19
- end
20
-
21
- packs.uniq { |pack|
22
- pack.public_path
23
- }.each do |pack|
24
- if pack.javascripts?
25
- head.object.append_html("<script src=\"#{File.join(app.config.assets.host, pack.public_path)}.js\"></script>\n")
26
- end
27
-
28
- if pack.stylesheets?
29
- head.object.append_html("<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"#{File.join(app.config.assets.host, pack.public_path)}.css\">\n")
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- # Silences asset requests from being logged.
9
- #
10
- module Silencing
11
- extend Support::Extension
12
-
13
- apply_extension do
14
- on "load" do
15
- if config.assets.silent
16
- # silence asset requests
17
- Pakyow.silence do |connection|
18
- # TODO: do we need the second check?
19
- connection.path.start_with?(config.assets.prefix) || self.class.asset.instances.any? { |asset|
20
- asset.logical_path == connection.path
21
- }
22
- end
23
-
24
- # silence requests to public files
25
- Pakyow.silence do |connection|
26
- # TODO: really need an in-memory directory for these files
27
- File.file?(File.join(config.assets.public_path, connection.path))
28
- end
29
- end
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pakyow/support/extension"
4
-
5
- module Pakyow
6
- module Assets
7
- module Behavior
8
- module Watching
9
- extend Support::Extension
10
-
11
- apply_extension do
12
- after "configure" do
13
- config.assets.extensions.each do |extension|
14
- config.process.watched_paths << File.join(config.presenter.path, "**/*#{extension}")
15
-
16
- # Exclude vendored assets.
17
- #
18
- config.process.excluded_paths << File.join(config.assets.externals.path, "*#{extension}")
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end