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.
-
#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.
Instance Method Summary collapse
- #charset ⇒ Object
- #content_type ⇒ Object
- #ext ⇒ Object
-
#hexdigest ⇒ Object
(also: #etag)
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.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/condenser/export.rb', line 6 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] end |
Instance Attribute Details
#content_types ⇒ Object (readonly)
Returns the value of attribute content_types.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def content_types @content_types end |
#digest ⇒ Object (readonly)
Returns the value of attribute digest.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def digest @digest end |
#digest_name ⇒ Object (readonly)
Returns the value of attribute digest_name.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def digest_name @digest_name end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def filename @filename end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def source @source end |
#sourcemap ⇒ Object (readonly)
Returns the value of attribute sourcemap.
4 5 6 |
# File 'lib/condenser/export.rb', line 4 def sourcemap @sourcemap end |
Instance Method Details
#charset ⇒ Object
38 39 40 |
# File 'lib/condenser/export.rb', line 38 def charset @source.encoding.name.downcase end |
#content_type ⇒ Object
21 22 23 |
# File 'lib/condenser/export.rb', line 21 def content_type @content_types.last end |
#ext ⇒ Object
73 74 75 |
# File 'lib/condenser/export.rb', line 73 def ext File.extname(filename) end |
#hexdigest ⇒ Object Also known as: etag
Public: Returns String hexdigest of source.
43 44 45 |
# File 'lib/condenser/export.rb', line 43 def hexdigest @digest.unpack('H*'.freeze).first end |
#integrity ⇒ Object
48 49 50 |
# File 'lib/condenser/export.rb', line 48 def integrity "#{@digest_name}-#{[@digest].pack('m0')}" end |
#length ⇒ Object Also known as: size
29 30 31 |
# File 'lib/condenser/export.rb', line 29 def length @source.bytesize end |
#path ⇒ Object
17 18 19 |
# File 'lib/condenser/export.rb', line 17 def path filename.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" } end |
#to_json ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/condenser/export.rb', line 52 def to_json { 'path' => path, 'size' => size, 'digest' => hexdigest, 'integrity' => integrity } end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/condenser/export.rb', line 25 def to_s @source end |
#write(output_directory) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/condenser/export.rb', line 61 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 |