Sha256: 9ebe6aae528d5d8707dbe8ba8ce110d5202893b60b7a99a0e0dfad89b1bd5dee

Contents?: true

Size: 808 Bytes

Versions: 4

Compression:

Stored size: 808 Bytes

Contents

require 'nokogiri'
module Trackman
  module Assets
    class HtmlAsset < Asset
      include Components::CompositeAsset

      def document
        @doc ||= Nokogiri::HTML(data)     
      end  
      
      def img_paths        
        @images_paths ||= refine_path(document.css('img'), 'src')
      end
      def js_paths
        @js_paths ||= refine_path(document.xpath('//script'), 'src')
      end
      def css_paths
        @css_paths ||= refine_path(document.xpath('//link[@type="text/css"]'), 'href')
      end

      def children_paths
         @children_paths ||= img_paths + js_paths + css_paths + inner_css_paths
      end

      def refine_path(paths, node)
        paths.map{|n| n[node].to_s.gsub(/\?[^\?]*$/, '') }.select{|n| n && n =~ /\w/ && n.internal_path? }
      end
    end 
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trackman-0.4.1 lib/trackman/assets/html_asset.rb
trackman-0.4.0 lib/trackman/assets/html_asset.rb
trackman-0.3.5 lib/trackman/assets/html_asset.rb
trackman-0.3.4 lib/trackman/assets/html_asset.rb