Class: Condenser::Export

Inherits:
Object
  • Object
show all
Defined in:
lib/condenser/export.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typesObject (readonly)

Returns the value of attribute content_types.



4
5
6
# File 'lib/condenser/export.rb', line 4

def content_types
  @content_types
end

#digestObject (readonly)

Returns the value of attribute digest.



4
5
6
# File 'lib/condenser/export.rb', line 4

def digest
  @digest
end

#digest_nameObject (readonly)

Returns the value of attribute digest_name.



4
5
6
# File 'lib/condenser/export.rb', line 4

def digest_name
  @digest_name
end

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/condenser/export.rb', line 4

def filename
  @filename
end

#sourceObject (readonly)

Returns the value of attribute source.



4
5
6
# File 'lib/condenser/export.rb', line 4

def source
  @source
end

#sourcemapObject (readonly)

Returns the value of attribute sourcemap.



4
5
6
# File 'lib/condenser/export.rb', line 4

def sourcemap
  @sourcemap
end

Instance Method Details

#charsetObject



38
39
40
# File 'lib/condenser/export.rb', line 38

def charset
  @source.encoding.name.downcase
end

#content_typeObject



21
22
23
# File 'lib/condenser/export.rb', line 21

def content_type
  @content_types.last
end

#extObject



73
74
75
# File 'lib/condenser/export.rb', line 73

def ext
  File.extname(filename)
end

#hexdigestObject 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

#integrityObject



48
49
50
# File 'lib/condenser/export.rb', line 48

def integrity
  "#{@digest_name}-#{[@digest].pack('m0')}"
end

#lengthObject Also known as: size



29
30
31
# File 'lib/condenser/export.rb', line 29

def length
  @source.bytesize
end

#pathObject



17
18
19
# File 'lib/condenser/export.rb', line 17

def path
  filename.sub(/\.(\w+)$/) { |ext| "-#{etag}#{ext}" }
end

#to_jsonObject



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_sObject



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