jekyll-kw-sri 0.0.4 → 0.0.5

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: 2bf7b33dc9b54d2ebcec17404f4bf5548760edba5148f8bf35b78a721d307293
4
- data.tar.gz: 03f1d62d5b555a4225c4d352d744de1152b8976afda0332dd7d5510b8c17a1dc
3
+ metadata.gz: 21baed53f8e36155187629181d0d0db471bb7e8c5002e7121998d6a2e8009a0b
4
+ data.tar.gz: fcce7592fcaa7901d35c418ee53f36e84747924ab3f5600749a185d8719a610d
5
5
  SHA512:
6
- metadata.gz: 1a9fe066a7815dff331e10b68da1c3d83ae020afc901bdb81624aeb970d794fad34c2e53290481c4295a648dcf88e9d0c33c75fae707adf140efd81c10d34d7b
7
- data.tar.gz: 4165a4c3b504a10622cc7991e13302bd3ee5c76ee8e62df7d86b28ed5a03268d87badf9c62c7881a89f6c7df25f69fdcb30b1deb008bbf258db7e5f84076d11d
6
+ metadata.gz: 6c50c84167e0febc7402d51df4bc66c040fb048899e9e58024847439319202fbcf89e59f8c7a9771b44f0b8f01fab290a76614728b0a094dc4a498b19c415062
7
+ data.tar.gz: e29ed92a20699f71a692141c25faf0b6eb79cab9e8c20d96cf4b18981a092d149211c9f80fdb493930c4d85203d979b324bcc77aa2cfbc27f7231420b2aaaa88
data/README.md CHANGED
@@ -10,7 +10,7 @@ from [Mozilla docs][Mozilla Subresource Integrity]
10
10
 
11
11
  ## Configuration
12
12
 
13
- Add `kw-sri` section to `_config.yml` configure the plugin globally.
13
+ Add `kw-sri` section to `_config.yml` configure the plugin globally. If you want to use defauls you can ommit the config-section.
14
14
 
15
15
  ```yaml
16
16
  kw-sri:
@@ -27,18 +27,46 @@ kw-sri:
27
27
  | hash_type | Which kind of integrity hash | sha256, **sha384**, sha512 |
28
28
  | write_source_mapping_url | Add the map-file like to the css | false, **true** |
29
29
 
30
- Add `sri: true` to **Front Matter** of `<page>` or `<post>` to activate the sri plugin.
30
+ ## Action Items / Shell commands
31
31
 
32
- ## Build gem
32
+ Run linting and tests
33
33
 
34
- ## Publish gem
34
+ ```sh
35
+ bundle exec rubocop
36
+ bundle exec rake test
37
+ ```
35
38
 
36
- ## Run tests
39
+ Build gem package
37
40
 
38
41
  ```sh
39
- bundle exec rake test
42
+ bundle exec rake build
43
+ ```
44
+
45
+ Publish gem package
46
+
47
+ ```sh
48
+ bundle exec rake release
49
+ ```
50
+
51
+ Calc a SRI Integrity hash of `./style.css` in format `sha256`
52
+
53
+ ```shell
54
+ openssl dgst -sha256 -binary ./style.css | openssl base64 -A
40
55
  ```
41
56
 
57
+ Calc different **SRI integrity** hash-files from `css-files` (same is valid for `js-files`) in format `sha256`, `sha384` and `sha512` inside a **Makefile**
58
+
59
+ ```plain
60
+ calc-integrity-files:
61
+ for strength in 256 384 512 ; do \
62
+ cat ./assets/css/style.min.css | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/style.min.css.sha$$strength ; \
63
+ cat ./assets/css/main.css | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/main.css.sha$$strength ; \
64
+ cat ./assets/js/script.js | openssl dgst -sha$$strength -binary | openssl base64 -A > ./_includes/integrity/script.js.sha$$strength ; \
65
+ done
66
+ ```
67
+
68
+ ## Notes / Hints
69
+
42
70
  ### Appraisal - Gemfile Generator
43
71
 
44
72
  [GitHub](https://github.com/thoughtbot/appraisal)
@@ -50,8 +78,6 @@ bundle exec rake test
50
78
  bundle exec appraisal generate
51
79
  ```
52
80
 
53
- ## Notes / Hints
54
-
55
81
  ### Site context is empty
56
82
 
57
83
  Inside the `render(context)` function of a `Liquid::Tag` there is a context object. With that context you can get the `site` object, anyhow when you want to cretae your temporry **site** and **context** you need a workaround.
@@ -92,12 +118,6 @@ converter = if defined? site.find_converter_instance
92
118
  end
93
119
  ```
94
120
 
95
- ## SRI Integrity
96
-
97
- ```shell
98
- openssl dgst -sha256 -binary ./style.css | openssl base64 -A
99
- ```
100
-
101
121
  ## Setup Steps
102
122
 
103
123
  ```sh
@@ -11,19 +11,13 @@ module Jekyll
11
11
  class SriScssHashTag < Jekyll::Tags::IncludeRelativeTag
12
12
  # class SriScssHashTag < Liquid::Tag
13
13
 
14
- alias super_render render
14
+ # alias super_render render
15
15
 
16
16
  def initialize(tag_name, input, tokens)
17
17
  super
18
18
 
19
19
  raise 'Please enter a file path' if input.length <= 0
20
-
21
- @scss_file = strip_or_self(input)
22
20
  # File.exists? is file?
23
-
24
- @tag_name = tag_name
25
-
26
- # puts syntax_example
27
21
  end
28
22
 
29
23
  # def syntax_example
@@ -31,8 +25,6 @@ module Jekyll
31
25
  # end
32
26
 
33
27
  def render(context)
34
- # return '' unless context.registers[:page]['sri']
35
-
36
28
  cache_compiled_scss(@file, context, lambda {
37
29
  if context.nil? || context.registers[:site].nil?
38
30
  puts 'WARNING: There was no context, generate default site and context'
@@ -44,17 +36,20 @@ module Jekyll
44
36
  @sri_config = context.registers[:site].config['kw-sri'] || {}
45
37
  end
46
38
 
39
+ # Render the context with the base-class
47
40
  converter = site.find_converter_instance(Jekyll::Converters::Scss)
48
-
49
- # var scss = render(context)
50
- result = super_render(context) # super(context)
41
+ result = super(context) # super_render(context)
51
42
  scss = result.gsub(/^---.*---/m, '')
52
43
  data = converter.convert(scss)
53
44
 
45
+ # Get path out of the file object
54
46
  file = render_variable(context) || @file
55
47
  validate_file_name(file)
56
48
  path = locate_include_file(context, file, site.safe)
57
49
 
50
+ # Use default config for kw-sri if it is nil
51
+ @sri_config ||= Jekyll::KargWare::Integrity::Configuration::DEFAULT_CONFIG
52
+
58
53
  Integrity::Parser.new(@sri_config).calc_integrity(path, data)
59
54
  })
60
55
  end
@@ -74,15 +69,6 @@ module Jekyll
74
69
  @cached_scss[path] = compute.call
75
70
  end
76
71
  end
77
-
78
- # https://stackoverflow.com/a/1000975
79
- def strip_or_self(str)
80
- str.strip! || str
81
- end
82
-
83
- def tag_includes_dirs(context)
84
- [context.registers[:site].source].freeze
85
- end
86
72
  end
87
73
  end
88
74
  end
@@ -19,7 +19,7 @@ module Jekyll
19
19
  data_modified = add_source_mapping_url(filename, data)
20
20
 
21
21
  # Debuging, save rendered css file as tmp file
22
- File.open(".#{filename}.tmp", 'w') { |file| file.write(data_modified) } if @configuration.create_tmpfile
22
+ File.open("#{filename}.tmp", 'w') { |file| file.write(data_modified) } if @configuration.create_tmpfile
23
23
 
24
24
  case hash_type
25
25
  when 'sha256'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JekyllKwSri
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-kw-sri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Karg