module Jekyll::Minibundle::AssetFileRegistry

Public Class Methods

clear_all() click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
12 def clear_all
13   @_files = {}
14 end
clear_unused() click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
16 def clear_unused
17   @_files
18     .reject { |_, cached| cached.fetch(:is_used) }
19     .each do |asset_destination_path, cached|
20       cached.fetch(:file).cleanup
21       @_files.delete(asset_destination_path)
22     end
23 
24   @_files.each_value do |cached|
25     cached[:is_used] = false
26   end
27 end
register_bundle_file(site, bundle_config) click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
29 def register_bundle_file(site, bundle_config)
30   register_file_for_bundle_block(BundleFile, site, bundle_config) { |file| [file] }
31 end
register_development_file(site, asset_source_path, asset_destination_path) click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
41 def register_development_file(site, asset_source_path, asset_destination_path)
42   register_file_for_stamp_tag(DevelopmentFile, site, asset_source_path, asset_destination_path)
43 end
register_development_file_collection(site, bundle_config) click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
33 def register_development_file_collection(site, bundle_config)
34   register_file_for_bundle_block(DevelopmentFileCollection, site, bundle_config, &:files)
35 end
register_stamp_file(site, asset_source_path, asset_destination_path) click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
37 def register_stamp_file(site, asset_source_path, asset_destination_path)
38   register_file_for_stamp_tag(StampFile, site, asset_source_path, asset_destination_path)
39 end

Private Class Methods

add_as_static_files_to_site(site, files) click to toggle source
    # File lib/jekyll/minibundle/asset_file_registry.rb
131 def add_as_static_files_to_site(site, files)
132   files.each { |file| site.static_files << file }
133 end
register_file_for_bundle_block(file_class, site, bundle_config, &get_files) click to toggle source
   # File lib/jekyll/minibundle/asset_file_registry.rb
47       def register_file_for_bundle_block(file_class, site, bundle_config, &get_files)
48         asset_destination_path = "#{bundle_config.fetch('destination_path')}.#{bundle_config.fetch('type')}"
49 
50         cached = @_files[asset_destination_path]
51 
52         if cached
53           if cached.fetch(:type) != :bundle
54             raise "minibundle block has the same destination path as a ministamp tag: #{asset_destination_path}"
55           end
56 
57           cached_file = cached.fetch(:file)
58           cached_config = cached.fetch(:config)
59           cached_is_used = cached.fetch(:is_used)
60 
61           if bundle_config == cached_config
62             unless cached_is_used
63               cached[:is_used] = true
64               add_as_static_files_to_site(site, get_files.call(cached_file))
65             end
66 
67             return cached_file
68           end
69 
70           if cached_is_used
71             raise <<~MESSAGE
72               Two or more minibundle blocks with the same destination path #{asset_destination_path.inspect}, but having different asset configuration: #{bundle_config.inspect} vs. #{cached_config.inspect}
73             MESSAGE
74           end
75 
76           cached_file.cleanup
77         end
78 
79         new_file = file_class.new(site, bundle_config)
80         @_files[asset_destination_path] = {
81           type:    :bundle,
82           file:    new_file,
83           config:  bundle_config,
84           is_used: true
85         }
86         add_as_static_files_to_site(site, get_files.call(new_file))
87         new_file
88       end
register_file_for_stamp_tag(file_class, site, asset_source_path, asset_destination_path) click to toggle source
    # File lib/jekyll/minibundle/asset_file_registry.rb
 90       def register_file_for_stamp_tag(file_class, site, asset_source_path, asset_destination_path)
 91         cached = @_files[asset_destination_path]
 92 
 93         if cached
 94           if cached.fetch(:type) != :stamp
 95             raise "ministamp tag has the same destination path as a minibundle block: #{asset_destination_path}"
 96           end
 97 
 98           cached_file = cached.fetch(:file)
 99           cached_config = cached.fetch(:config)
100           cached_is_used = cached.fetch(:is_used)
101 
102           if asset_source_path == cached_config
103             unless cached_is_used
104               cached[:is_used] = true
105               add_as_static_files_to_site(site, [cached_file])
106             end
107 
108             return cached_file
109           end
110 
111           if cached_is_used
112             raise <<~MESSAGE
113               Two or more ministamp tags with the same destination path #{asset_destination_path.inspect}, but different asset source paths: #{asset_source_path.inspect} vs. #{cached_config.inspect}
114             MESSAGE
115           end
116 
117           cached_file.cleanup
118         end
119 
120         new_file = file_class.new(site, asset_source_path, asset_destination_path)
121         @_files[asset_destination_path] = {
122           type:    :stamp,
123           file:    new_file,
124           config:  asset_source_path,
125           is_used: true
126         }
127         add_as_static_files_to_site(site, [new_file])
128         new_file
129       end