jekyll-asset-post-processor 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a792371c4737b731abbb720b92425965ccce1f1841969db9c1113cfc18a551b
4
- data.tar.gz: a536f5d13e043a833e75e3bf35fa74dcbc2c20c9a0e66e9f55f2447812a24b41
3
+ metadata.gz: 49fd94c0bbcf82ad730f511c352fd415c77b61299e68fe53da97d6d39b07039d
4
+ data.tar.gz: 9563eb740ee7c01f0b1dfcec82c2930fe9b2bfe610268690cb0b9998e2ac5b2a
5
5
  SHA512:
6
- metadata.gz: 1c5187e72e50fe89cc483f2785eeb865ea81e91e1671fffc965da1229f008e9e9a7a7dc145c3e02aa0cf160f1a3ae544f40452ffe02b7851f17eea335986328f
7
- data.tar.gz: 44ce6da1ee7ba522a40b8eb611a4b7e137228986fdbf5fcb9b62da897415a5e752753c83685201551c73b6ea6a51da6ceaecdf2ded5ac02f20fcafb23603205c
6
+ metadata.gz: '093a6bed1e6d402113a49b1a082c53fbf0ed6ca3ee146e59dfc9db3315ca18b30f1cd4020f6e450c94253ade32fcb84a151bf1ec707cc6229fce8c637fc2a70d'
7
+ data.tar.gz: b6598cbf5f9a36102db08623d58b674909e9af320d8eb49f70c9ba13bf2516e1d7f81235a951caf70c0fae3fc73ef673e8a4500e29fb5b88d7007d36d160ba2a
data/ACKNOWLEDGEMENTS CHANGED
@@ -1,23 +1,23 @@
1
- matthodan/jekyll-asset-pipeline - https://github.com/matthodan/jekyll-asset-pipeline
2
-
3
- (The MIT License)
4
-
5
- Copyright (c) 2012 Matt Hodan (http://www.matthodan.com)
6
-
7
- Permission is hereby granted, free of charge, to any person obtaining a copy
8
- of this software and associated documentation files (the 'Software'), to deal
9
- in the Software without restriction, including without limitation the rights
10
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- copies of the Software, and to permit persons to whom the Software is
12
- furnished to do so, subject to the following conditions:
13
-
14
- The above copyright notice and this permission notice shall be included in all
15
- copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ matthodan/jekyll-asset-pipeline - https://github.com/matthodan/jekyll-asset-pipeline
2
+
3
+ (The MIT License)
4
+
5
+ Copyright (c) 2012 Matt Hodan (http://www.matthodan.com)
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the 'Software'), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in all
15
+ copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
23
  SOFTWARE.
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Darcy Supply Ltd.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Darcy Supply Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
data/README.md CHANGED
@@ -1,85 +1,85 @@
1
- # jekyll-asset-post-processor
2
- Process then suffix your Jekyll assets with cache busting version hashes
3
-
4
- ## How It Works
5
-
6
- `jekyll-asset-post-processor` takes a given asset, renders/processes it, suffixes a version hash based on it's contents and name, and then bundles it in your website's final build. It was built for cache busting with these core concepts in mind:
7
-
8
- - Work with all assets: CSS, JS, images, videos, etc.
9
- - Produce a version hash that's consistent across environments and is Git friendly.
10
- - The ability to import assets within HTML and Sass files.
11
- - Simple to setup and use, matching Jekyll's simplicity.
12
- - No inline templates: you handle the code, the plugin handles the assets.
13
- - Fully compatible with `jekyll serve`.
14
- - Extendable with custom processors.
15
-
16
- Used in production at [darcysupply.com](https://darcysupply.com).
17
-
18
- ## Usage
19
-
20
- A single tag imports an asset, which in turn returns the new relative path to the bundled asset.
21
- `{% process_asset _assets/css/style.scss %}` = `/assets/css/style-cdb523590dafe38b9df14dde169125a4.css`
22
-
23
- The tag can be used in any HTML or Sass file and even supports Liquid variables, filters, and tags. An asset is only rendered and bundled once, meaning you can include an asset more than once across multiple files without conflicts.
24
-
25
- ### HTML
26
-
27
- Because Liquid variables are supported, you can pass a page provided variable as the input asset.
28
-
29
- ```html
30
- <link rel="stylesheet" href="{% process_asset {{ page.stylesheet }} %}">
31
- ```
32
-
33
- ### Sass / SCSS
34
-
35
- Sass files are parsed with Liquid, rendered with `sassc`, and then minified.
36
-
37
- Sass files inherit the static Liquid variables from the page that imported it. In cases where a file is imported more than once, the variables present will be from the first page that imported it.
38
-
39
- ```css
40
- .app-glyph {
41
- background-image: url("{% process_asset _assets/img/app-icon.png %} ")
42
- }
43
- ```
44
-
45
- ### Version Hashing
46
-
47
- The module creates an MD5 digest hash based on the final rendered contents of the file. This makes the version hash consistent across environments, especially since Git doesn't preserve modification dates, and means on CDN deploy the only new assets that get updated are the ones that have changed.
48
-
49
- ## Setup
50
-
51
- 1. Add `gem "jekyll-asset-post-processor"` to your Gemfile and run `bundle install`.
52
- 2. Add `jekyll-asset-post-processor` to plugins in `_config.yml`
53
- ```yaml
54
- plugins:
55
- - jekyll-asset-post-processor
56
- ```
57
-
58
- ## Config
59
-
60
- `jekyll-asset-post-processor` can be further configured in your Jekyll `_config.yml`.
61
-
62
- ```yaml
63
- asset-post-processor:
64
- - staging_path: "_staging"
65
- - destination_path: "assets"
66
- ```
67
-
68
- |Name|Description|Default|
69
- |-|-|-|
70
- |`staging_path`|The temporary directory where bundled assets are stored before being moved to the final build. The plugin will automatically add this file to Jekyll's excluded list, you should also add it to your `.gitignore` if necessary.|`_staging`|
71
- |`destination_path`|The root directory in the site's final build (`_site`) where the bundled assets should be stored.|`assets`|
72
-
73
- ## Custom Processors
74
-
75
- You can write your own processor for a specified file extension, [find full documentation](https://github.com/darcysupply/jekyll-asset-post-processor/blob/main/lib/processor.rb) within the class definition. [The Sass processor](https://github.com/darcysupply/jekyll-asset-post-processor/blob/main/lib/processors/scss.rb) is a fully working, in-production example.
76
-
77
- ## Acknowledgements
78
-
79
- Parts of the Jekyll code and architectural choices come from [jekyll-asset-pipeline](https://github.com/matthodan/jekyll-asset-pipeline), thanks to Matt Hodan and other contributors of the project.
80
-
81
- ## About
82
-
83
- ![Darcy logo](https://raw.githubusercontent.com/darcysupply/jekyll-asset-post-processor/main/.github/darcy.png)
84
-
1
+ # jekyll-asset-post-processor
2
+ Process then suffix your Jekyll assets with cache busting version hashes
3
+
4
+ ## How It Works
5
+
6
+ `jekyll-asset-post-processor` takes a given asset, renders/processes it, suffixes a version hash based on it's contents and name, and then bundles it in your website's final build. It was built for cache busting with these core concepts in mind:
7
+
8
+ - Work with all assets: CSS, JS, images, videos, etc.
9
+ - Produce a version hash that's consistent across environments and is Git friendly.
10
+ - The ability to import assets within HTML and Sass files.
11
+ - Simple to setup and use, matching Jekyll's simplicity.
12
+ - No inline templates: you handle the code, the plugin handles the assets.
13
+ - Fully compatible with `jekyll serve`.
14
+ - Extendable with custom processors.
15
+
16
+ Used in production at [darcysupply.com](https://darcysupply.com).
17
+
18
+ ## Usage
19
+
20
+ A single tag imports an asset, which in turn returns the new relative path to the bundled asset.
21
+ `{% process_asset _assets/css/style.scss %}` = `/assets/css/style-cdb523590dafe38b9df14dde169125a4.css`
22
+
23
+ The tag can be used in any HTML or Sass file and even supports Liquid variables, filters, and tags. An asset is only rendered and bundled once, meaning you can include an asset more than once across multiple files without conflicts.
24
+
25
+ ### HTML
26
+
27
+ Because Liquid variables are supported, you can pass a page provided variable as the input asset.
28
+
29
+ ```html
30
+ <link rel="stylesheet" href="{% process_asset {{ page.stylesheet }} %}">
31
+ ```
32
+
33
+ ### Sass / SCSS
34
+
35
+ Sass files are rendered with `sassc`, parsed with Liquid, and then minified.
36
+
37
+ Sass files inherit the static Liquid variables from the page that imported it. In cases where a file is imported more than once, the variables present will be from the first page that imported it. Processing is supported in all Sass imported stylesheets too.
38
+
39
+ ```css
40
+ .app-glyph {
41
+ background-image: url("{% process_asset _assets/img/app-icon.png %} ")
42
+ }
43
+ ```
44
+
45
+ ### Version Hashing
46
+
47
+ The module creates an MD5 digest hash based on the final rendered contents of the file. This makes the version hash consistent across environments, especially since Git doesn't preserve modification dates, and means on CDN deploy the only new assets that get updated are the ones that have changed.
48
+
49
+ ## Setup
50
+
51
+ 1. Add `gem "jekyll-asset-post-processor"` to your Gemfile and run `bundle install`.
52
+ 2. Add `jekyll-asset-post-processor` to plugins in `_config.yml`
53
+ ```yaml
54
+ plugins:
55
+ - jekyll-asset-post-processor
56
+ ```
57
+
58
+ ## Config
59
+
60
+ `jekyll-asset-post-processor` can be further configured in your Jekyll `_config.yml`.
61
+
62
+ ```yaml
63
+ asset-post-processor:
64
+ - staging_path: "_staging"
65
+ - destination_path: "assets"
66
+ ```
67
+
68
+ |Name|Description|Default|
69
+ |-|-|-|
70
+ |`staging_path`|The temporary directory where bundled assets are stored before being moved to the final build. The plugin will automatically add this file to Jekyll's excluded list, you should also add it to your `.gitignore` if necessary.|`_staging`|
71
+ |`destination_path`|The root directory in the site's final build (`_site`) where the bundled assets should be stored.|`assets`|
72
+
73
+ ## Custom Processors
74
+
75
+ You can write your own processor for a specified file extension, [find full documentation](https://github.com/darcysupply/jekyll-asset-post-processor/blob/main/lib/processor.rb) within the class definition. [The Sass processor](https://github.com/darcysupply/jekyll-asset-post-processor/blob/main/lib/processors/scss.rb) is a fully working, in-production example.
76
+
77
+ ## Acknowledgements
78
+
79
+ Parts of the Jekyll code and architectural choices come from [jekyll-asset-pipeline](https://github.com/matthodan/jekyll-asset-pipeline), thanks to Matt Hodan and other contributors of the project.
80
+
81
+ ## About
82
+
83
+ ![Darcy logo](https://raw.githubusercontent.com/darcysupply/jekyll-asset-post-processor/main/.github/darcy.png)
84
+
85
85
  `jekyll-asset-post-processor` is maintained by Darcy. We make apps, come [check us out](https://darcysupply.com).
data/lib/cache.rb CHANGED
@@ -1,11 +1,11 @@
1
- module JekyllAssetPostProcessor
2
- # Return the cache and create it if not present.
3
- def self.cache
4
- @cache ||= {}
5
- end
6
-
7
- # Clear the cache.
8
- def self.clear_cache
9
- @cache = {}
10
- end
1
+ module JekyllAssetPostProcessor
2
+ # Return the cache and create it if not present.
3
+ def self.cache
4
+ @cache ||= {}
5
+ end
6
+
7
+ # Clear the cache.
8
+ def self.clear_cache
9
+ @cache = {}
10
+ end
11
11
  end
data/lib/config.rb CHANGED
@@ -1,16 +1,16 @@
1
- module JekyllAssetPostProcessor
2
- DEFAULTS = {
3
- 'staging_path' => '_staging',
4
- 'destination_path' => 'assets'
5
- }
6
-
7
- def self.config_staging_path(jekyll_config)
8
- config = jekyll_config['asset-post-processor'] || [{}]
9
- return config[0]['staging_path'] || DEFAULTS['staging_path']
10
- end
11
-
12
- def self.config_destination_path(jekyll_config)
13
- config = jekyll_config['asset-post-processor'] || [{}]
14
- config[0]['destination_path'] || DEFAULTS['destination_path']
15
- end
1
+ module JekyllAssetPostProcessor
2
+ DEFAULTS = {
3
+ 'staging_path' => '_staging',
4
+ 'destination_path' => 'assets'
5
+ }
6
+
7
+ def self.config_staging_path(jekyll_config)
8
+ config = jekyll_config['asset-post-processor'] || [{}]
9
+ return config[0]['staging_path'] || DEFAULTS['staging_path']
10
+ end
11
+
12
+ def self.config_destination_path(jekyll_config)
13
+ config = jekyll_config['asset-post-processor'] || [{}]
14
+ config[0]['destination_path'] || DEFAULTS['destination_path']
15
+ end
16
16
  end
@@ -1,42 +1,42 @@
1
- # This trick comes directly from jekyll-asset-pipeline. All credit and thanks to Matt Hodan and contributors.
2
- # https://github.com/matthodan/jekyll-asset-pipeline
3
- module JekyllSiteExtension
4
- def self.included(base)
5
- base.class_eval do
6
- base_cleanup = instance_method(:cleanup)
7
- define_method(:cleanup) do
8
- return_value = base_cleanup.bind(self).call
9
- JekyllAssetPostProcessor::clear_cache
10
- return_value
11
- end
12
-
13
- # No longer removing staged assets as re-generating un-changed staged assets
14
- # causes infinite loops when serving.
15
-
16
- # base_write = instance_method(:write)
17
- # define_method(:write) do
18
- # return_value = base_write.bind(self).call
19
- # JekyllAssetPostProcessor::remove_staged_assets(self.config)
20
- # return_value
21
- # end
22
- end
23
- end
24
- end
25
-
26
- module Jekyll
27
- class Site
28
- include JekyllSiteExtension
29
- end
30
- end
31
-
32
- # Add the staging directory to the serve based
33
- require 'jekyll-watch'
34
- module Jekyll
35
- module Watcher
36
- alias_method :old_custom_excludes, :custom_excludes
37
- def custom_excludes(options)
38
- options['exclude'] << JekyllAssetPostProcessor::config_staging_path(options)
39
- old_custom_excludes(options)
40
- end
41
- end
1
+ # This trick comes directly from jekyll-asset-pipeline. All credit and thanks to Matt Hodan and contributors.
2
+ # https://github.com/matthodan/jekyll-asset-pipeline
3
+ module JekyllSiteExtension
4
+ def self.included(base)
5
+ base.class_eval do
6
+ base_cleanup = instance_method(:cleanup)
7
+ define_method(:cleanup) do
8
+ return_value = base_cleanup.bind(self).call
9
+ JekyllAssetPostProcessor::clear_cache
10
+ return_value
11
+ end
12
+
13
+ # No longer removing staged assets as re-generating un-changed staged assets
14
+ # causes infinite loops when serving.
15
+
16
+ # base_write = instance_method(:write)
17
+ # define_method(:write) do
18
+ # return_value = base_write.bind(self).call
19
+ # JekyllAssetPostProcessor::remove_staged_assets(self.config)
20
+ # return_value
21
+ # end
22
+ end
23
+ end
24
+ end
25
+
26
+ module Jekyll
27
+ class Site
28
+ include JekyllSiteExtension
29
+ end
30
+ end
31
+
32
+ # Add the staging directory to the serve based
33
+ require 'jekyll-watch'
34
+ module Jekyll
35
+ module Watcher
36
+ alias_method :old_custom_excludes, :custom_excludes
37
+ def custom_excludes(options)
38
+ options['exclude'] << JekyllAssetPostProcessor::config_staging_path(options)
39
+ old_custom_excludes(options)
40
+ end
41
+ end
42
42
  end
data/lib/hash.rb CHANGED
@@ -1,14 +1,14 @@
1
- module JekyllAssetPostProcessor
2
- # Generate a hash to be used in the internal cache to avoid processing
3
- # a file more than once per build.
4
- def self.cache_hash(file_path)
5
- mtime = File.mtime(File.join(file_path))
6
- Digest::MD5.hexdigest(file_path + mtime.to_s)
7
- end
8
-
9
- # Generate a hash to be used in the final file name. Generated from
10
- # the final rendered file contents.
11
- def self.file_hash(file_path, content)
12
- Digest::MD5.hexdigest(content)
13
- end
1
+ module JekyllAssetPostProcessor
2
+ # Generate a hash to be used in the internal cache to avoid processing
3
+ # a file more than once per build.
4
+ def self.cache_hash(file_path)
5
+ mtime = File.mtime(File.join(file_path))
6
+ Digest::MD5.hexdigest(file_path + mtime.to_s)
7
+ end
8
+
9
+ # Generate a hash to be used in the final file name. Generated from
10
+ # the final rendered file contents.
11
+ def self.file_hash(file_path, content)
12
+ Digest::MD5.hexdigest(content)
13
+ end
14
14
  end
@@ -1,16 +1,16 @@
1
- require 'digest/md5'
2
- require 'fileutils'
3
- require 'time'
4
-
5
- require 'jekyll'
6
- require 'sassc'
7
-
8
- require 'cache'
9
- require 'config'
10
- require 'hash'
11
- require 'processor'
12
- require 'process'
13
- require 'processors/scss'
14
- require 'liquid/process_asset_tag'
15
-
16
- require 'extensions/jekyll.rb'
1
+ require 'digest/md5'
2
+ require 'fileutils'
3
+ require 'time'
4
+
5
+ require 'jekyll'
6
+ require 'sassc'
7
+
8
+ require 'cache'
9
+ require 'config'
10
+ require 'hash'
11
+ require 'processor'
12
+ require 'process'
13
+ require 'processors/scss'
14
+ require 'liquid/process_asset_tag'
15
+
16
+ require 'extensions/jekyll.rb'
@@ -1,22 +1,22 @@
1
- module JekyllAssetPostProcessor
2
-
3
- class ProcessAssetTag < Liquid::Tag
4
- def initialize(tag_name, args, token)
5
- super
6
- @args = args.strip
7
- end
8
-
9
- def render(context)
10
- template = Liquid::Template.parse(@args)
11
- stylesheet_path = template.render(context)
12
-
13
- if stylesheet_path.length == 0
14
- raise 'No asset given to process'
15
- end
16
-
17
- JekyllAssetPostProcessor::process(context, stylesheet_path)
18
- end
19
- end
20
- Liquid::Template.register_tag('process_asset', ProcessAssetTag)
21
-
1
+ module JekyllAssetPostProcessor
2
+
3
+ class ProcessAssetTag < Liquid::Tag
4
+ def initialize(tag_name, args, token)
5
+ super
6
+ @args = args.strip
7
+ end
8
+
9
+ def render(context)
10
+ template = Liquid::Template.parse(@args)
11
+ stylesheet_path = template.render(context)
12
+
13
+ if stylesheet_path.length == 0
14
+ raise 'No asset given to process'
15
+ end
16
+
17
+ JekyllAssetPostProcessor::process(context, stylesheet_path)
18
+ end
19
+ end
20
+ Liquid::Template.register_tag('process_asset', ProcessAssetTag)
21
+
22
22
  end
data/lib/process.rb CHANGED
@@ -1,106 +1,106 @@
1
- module JekyllAssetPostProcessor
2
- def self.remove_staged_assets(jekyll_config)
3
- staging_path = File.join(config_staging_path(jekyll_config))
4
- FileUtils.rm_rf(staging_path)
5
- end
6
-
7
- # Register a new asset with Jekyll from the staging directory in order
8
- # to be moved into the final build directory.
9
- def self.new_jekyll_asset(site, staging_path, output_path, filename)
10
- site.static_files << Jekyll::StaticFile.new(site, staging_path, output_path, filename)
11
- end
12
-
13
- def self.processors
14
- @processors ||= {}
15
- end
16
-
17
- def self.register_processor(extension, processor)
18
- processors[extension] = processor
19
- end
20
-
21
- # Process a single asset file.
22
- def self.process(context, file_path)
23
- site = context.registers[:site]
24
- jekyll_config = site.config
25
-
26
- generated_cache_hash = cache_hash(file_path)
27
- return cache[generated_cache_hash] if cache.key?(generated_cache_hash)
28
-
29
- source = site.source
30
- path = File.join(source, file_path)
31
- basename = File.basename(path)
32
- filename = File.basename(path, '.*')
33
- extension = File.extname(basename)
34
-
35
- # generate the destination path, by default insert into assets directory
36
- staging_path = config_staging_path(jekyll_config)
37
- destination_path = config_destination_path(jekyll_config)
38
-
39
- split_path = file_path.split('/')
40
- if split_path.length > 2
41
- destination_path += '/' + split_path[1..-2].join('/')
42
- end
43
-
44
- generated_file_hash = nil
45
- new_extension = extension
46
- rendered = nil
47
-
48
- rendered = nil
49
- rendered_binary = nil
50
- if processors.key?(extension)
51
- processor = processors[extension].new(filename, extension, file_path)
52
- new_extension = processor.new_extension
53
-
54
- new_contents = nil
55
- File.open(path, 'r') do |file|
56
- new_contents = processor.process(file.read, context)
57
- end
58
- if new_contents.nil?
59
- File.open(path, 'rb') do |file|
60
- new_binary_contents = processor.process_binary(file.read, context)
61
- if new_binary_contents.nil?
62
- raise "Processor for #{extension} doesn't override process or process_binary"
63
- else
64
- rendered_binary = new_binary_contents
65
- generated_file_hash = file_hash(file_path, rendered_binary)
66
- end
67
- end
68
- else
69
- rendered = new_contents
70
- generated_file_hash = file_hash(file_path, rendered)
71
- end
72
- else
73
- File.open(path, 'rb') do |file|
74
- generated_file_hash = file_hash(file_path, file.read)
75
- end
76
- end
77
-
78
-
79
- generated_filename = "#{filename}-#{generated_file_hash}#{new_extension}"
80
- staging_destination = File.join(source, staging_path, destination_path)
81
-
82
- FileUtils.mkpath(staging_destination) unless File.directory?(staging_destination)
83
- generated_staging_path = File.join(staging_destination, generated_filename)
84
- if !File.file?(generated_staging_path)
85
- if !rendered.nil?
86
- File.open(generated_staging_path, 'w') do |file|
87
- file.write(rendered)
88
- end
89
- elsif !rendered_binary.nil?
90
- File.open(generated_staging_path, 'wb') do |file|
91
- file.write(rendered_binary)
92
- end
93
- else
94
- FileUtils.cp(path, File.join(staging_destination, generated_filename))
95
- end
96
- end
97
-
98
- new_jekyll_asset(site, staging_path, destination_path, generated_filename)
99
-
100
- generated_asset_site_path = '/' + File.join(destination_path, generated_filename)
101
- cache[cache_hash(file_path)] = generated_asset_site_path
102
- return generated_asset_site_path
103
-
104
- end
105
-
1
+ module JekyllAssetPostProcessor
2
+ def self.remove_staged_assets(jekyll_config)
3
+ staging_path = File.join(config_staging_path(jekyll_config))
4
+ FileUtils.rm_rf(staging_path)
5
+ end
6
+
7
+ # Register a new asset with Jekyll from the staging directory in order
8
+ # to be moved into the final build directory.
9
+ def self.new_jekyll_asset(site, staging_path, output_path, filename)
10
+ site.static_files << Jekyll::StaticFile.new(site, staging_path, output_path, filename)
11
+ end
12
+
13
+ def self.processors
14
+ @processors ||= {}
15
+ end
16
+
17
+ def self.register_processor(extension, processor)
18
+ processors[extension] = processor
19
+ end
20
+
21
+ # Process a single asset file.
22
+ def self.process(context, file_path)
23
+ site = context.registers[:site]
24
+ jekyll_config = site.config
25
+
26
+ generated_cache_hash = cache_hash(file_path)
27
+ return cache[generated_cache_hash] if cache.key?(generated_cache_hash)
28
+
29
+ source = site.source
30
+ path = File.join(source, file_path)
31
+ basename = File.basename(path)
32
+ filename = File.basename(path, '.*')
33
+ extension = File.extname(basename)
34
+
35
+ # generate the destination path, by default insert into assets directory
36
+ staging_path = config_staging_path(jekyll_config)
37
+ destination_path = config_destination_path(jekyll_config)
38
+
39
+ split_path = file_path.split('/')
40
+ if split_path.length > 2
41
+ destination_path += '/' + split_path[1..-2].join('/')
42
+ end
43
+
44
+ generated_file_hash = nil
45
+ new_extension = extension
46
+ rendered = nil
47
+
48
+ rendered = nil
49
+ rendered_binary = nil
50
+ if processors.key?(extension)
51
+ processor = processors[extension].new(filename, extension, file_path)
52
+ new_extension = processor.new_extension
53
+
54
+ new_contents = nil
55
+ File.open(path, 'r') do |file|
56
+ new_contents = processor.process(file.read, context)
57
+ end
58
+ if new_contents.nil?
59
+ File.open(path, 'rb') do |file|
60
+ new_binary_contents = processor.process_binary(file.read, context)
61
+ if new_binary_contents.nil?
62
+ raise "Processor for #{extension} doesn't override process or process_binary"
63
+ else
64
+ rendered_binary = new_binary_contents
65
+ generated_file_hash = file_hash(file_path, rendered_binary)
66
+ end
67
+ end
68
+ else
69
+ rendered = new_contents
70
+ generated_file_hash = file_hash(file_path, rendered)
71
+ end
72
+ else
73
+ File.open(path, 'rb') do |file|
74
+ generated_file_hash = file_hash(file_path, file.read)
75
+ end
76
+ end
77
+
78
+
79
+ generated_filename = "#{filename}-#{generated_file_hash}#{new_extension}"
80
+ staging_destination = File.join(source, staging_path, destination_path)
81
+
82
+ FileUtils.mkpath(staging_destination) unless File.directory?(staging_destination)
83
+ generated_staging_path = File.join(staging_destination, generated_filename)
84
+ if !File.file?(generated_staging_path)
85
+ if !rendered.nil?
86
+ File.open(generated_staging_path, 'w') do |file|
87
+ file.write(rendered)
88
+ end
89
+ elsif !rendered_binary.nil?
90
+ File.open(generated_staging_path, 'wb') do |file|
91
+ file.write(rendered_binary)
92
+ end
93
+ else
94
+ FileUtils.cp(path, File.join(staging_destination, generated_filename))
95
+ end
96
+ end
97
+
98
+ new_jekyll_asset(site, staging_path, destination_path, generated_filename)
99
+
100
+ generated_asset_site_path = '/' + File.join(destination_path, generated_filename)
101
+ cache[cache_hash(file_path)] = generated_asset_site_path
102
+ return generated_asset_site_path
103
+
104
+ end
105
+
106
106
  end
data/lib/processor.rb CHANGED
@@ -1,54 +1,54 @@
1
- module JekyllAssetPostProcessor
2
-
3
- # Subclass any processors with JekyllAssetPostProcessor::Processor.
4
- #
5
- # To register your processor:
6
- # `JekyllAssetPostProcessor::register_processor('.ext', processor)`
7
- class Processor
8
- # If overriding you are required to call `super`.
9
- def initialize(filename, extension, source_path)
10
- # Filename stripped of the extension.
11
- @filename = filename
12
- # Extension, containing the prefix '.'.
13
- @extension = extension
14
- # The source path directly given from {% process_asset %}
15
- @source_path = source_path
16
- end
17
-
18
- # Optional to override, default behavior is using the original extension.
19
- def new_extension
20
- @extension
21
- end
22
-
23
- # Process the string value of the file, useful for text based files like
24
- # JS and CSS.
25
- #
26
- # You are given the Liquid context as the second arguument which can
27
- # be used like `Liquid::Template.parse(contents).render(liquid_context)`.
28
- # The string contents argument given is pre-Liquid rendering, you must
29
- # render Liquid content yourself as shown before.
30
- #
31
- # You must override either this or `process_binary`. See also `process_binary`.
32
- def process(contents, liquid_context)
33
- nil
34
- end
35
-
36
- # Process the binary value of the file, useful for binary files like
37
- # images and videos.
38
- #
39
- # You are given the Liquid context as the second argument. Rendering
40
- # the content may be less useful as Liquid only works with strings,
41
- # however you can get the page and site variables like so:
42
- # page = liquid_context.registers[:page]
43
- # site = liquid_context.registers[:site]
44
- # page_title = site[:title]
45
- #
46
- # You must override either this or `process`. See also `process`.
47
- def process_binary(contents, liquid_context)
48
- nil
49
- end
50
- end
51
-
52
- # See lib/processors/scss.rb for an example of a processor.
53
-
1
+ module JekyllAssetPostProcessor
2
+
3
+ # Subclass any processors with JekyllAssetPostProcessor::Processor.
4
+ #
5
+ # To register your processor:
6
+ # `JekyllAssetPostProcessor::register_processor('.ext', processor)`
7
+ class Processor
8
+ # If overriding you are required to call `super`.
9
+ def initialize(filename, extension, source_path)
10
+ # Filename stripped of the extension.
11
+ @filename = filename
12
+ # Extension, containing the prefix '.'.
13
+ @extension = extension
14
+ # The source path directly given from {% process_asset %}
15
+ @source_path = source_path
16
+ end
17
+
18
+ # Optional to override, default behavior is using the original extension.
19
+ def new_extension
20
+ @extension
21
+ end
22
+
23
+ # Process the string value of the file, useful for text based files like
24
+ # JS and CSS.
25
+ #
26
+ # You are given the Liquid context as the second arguument which can
27
+ # be used like `Liquid::Template.parse(contents).render(liquid_context)`.
28
+ # The string contents argument given is pre-Liquid rendering, you must
29
+ # render Liquid content yourself as shown before.
30
+ #
31
+ # You must override either this or `process_binary`. See also `process_binary`.
32
+ def process(contents, liquid_context)
33
+ nil
34
+ end
35
+
36
+ # Process the binary value of the file, useful for binary files like
37
+ # images and videos.
38
+ #
39
+ # You are given the Liquid context as the second argument. Rendering
40
+ # the content may be less useful as Liquid only works with strings,
41
+ # however you can get the page and site variables like so:
42
+ # page = liquid_context.registers[:page]
43
+ # site = liquid_context.registers[:site]
44
+ # page_title = site[:title]
45
+ #
46
+ # You must override either this or `process`. See also `process`.
47
+ def process_binary(contents, liquid_context)
48
+ nil
49
+ end
50
+ end
51
+
52
+ # See lib/processors/scss.rb for an example of a processor.
53
+
54
54
  end
@@ -1,19 +1,19 @@
1
- # See lib/processor.rb for full documentation.
2
-
3
- module JekyllAssetPostProcessor
4
-
5
- class SassProcessor < JekyllAssetPostProcessor::Processor
6
-
7
- def new_extension
8
- '.css'
9
- end
10
-
11
- def process(contents, liquid_context)
12
- template = Liquid::Template.parse(contents)
13
- SassC::Engine.new(template.render(liquid_context), syntax: :scss, style: :compressed).render
14
- end
15
-
16
- end
17
- JekyllAssetPostProcessor::register_processor('.scss', SassProcessor)
18
-
1
+ # See lib/processor.rb for full documentation.
2
+
3
+ module JekyllAssetPostProcessor
4
+
5
+ class SassProcessor < JekyllAssetPostProcessor::Processor
6
+
7
+ def new_extension
8
+ '.css'
9
+ end
10
+
11
+ def process(contents, liquid_context)
12
+ sass = SassC::Engine.new(contents, syntax: :scss, style: :compressed).render
13
+ Liquid::Template.parse(sass).render(liquid_context)
14
+ end
15
+
16
+ end
17
+ JekyllAssetPostProcessor::register_processor('.scss', SassProcessor)
18
+
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-asset-post-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darcy Supply Ltd.
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-05-05 00:00:00.000000000 Z
12
+ date: 2023-03-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jekyll
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  requirements: []
113
- rubygems_version: 3.2.32
113
+ rubygems_version: 3.4.6
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Process then suffix your Jekyll assets with cache busting version hashes