jekyll-asset-pipeline 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,8 +10,6 @@ require 'jekyll'
10
10
  require 'liquid'
11
11
 
12
12
  # Jekyll extensions
13
- require 'jekyll_asset_pipeline/extensions/jekyll/static_file_extensions'
14
- require 'jekyll_asset_pipeline/extensions/jekyll/static_asset_file'
15
13
  require 'jekyll_asset_pipeline/extensions/jekyll/site_extensions'
16
14
  require 'jekyll_asset_pipeline/extensions/jekyll/site'
17
15
 
@@ -37,11 +35,20 @@ require 'jekyll_asset_pipeline/pipeline'
37
35
  module JekyllAssetPipeline
38
36
  # Default configuration settings for Jekyll Asset Pipeline
39
37
  # Strings used for keys to play nice when merging with _config.yml
38
+ #
39
+ # 'output_path' Destination for bundle file (within the '_site' directory)
40
+ # 'display_path' Optional. Override path to assets for output HTML refs
41
+ # 'staging_path' Destination for staged assets (within project root directory)
42
+ # 'bundle' true = Bundle assets, false = Leave assets unbundled
43
+ # 'compress' true = Minify assets, false = Leave assets unminified
44
+ # 'gzip' true = Create gzip versions, false = Do not create gzip versions
45
+ #
40
46
  DEFAULTS = {
41
- 'output_path' => 'assets', # Destination for bundle file (within the '_site' directory)
42
- 'display_path' => nil, # Optional. Override path to assets for output HTML refs
43
- 'bundle' => true, # true = Bundle assets, false = Leave assets unbundled
44
- 'compress' => true, # true = Minify assets, false = Leave assets unminified
45
- 'gzip' => false # true = Create gzip versions, false = Do not create gzip versions
47
+ 'output_path' => 'assets',
48
+ 'display_path' => nil,
49
+ 'staging_path' => '.asset_pipeline',
50
+ 'bundle' => true,
51
+ 'compress' => true,
52
+ 'gzip' => false
46
53
  }
47
54
  end
@@ -15,6 +15,21 @@ module JekyllAssetPipeline
15
15
 
16
16
  original_return_val
17
17
  end
18
+
19
+ # Store the original Jekyll::Site#write method
20
+ old_write_method = instance_method(:write)
21
+
22
+ # Override Jekyll::Site#write
23
+ define_method(:write) do
24
+ # Run the Jekyll::Site#write method
25
+ original_return_value = old_write_method.bind(self).call()
26
+
27
+ # Clear Jekyll Asset Pipeline staged assets
28
+ config = self.config['asset_pipeline'] || {}
29
+ Pipeline.remove_staged_assets(self.source, config)
30
+
31
+ original_return_value
32
+ end
18
33
  end
19
34
  end
20
35
  end
@@ -21,7 +21,8 @@ module JekyllAssetPipeline
21
21
  if pipeline.is_a?(Pipeline)
22
22
  # Prevent Jekyll from cleaning up saved assets if new pipeline
23
23
  pipeline.assets.each do |asset|
24
- site.static_files << StaticAssetFile.new(site, site.dest,
24
+ config = JekyllAssetPipeline::DEFAULTS.merge(config)
25
+ site.static_files << Jekyll::StaticFile.new(site, config['staging_path'],
25
26
  asset.output_path, asset.filename)
26
27
  end unless cached
27
28
 
@@ -58,6 +58,20 @@ module JekyllAssetPipeline
58
58
  @cache = {}
59
59
  end
60
60
 
61
+ # Remove staged assets
62
+ def remove_staged_assets(source, config)
63
+ begin
64
+ config = DEFAULTS.merge(config)
65
+ staging_path = File.join(source, config['staging_path'])
66
+ FileUtils.rm_rf(staging_path)
67
+ rescue Exception => e
68
+ puts "Failed to remove staged assets."
69
+
70
+ # Re-raise the exception
71
+ raise e
72
+ end
73
+ end
74
+
61
75
  # Add prefix to output
62
76
  def puts(message)
63
77
  $stdout.puts("Asset Pipeline: #{message}")
@@ -179,10 +193,10 @@ module JekyllAssetPipeline
179
193
  # Save assets to file
180
194
  def save
181
195
  output_path = @options['output_path']
196
+ staging_path = @options['staging_path']
182
197
 
183
198
  @assets.each do |asset|
184
- # Create directories if necessary
185
- directory = File.join(@destination, output_path)
199
+ directory = File.join(@source, staging_path, output_path)
186
200
  FileUtils::mkpath(directory) unless File.directory?(directory)
187
201
 
188
202
  begin
@@ -1,3 +1,3 @@
1
1
  module JekyllAssetPipeline
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-asset-pipeline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -88,8 +88,6 @@ files:
88
88
  - lib/jekyll_asset_pipeline/converter.rb
89
89
  - lib/jekyll_asset_pipeline/extensions/jekyll/site.rb
90
90
  - lib/jekyll_asset_pipeline/extensions/jekyll/site_extensions.rb
91
- - lib/jekyll_asset_pipeline/extensions/jekyll/static_asset_file.rb
92
- - lib/jekyll_asset_pipeline/extensions/jekyll/static_file_extensions.rb
93
91
  - lib/jekyll_asset_pipeline/extensions/liquid/asset_tag.rb
94
92
  - lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/css_asset_tag.rb
95
93
  - lib/jekyll_asset_pipeline/extensions/liquid/asset_tags/javascript_asset_tag.rb
@@ -1,5 +0,0 @@
1
- module JekyllAssetPipeline
2
- class StaticAssetFile < ::Jekyll::StaticFile
3
- include JekyllAssetPipeline::JekyllStaticFileExtensions
4
- end
5
- end
@@ -1,8 +0,0 @@
1
- module JekyllAssetPipeline
2
- module JekyllStaticFileExtensions
3
- # Override #write method since the asset file is dynamically created
4
- def write(dest)
5
- true
6
- end
7
- end
8
- end