Class: Pakyow::Assets::PackedAssets
- Inherits:
-
Object
- Object
- Pakyow::Assets::PackedAssets
- Extended by:
- Forwardable
- Defined in:
- lib/pakyow/assets/pack.rb
Instance Attribute Summary collapse
-
#assets ⇒ Object
readonly
Returns the value of attribute assets.
-
#public_path ⇒ Object
readonly
Returns the value of attribute public_path.
Instance Method Summary collapse
- #bytesize ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(assets, public_path, config, name) ⇒ PackedAssets
constructor
A new instance of PackedAssets.
- #initialize_copy(_) ⇒ Object
- #mime_suffix ⇒ Object
- #mime_type ⇒ Object
- #read ⇒ Object
- #source_map ⇒ Object
- #source_map? ⇒ Boolean
- #source_mapping_url ⇒ Object
Constructor Details
#initialize(assets, public_path, config, name) ⇒ PackedAssets
Returns a new instance of PackedAssets.
102 103 104 |
# File 'lib/pakyow/assets/pack.rb', line 102 def initialize(assets, public_path, config, name) @assets, @public_path, @config, @name = assets, public_path, config, name end |
Instance Attribute Details
#assets ⇒ Object (readonly)
Returns the value of attribute assets.
100 101 102 |
# File 'lib/pakyow/assets/pack.rb', line 100 def assets @assets end |
#public_path ⇒ Object (readonly)
Returns the value of attribute public_path.
100 101 102 |
# File 'lib/pakyow/assets/pack.rb', line 100 def public_path @public_path end |
Instance Method Details
#bytesize ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/pakyow/assets/pack.rb', line 142 def bytesize bytes = @assets.map(&:bytesize).inject(&:+) if @config.source_maps && source_map? bytes += source_mapping_url.bytesize end bytes end |
#each(&block) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/pakyow/assets/pack.rb', line 120 def each(&block) @assets.each do |asset| asset.each(&block) end if @config.source_maps && source_map? yield source_mapping_url end end |
#initialize_copy(_) ⇒ Object
106 107 108 109 110 |
# File 'lib/pakyow/assets/pack.rb', line 106 def initialize_copy(_) super @assets = @assets.map(&:dup) end |
#mime_suffix ⇒ Object
116 117 118 |
# File 'lib/pakyow/assets/pack.rb', line 116 def mime_suffix @assets.first&.mime_suffix end |
#mime_type ⇒ Object
112 113 114 |
# File 'lib/pakyow/assets/pack.rb', line 112 def mime_type @assets.first&.mime_type end |
#read ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/pakyow/assets/pack.rb', line 130 def read String.new.tap do |packed_asset| @assets.each do |asset| packed_asset << asset.read end if @config.source_maps && source_map? packed_asset << source_mapping_url end end end |
#source_map ⇒ Object
152 153 154 155 156 157 158 159 160 |
# File 'lib/pakyow/assets/pack.rb', line 152 def source_map @assets.select(&:source_map?).inject( SourceMap.new( file: File.basename(@public_path) ) ) { |merged, asset| merged.merge(asset.source_map) } end |
#source_map? ⇒ Boolean
162 163 164 |
# File 'lib/pakyow/assets/pack.rb', line 162 def source_map? @assets.any?(&:source_map?) end |
#source_mapping_url ⇒ Object
166 167 168 |
# File 'lib/pakyow/assets/pack.rb', line 166 def source_mapping_url SourceMap.mapping_url(path: @public_path, type: @assets.first.mime_suffix) end |