Class: Jekyll::KargWare::Integrity::Parser
- Inherits:
-
Object
- Object
- Jekyll::KargWare::Integrity::Parser
- Defined in:
- lib/jekyll-kw-sri/parser.rb
Overview
jekyll-kw-sri parser class
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #add_source_mapping_url(filename, data) ⇒ Object
- #calc_integrity(filename, data) ⇒ Object
-
#initialize(options = {}) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(options = {}) ⇒ Parser
Returns a new instance of Parser.
12 13 14 |
# File 'lib/jekyll-kw-sri/parser.rb', line 12 def initialize( = {}) @configuration = Configuration.new() end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/jekyll-kw-sri/parser.rb', line 10 def configuration @configuration end |
Instance Method Details
#add_source_mapping_url(filename, data) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/jekyll-kw-sri/parser.rb', line 36 def add_source_mapping_url(filename, data) if @configuration.write_source_mapping_url base = File.basename(filename) base = base.sub! 'scss', 'css' data + "\n/*# sourceMappingURL=#{base}.map */" else data end end |
#calc_integrity(filename, data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/jekyll-kw-sri/parser.rb', line 16 def calc_integrity(filename, data) hash_type = @configuration.hash_type data_modified = add_source_mapping_url(filename, data) # Debuging, save rendered css file as tmp file File.open("#{filename}.tmp", 'w') { |file| file.write(data_modified) } if @configuration.create_tmpfile case hash_type when 'sha256' "sha256-#{Digest::SHA256.base64digest data_modified}" when 'sha384' "sha384-#{Digest::SHA384.base64digest data_modified}" when 'sha512' "sha512-#{Digest::SHA512.base64digest data_modified}" else raise Jekyll::KargWare::Integrity::InvalidHashTypeException, "The type of the hash '#{hash_type}' is invalid!'" end end |