jekyll-asset-pipeline 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jekyll_asset_pipeline.rb +0 -1
- data/lib/jekyll_asset_pipeline/compressor.rb +1 -6
- data/lib/jekyll_asset_pipeline/converter.rb +1 -6
- data/lib/jekyll_asset_pipeline/extensions/jekyll/site_extensions.rb +1 -1
- data/lib/jekyll_asset_pipeline/extensions/liquid/liquid_block_extensions.rb +12 -29
- data/lib/jekyll_asset_pipeline/pipeline.rb +69 -16
- data/lib/jekyll_asset_pipeline/version.rb +1 -1
- metadata +16 -17
- data/lib/jekyll_asset_pipeline/cache.rb +0 -21
@@ -32,7 +32,6 @@ require 'jekyll_asset_pipeline/compressor'
|
|
32
32
|
require 'jekyll_asset_pipeline/template'
|
33
33
|
require 'jekyll_asset_pipeline/templates/javascript_tag_template'
|
34
34
|
require 'jekyll_asset_pipeline/templates/css_tag_template'
|
35
|
-
require 'jekyll_asset_pipeline/cache'
|
36
35
|
require 'jekyll_asset_pipeline/pipeline'
|
37
36
|
|
38
37
|
module JekyllAssetPipeline
|
@@ -4,12 +4,7 @@ module JekyllAssetPipeline
|
|
4
4
|
|
5
5
|
def initialize(content)
|
6
6
|
@content = content
|
7
|
-
|
8
|
-
@compressed = self.compress
|
9
|
-
rescue Exception => e
|
10
|
-
puts "Failed to compress asset with '#{self.class.to_s}'."
|
11
|
-
raise e
|
12
|
-
end
|
7
|
+
@compressed = self.compress
|
13
8
|
end
|
14
9
|
|
15
10
|
# Returns compressed content
|
@@ -5,12 +5,7 @@ module JekyllAssetPipeline
|
|
5
5
|
def initialize(asset)
|
6
6
|
@content = asset.content
|
7
7
|
@type = File.extname(asset.filename).downcase
|
8
|
-
|
9
|
-
@converted = self.convert
|
10
|
-
rescue Exception => e
|
11
|
-
puts "Failed to convert asset '#{asset.filename}'."
|
12
|
-
raise e
|
13
|
-
end
|
8
|
+
@converted = self.convert
|
14
9
|
end
|
15
10
|
|
16
11
|
def converted
|
@@ -11,42 +11,25 @@ module JekyllAssetPipeline
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def render(context)
|
14
|
-
# Get YAML manifest from Liquid block
|
15
|
-
manifest = @nodelist.first
|
16
|
-
prefix = @markup.lstrip.rstrip
|
17
|
-
|
18
|
-
# Get site instance from Jekyll
|
19
14
|
site = context.registers[:site]
|
20
|
-
|
21
|
-
# Initialize configuration hash
|
22
15
|
config = site.config['asset_pipeline'] || {}
|
23
16
|
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
# Fetch pipeline from cache if recently processed
|
28
|
-
if JekyllAssetPipeline::Cache.has_key?(hash)
|
29
|
-
pipeline = JekyllAssetPipeline::Cache.get(hash)
|
30
|
-
|
31
|
-
# Return HTML tags pointing to assets
|
32
|
-
return pipeline.html
|
33
|
-
else
|
34
|
-
# Create pipeline and process assets
|
35
|
-
puts "Asset Pipeline: Processing '#{self.class.tag_name}' manifest '#{prefix}'"
|
36
|
-
pipeline = JekyllAssetPipeline::Pipeline.new(manifest, prefix, site.source, site.dest, self.class.output_type, config)
|
37
|
-
pipeline.process
|
17
|
+
# Run Jekyll Asset Pipeline
|
18
|
+
pipeline, cached = Pipeline.run(@nodelist.first, @markup.strip, site.source,
|
19
|
+
site.dest, self.class.tag_name, self.class.output_type, config)
|
38
20
|
|
39
|
-
|
21
|
+
if pipeline.is_a?(Pipeline)
|
22
|
+
# Prevent Jekyll from cleaning up saved assets if new pipeline
|
40
23
|
pipeline.assets.each do |asset|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
24
|
+
site.static_files << StaticAssetFile.new(site, site.dest,
|
25
|
+
asset.output_path, asset.filename)
|
26
|
+
end unless cached
|
44
27
|
|
45
|
-
#
|
46
|
-
JekyllAssetPipeline::Cache.add(hash, pipeline)
|
47
|
-
|
48
|
-
# Return HTML tags pointing to assets
|
28
|
+
# Return HTML tag pointing to asset
|
49
29
|
return pipeline.html
|
30
|
+
else
|
31
|
+
# Return nothing
|
32
|
+
return nil
|
50
33
|
end
|
51
34
|
end
|
52
35
|
end
|
@@ -1,5 +1,69 @@
|
|
1
1
|
module JekyllAssetPipeline
|
2
2
|
class Pipeline
|
3
|
+
class << self
|
4
|
+
# Generate hash based on manifest
|
5
|
+
def hash(source, manifest, options = {})
|
6
|
+
options = DEFAULTS.merge(options)
|
7
|
+
begin
|
8
|
+
Digest::MD5.hexdigest(YAML::load(manifest).map! do |path|
|
9
|
+
"#{path}#{File.mtime(File.join(source, path)).to_i}"
|
10
|
+
end.join.concat(options.to_s))
|
11
|
+
rescue Exception => e
|
12
|
+
puts "Failed to generate hash from provided manifest."
|
13
|
+
raise e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Run pipeline
|
18
|
+
def run(manifest, prefix, source, destination, tag, type, config)
|
19
|
+
# Get hash for pipeline
|
20
|
+
hash = hash(source, manifest, config)
|
21
|
+
|
22
|
+
# Check if pipeline has been cached
|
23
|
+
if cache.has_key?(hash)
|
24
|
+
# Return cached pipeline and cached status
|
25
|
+
return cache[hash], true
|
26
|
+
else
|
27
|
+
begin
|
28
|
+
puts "Processing '#{tag}' manifest '#{prefix}'"
|
29
|
+
|
30
|
+
# Create and process new pipeline
|
31
|
+
pipeline = self.new(manifest, prefix, source, destination, type, config)
|
32
|
+
pipeline.assets.each do |asset|
|
33
|
+
puts "Saved '#{asset.filename}' to '#{destination}/#{asset.output_path}'"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Add processed pipeline to cache
|
37
|
+
cache[hash] = pipeline
|
38
|
+
|
39
|
+
# Return newly processed pipeline and cached status
|
40
|
+
return pipeline, false
|
41
|
+
rescue Exception => e
|
42
|
+
# Add exception to cache
|
43
|
+
cache[hash] = e
|
44
|
+
|
45
|
+
# Re-raise the exception
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Cache processed pipelines
|
52
|
+
def cache
|
53
|
+
@cache ||= {}
|
54
|
+
end
|
55
|
+
|
56
|
+
# Empty cache
|
57
|
+
def clear_cache
|
58
|
+
@cache = {}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Add prefix to output
|
62
|
+
def puts(message)
|
63
|
+
$stdout.puts("Asset Pipeline: #{message}")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
3
67
|
# Initialize new pipeline
|
4
68
|
def initialize(manifest, prefix, source, destination, type, options = {})
|
5
69
|
@manifest = manifest
|
@@ -8,10 +72,14 @@ module JekyllAssetPipeline
|
|
8
72
|
@destination = destination
|
9
73
|
@type = type
|
10
74
|
@options = JekyllAssetPipeline::DEFAULTS.merge(options)
|
75
|
+
|
76
|
+
process
|
11
77
|
end
|
12
78
|
|
13
79
|
attr_reader :assets, :html
|
14
80
|
|
81
|
+
private
|
82
|
+
|
15
83
|
# Process the pipeline
|
16
84
|
def process
|
17
85
|
collect
|
@@ -23,21 +91,6 @@ module JekyllAssetPipeline
|
|
23
91
|
markup
|
24
92
|
end
|
25
93
|
|
26
|
-
# Generate hash based on manifest contents
|
27
|
-
def self.hash(source, manifest, options = {})
|
28
|
-
options = JekyllAssetPipeline::DEFAULTS.merge(options)
|
29
|
-
begin
|
30
|
-
Digest::MD5.hexdigest(YAML::load(manifest).map! do |path|
|
31
|
-
"#{path}#{File.mtime(File.join(source, path)).to_i}"
|
32
|
-
end.join.concat(options.to_s))
|
33
|
-
rescue Exception => e
|
34
|
-
puts "Asset Pipeline: Failed to generate hash from provided manifest."
|
35
|
-
raise e
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
private
|
40
|
-
|
41
94
|
# Collect assets based on manifest
|
42
95
|
def collect
|
43
96
|
begin
|
@@ -154,7 +207,7 @@ module JekyllAssetPipeline
|
|
154
207
|
@html = @assets.map do |asset|
|
155
208
|
klass = JekyllAssetPipeline::Template.subclasses.select do |t|
|
156
209
|
t.filetype == File.extname(asset.filename).downcase
|
157
|
-
end.sort! { |x, y|
|
210
|
+
end.sort! { |x, y| x.priority <=> y.priority }.last
|
158
211
|
|
159
212
|
html = klass.new(path, asset.filename).html unless klass.nil?
|
160
213
|
|
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
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,62 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jekyll
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: '0.12'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: '0.12'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: liquid
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
35
|
-
- -
|
35
|
+
- - ~>
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: '2.4'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: '2.4'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rake
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0
|
53
|
+
version: '10.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0
|
61
|
+
version: '10.0'
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
63
|
name: minitest
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '4.3'
|
70
70
|
type: :development
|
@@ -72,7 +72,7 @@ dependencies:
|
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
|
-
- -
|
75
|
+
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '4.3'
|
78
78
|
description: Adds asset preprocessing (CoffeeScript, Sass, Less, ERB, etc.) and asset
|
@@ -84,7 +84,6 @@ extensions: []
|
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
86
|
- lib/jekyll_asset_pipeline/asset.rb
|
87
|
-
- lib/jekyll_asset_pipeline/cache.rb
|
88
87
|
- lib/jekyll_asset_pipeline/compressor.rb
|
89
88
|
- lib/jekyll_asset_pipeline/converter.rb
|
90
89
|
- lib/jekyll_asset_pipeline/extensions/jekyll/site.rb
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module JekyllAssetPipeline
|
2
|
-
class Cache
|
3
|
-
@cache = {}
|
4
|
-
|
5
|
-
def self.add(key, value)
|
6
|
-
@cache[key] = value
|
7
|
-
end
|
8
|
-
|
9
|
-
def self.has_key?(key)
|
10
|
-
@cache.has_key?(key)
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.get(key)
|
14
|
-
@cache[key]
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.clear
|
18
|
-
@cache = {}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|