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 27 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 10 def initialize(config) @type = config.fetch(:type) @asset_paths = config.fetch(:asset_paths) @destination_path = config.fetch(:destination_path) @site_dir = config.fetch(:site_dir) @minifier_cmd = config.fetch(:minifier_cmd) unless @minifier_cmd raise <<-END Missing minification command for bundling #{bundle_destination_path.inspect}. 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 @tempfile = Tempfile.new([TEMPFILE_PREFIX, ".#{@type}"]) end |
Instance Method Details
#close ⇒ Object
29 30 31 32 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 29 def close @tempfile.close! @tempfile = nil end |
#make_bundle ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 39 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 #{bundle_destination_path}:") @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 #{bundle_destination_path.inspect} failed with exit status #{exit_status}, command: #{@minifier_cmd.inspect}" log_minifier_error(msg) raise msg end self end |
#path ⇒ Object
34 35 36 37 |
# File 'lib/jekyll/minibundle/asset_bundle.rb', line 34 def path raise IllegalStateError, 'Cannot get path of closed AssetBundle' unless @tempfile @tempfile.path end |