Class: Assetify::Pathfix
- Inherits:
-
Object
- Object
- Assetify::Pathfix
- Defined in:
- lib/assetify/asset/pathfix.rb
Overview
Attempt to fix assets in js/css for #image_url
Instance Attribute Summary collapse
-
#images ⇒ Object
readonly
Returns the value of attribute images.
Instance Method Summary collapse
- #fix ⇒ Object
-
#initialize(chunk, renderer = :erb, ns = nil) ⇒ Pathfix
constructor
A new instance of Pathfix.
- #replace(src) ⇒ Object
- #scan_images ⇒ Object
- #tmpl_chunk ⇒ Object
Constructor Details
#initialize(chunk, renderer = :erb, ns = nil) ⇒ Pathfix
Returns a new instance of Pathfix.
6 7 8 9 10 11 |
# File 'lib/assetify/asset/pathfix.rb', line 6 def initialize(chunk, renderer = :erb, ns = nil) @chunk = chunk @renderer = renderer @ns = ns @images = scan_images end |
Instance Attribute Details
#images ⇒ Object (readonly)
Returns the value of attribute images.
13 14 15 |
# File 'lib/assetify/asset/pathfix.rb', line 13 def images @images end |
Instance Method Details
#fix ⇒ Object
28 29 30 31 32 33 |
# File 'lib/assetify/asset/pathfix.rb', line 28 def fix @images.each do |path| @chunk["url(#{path})"] = replace path.split('/').last end @renderer != :erb ? tmpl_chunk : @chunk end |
#replace(src) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/assetify/asset/pathfix.rb', line 19 def replace(src) fpath = @ns ? "#{@ns}/#{src}" : src if @renderer == :erb "url('<%= image_path('#{fpath}') %>')" else "image-url('#{fpath}')" end end |
#scan_images ⇒ Object
15 16 17 |
# File 'lib/assetify/asset/pathfix.rb', line 15 def scan_images @chunk.scan(%r{url\(([a-zA-Z0-9/\_\-\.]*\.\w+)\)}xo).flatten end |
#tmpl_chunk ⇒ Object
35 36 37 38 39 40 |
# File 'lib/assetify/asset/pathfix.rb', line 35 def tmpl_chunk require 'sass/css' Sass::CSS.new(@chunk).render(@renderer) rescue Sass::SyntaxError => e @error = e end |