Class: Jekyll::Minibundle::AssetBundle
- Inherits:
-
Object
- Object
- Jekyll::Minibundle::AssetBundle
- Defined in:
- lib/jekyll/minibundle/asset_bundle.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ AssetBundle
constructor
A new instance of AssetBundle.
- #make_bundle ⇒ Object
- #path ⇒ Object
Constructor Details
#initialize(config) ⇒ AssetBundle
Returns a new instance of AssetBundle.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 6 def initialize(config) @type = config.fetch(:type) @asset_paths = config.fetch(:asset_paths) @site_dir = config.fetch(:site_dir) @minifier_cmd = config.fetch(:minifier_cmd) unless @minifier_cmd fail <<-END Missing minification command for bundling #{@type} assets. Specify it in 1) minibundle.minifier_commands.#{@type} setting in _config.yml, 2) $JEKYLL_MINIBUNDLE_CMD_#{@type.to_s.upcase} environment variable, or 3) minifier_cmd setting inside minibundle block. END end @temp_file = Tempfile.new(["jekyll-minibundle-", ".#{@type}"]) at_exit { @temp_file.close! } end |
Instance Method Details
#make_bundle ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 29 def make_bundle exit_status = spawn_minifier(@minifier_cmd) do |input| $stdout.puts # place newline after "(Re)generating..." log messages Compatibility.log_info("Bundling #{@type} assets:") @asset_paths.each do |asset| Compatibility.log_info(relative_path_from(asset, @site_dir)) IO.foreach(asset) { |line| input.write(line) } input.puts(';') if @type == :js end end fail "Bundling #{@type} assets failed with exit status #{exit_status}, command: #{@minifier_cmd}" if exit_status != 0 self end |
#path ⇒ Object
25 26 27 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 25 def path @temp_file.path end |