Class: Condenser::Export
- Inherits:
-
Object
- Object
- Condenser::Export
- Defined in:
- lib/condenser/export.rb
Instance Attribute Summary collapse
-
#content_types ⇒ Object
readonly
Returns the value of attribute content_types.
-
#digest ⇒ Object
readonly
Returns the value of attribute digest.
-
#digest_name ⇒ Object
readonly
Returns the value of attribute digest_name.
-
#etag ⇒ Object
readonly
Returns the value of attribute etag.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#sourcemap ⇒ Object
readonly
Returns the value of attribute sourcemap.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #charset ⇒ Object
- #content_type ⇒ Object
- #ext ⇒ Object
-
#hexdigest ⇒ Object
Public: Returns String hexdigest of source.
-
#initialize(env, input = {}) ⇒ Export
constructor
A new instance of Export.
- #integrity ⇒ Object
- #length ⇒ Object (also: #size)
- #path ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
- #write(output_directory) ⇒ Object
Constructor Details
#initialize(env, input = {}) ⇒ Export
Returns a new instance of Export.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/condenser/export.rb', line 8 def initialize(env, input={}) @environment = env @source = input[:source] @sourcemap = input[:map] @filename = input[:filename] @content_types = input[:content_types] @digest = input[:digest] @digest_name = input[:digest_name] @etag = input[:etag] @type = input[:type] end |
Instance Attribute Details
#content_types ⇒ Object (readonly)
Returns the value of attribute content_types.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def content_types @content_types end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def digest @digest end |
#digest_name ⇒ Object (readonly)
Returns the value of attribute digest_name.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def digest_name @digest_name end |
#etag ⇒ Object (readonly)
Returns the value of attribute etag.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def etag @etag end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def filename @filename end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def source @source end |
#sourcemap ⇒ Object (readonly)
Returns the value of attribute sourcemap.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def sourcemap @sourcemap end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/condenser/export.rb', line 6 def type @type end |
Instance Method Details
#charset ⇒ Object
42 43 44 |
# File 'lib/condenser/export.rb', line 42 def charset @source.encoding.name.downcase end |
#content_type ⇒ Object
25 26 27 |
# File 'lib/condenser/export.rb', line 25 def content_type @content_types.last end |
#ext ⇒ Object
78 79 80 |
# File 'lib/condenser/export.rb', line 78 def ext File.extname(filename) end |
#hexdigest ⇒ Object
Public: Returns String hexdigest of source.
47 48 49 |
# File 'lib/condenser/export.rb', line 47 def hexdigest @digest.unpack('H*'.freeze).first end |
#integrity ⇒ Object
51 52 53 |
# File 'lib/condenser/export.rb', line 51 def integrity "#{@digest_name}-#{[@digest].pack('m0')}" end |
#length ⇒ Object Also known as: size
33 34 35 |
# File 'lib/condenser/export.rb', line 33 def length @source.bytesize end |
#path ⇒ Object
21 22 23 |
# File 'lib/condenser/export.rb', line 21 def path filename.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" } end |
#to_json ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/condenser/export.rb', line 55 def to_json { path: path, etag: etag, type: type, size: size, digest: hexdigest, integrity: integrity } end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/condenser/export.rb', line 29 def to_s @source end |
#write(output_directory) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/condenser/export.rb', line 66 def write(output_directory) files = @environment.writers_for_mime_type(content_type).map do |writer| if writer.exist?(self) @environment.logger.debug "Skipping #{ self.path }, already exists" else @environment.logger.info "Writing #{ self.path }" writer.call(output_directory, self) end end files.flatten.compact end |