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