Class: Jekyll::Assets::Env
- Inherits:
-
Sprockets::Environment
- Object
- Sprockets::Environment
- Jekyll::Assets::Env
- Extended by:
- Forwardable::Extended
- Includes:
- Utils
- Defined in:
- lib/jekyll/assets/env.rb
Instance Attribute Summary collapse
-
#asset_config ⇒ Object
readonly
Returns the value of attribute asset_config.
-
#assets_to_write ⇒ Object
Returns the value of attribute assets_to_write.
-
#jekyll ⇒ Object
readonly
Returns the value of attribute jekyll.
-
#manifest ⇒ Object
readonly
–.
Instance Method Summary collapse
-
#cache ⇒ Sprockets::Cache
– Create a cache, or a null cache (if no caching) for caching.
-
#find_asset(v, *a) ⇒ Object
–.
-
#find_asset!(v, *a) ⇒ Object
–.
-
#initialize(jekyll = nil) ⇒ Env
constructor
–.
-
#remove_old_assets ⇒ Object
—.
-
#skip_gzip? ⇒ Boolean
–.
-
#to_liquid_payload ⇒ Hash
– Takes all user assets and turns them into a drop.
-
#write_all ⇒ Object
–.
Methods included from Utils
activate, #external?, #external_asset, #find_assets_by_glob, #glob_paths, html, html_fragment, #in_cache_dir, #in_dest_dir, javascript?, make_https, manifest_files, new_uglifier?, old_sprockets?, #parse_liquid, #prefix_url, #raw_precompiles, #strip_paths, strip_secondary_content_type, strip_slashes, #url_asset, xml
Constructor Details
#initialize(jekyll = nil) ⇒ Env
–
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jekyll/assets/env.rb', line 39 def initialize(jekyll = nil) @asset_config = Config.new(jekyll.config["assets"] ||= {}) Hook.trigger :env, :before_init do |h| instance_eval(&h) end super() @jekyll = jekyll @assets_to_write = [] @manifest = Manifest.new(self, in_dest_dir) @jekyll.sprockets = self @total_time = 0.000000 @logger = Logger @cache = nil setup_sources! setup_resolver! ignore_caches! setup_drops! precompile! copy_raw! Hook.trigger :env, :after_init do |h| instance_eval(&h) end end |
Instance Attribute Details
#asset_config ⇒ Object (readonly)
Returns the value of attribute asset_config.
35 36 37 |
# File 'lib/jekyll/assets/env.rb', line 35 def asset_config @asset_config end |
#assets_to_write ⇒ Object
Returns the value of attribute assets_to_write.
34 35 36 |
# File 'lib/jekyll/assets/env.rb', line 34 def assets_to_write @assets_to_write end |
#jekyll ⇒ Object (readonly)
Returns the value of attribute jekyll.
36 37 38 |
# File 'lib/jekyll/assets/env.rb', line 36 def jekyll @jekyll end |
#manifest ⇒ Object (readonly)
–
33 34 35 |
# File 'lib/jekyll/assets/env.rb', line 33 def manifest @manifest end |
Instance Method Details
#cache ⇒ Sprockets::Cache
this is configurable with :caching -> :type
this is configurable with :caching -> :enabled
– Create a cache, or a null cache (if no caching) for caching. –
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/jekyll/assets/env.rb', line 101 def cache @cache ||= begin type = asset_config[:caching][:type] enbl = asset_config[:caching][:enabled] path = in_cache_dir out = Sprockets::Cache::MemoryStore.new if enbl && type == "memory" out = Sprockets::Cache::FileStore.new(path) if enbl && type == "file" out = Sprockets::Cache::NullStore.new unless enbl out = Sprockets::Cache.new(out, Logger) clear_cache(out) out end end |
#find_asset(v, *a) ⇒ Object
–
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/jekyll/assets/env.rb', line 72 def find_asset(v, *a) msg = "Searched for, and rendered #{v} in %<time>s" out = Logger.with_timed_logging msg do super(v, *a) end # We keep track. @total_time += out[:time] out[:result] end |
#find_asset!(v, *a) ⇒ Object
–
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/jekyll/assets/env.rb', line 84 def find_asset!(v, *a) msg = "Searched for, and rendered #{v} in %<time>s" out = Logger.with_timed_logging msg do super(v, *a) end # We keep track. @total_time += out[:time] out[:result] end |
#remove_old_assets ⇒ Object
150 151 152 153 154 |
# File 'lib/jekyll/assets/env.rb', line 150 def remove_old_assets assets_to_write.each do |v| in_dest_dir(find_asset!(v).logical_path).rm_f end end |
#skip_gzip? ⇒ Boolean
–
67 68 69 |
# File 'lib/jekyll/assets/env.rb', line 67 def skip_gzip? !asset_config[:gzip] end |
#to_liquid_payload ⇒ Hash
this does not find the asset.
– Takes all user assets and turns them into a drop. –
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/jekyll/assets/env.rb', line 121 def to_liquid_payload each_file.each_with_object({}) do |k, h| skip, path = false, Pathutil.new(strip_paths(k)) path.descend do |p| skip = p.start_with?("_") if skip break end end next if skip h.update({ path.to_s => Drop.new(path, { jekyll: jekyll, }), }) end end |
#write_all ⇒ Object
–
141 142 143 144 145 146 147 |
# File 'lib/jekyll/assets/env.rb', line 141 def write_all remove_old_assets unless asset_config[:digest] manifest.compile(*assets_to_write); @asset_to_write = [] Hook.trigger(:env, :after_write) { |h| instance_eval(&h) } Logger.debug "took #{format(@total_time.round(2).to_s, '%.2f')}s" end |