Class: Pakyow::Assets::Pack
- Inherits:
-
Object
- Object
- Pakyow::Assets::Pack
- Defined in:
- lib/pakyow/assets/pack.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#public_path ⇒ Object
readonly
Returns the value of attribute public_path.
Instance Method Summary collapse
- #<<(asset) ⇒ Object
- #finalize ⇒ Object
- #fingerprint ⇒ Object
-
#initialize(name, config, prefix: "/") ⇒ Pack
constructor
A new instance of Pack.
- #javascripts ⇒ Object
- #javascripts? ⇒ Boolean
- #packed(path) ⇒ Object
- #public_css_path ⇒ Object
- #public_js_path ⇒ Object
- #stylesheets ⇒ Object
- #stylesheets? ⇒ Boolean
Constructor Details
#initialize(name, config, prefix: "/") ⇒ Pack
Returns a new instance of Pack.
18 19 20 21 22 23 24 25 |
# File 'lib/pakyow/assets/pack.rb', line 18 def initialize(name, config, prefix: "/") @name, @config = name, config @assets = [] @packed = { js: [], css: [] } @public_path = String.normalize_path( File.join(config.prefix, prefix, "packs", name.to_s) ) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/pakyow/assets/pack.rb', line 16 def name @name end |
#public_path ⇒ Object (readonly)
Returns the value of attribute public_path.
16 17 18 |
# File 'lib/pakyow/assets/pack.rb', line 16 def public_path @public_path end |
Instance Method Details
#<<(asset) ⇒ Object
41 42 43 |
# File 'lib/pakyow/assets/pack.rb', line 41 def <<(asset) @assets << asset.disable_source_map end |
#finalize ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pakyow/assets/pack.rb', line 27 def finalize tap do if @config.fingerprint extension = File.extname(@public_path) @public_path = File.join( File.dirname(@public_path), File.basename(@public_path, extension) + "__" + fingerprint + extension ) end pack_assets! end end |
#fingerprint ⇒ Object
69 70 71 72 73 |
# File 'lib/pakyow/assets/pack.rb', line 69 def fingerprint @assets.flat_map(&:fingerprint).sort.each_with_object(Digest::MD5.new) { |fingerprint, digest| digest.update(fingerprint) }.hexdigest end |
#javascripts ⇒ Object
53 54 55 |
# File 'lib/pakyow/assets/pack.rb', line 53 def javascripts @packed[:js] end |
#javascripts? ⇒ Boolean
61 62 63 |
# File 'lib/pakyow/assets/pack.rb', line 61 def javascripts? javascripts.any? end |
#packed(path) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/pakyow/assets/pack.rb', line 45 def packed(path) if path.start_with?(@public_path + ".") @packed[File.extname(path)[1..-1].to_sym] else nil end end |
#public_css_path ⇒ Object
79 80 81 |
# File 'lib/pakyow/assets/pack.rb', line 79 def public_css_path @public_path + ".css" end |
#public_js_path ⇒ Object
75 76 77 |
# File 'lib/pakyow/assets/pack.rb', line 75 def public_js_path @public_path + ".js" end |
#stylesheets ⇒ Object
57 58 59 |
# File 'lib/pakyow/assets/pack.rb', line 57 def stylesheets @packed[:css] end |
#stylesheets? ⇒ Boolean
65 66 67 |
# File 'lib/pakyow/assets/pack.rb', line 65 def stylesheets? stylesheets.any? end |