Class: Jekyll::Minibundle::AssetBundle
- Inherits:
-
Object
- Object
- Jekyll::Minibundle::AssetBundle
- Defined in:
- lib/jekyll/minibundle/asset_bundle.rb
Constant Summary collapse
- TEMPFILE_PREFIX =
'jekyll-minibundle-'.freeze
Instance Method Summary collapse
- #close ⇒ Object
-
#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.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 10 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 raise "Missing minification command for bundling \#{@type} assets. Specify it in\n1) minibundle.minifier_commands.\#{@type} setting in _config.yml,\n2) $JEKYLL_MINIBUNDLE_CMD_\#{@type.to_s.upcase} environment variable, or\n3) minifier_cmd setting inside minibundle block.\n" end @tempfile = Tempfile.new([TEMPFILE_PREFIX, ".#{@type}"]) end |
Instance Method Details
#close ⇒ Object
28 29 30 31 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 28 def close @tempfile.close! @tempfile = nil end |
#make_bundle ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 38 def make_bundle raise IllegalStateError, 'Cannot make bundle with closed AssetBundle' unless @tempfile exit_status = spawn_minifier(@minifier_cmd) do |input| $stdout.puts # place newline after "(Re)generating..." log messages Log.info("Bundling #{@type} assets:") @asset_paths.each do |asset| Log.info(relative_path_from(asset, @site_dir)) IO.foreach(asset) { |line| input.write(line) } input.puts(';') if @type == :js end end if exit_status != 0 msg = "Bundling #{@type} assets failed with exit status #{exit_status}, command: '#{@minifier_cmd}'" log_minifier_error(msg) raise msg end self end |
#path ⇒ Object
33 34 35 36 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 33 def path raise IllegalStateError, 'Cannot get path of closed AssetBundle' unless @tempfile @tempfile.path end |