Sha256: 70b3dbc9b5fc4c33b1764bb828d3bd2803c127a775187970a5c69ddd61f5e936

Contents?: true

Size: 844 Bytes

Versions: 12

Compression:

Stored size: 844 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)
        temp = paths.map{|n| n[node].to_s.gsub(/\?[^\?]*$/, '') }
        temp.select{|n| n && n =~ /\w/ && n.internal_path? && !n.embedded? }
      end
    end 
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
trackman-0.5.4 lib/trackman/assets/html_asset.rb
trackman-0.5.3 lib/trackman/assets/html_asset.rb
trackman-0.5.2 lib/trackman/assets/html_asset.rb
trackman-0.5.1 lib/trackman/assets/html_asset.rb
trackman-0.5.0 lib/trackman/assets/html_asset.rb
trackman-0.4.8 lib/trackman/assets/html_asset.rb
trackman-0.4.7 lib/trackman/assets/html_asset.rb
trackman-0.4.6 lib/trackman/assets/html_asset.rb
trackman-0.4.5 lib/trackman/assets/html_asset.rb
trackman-0.4.4 lib/trackman/assets/html_asset.rb
trackman-0.4.3 lib/trackman/assets/html_asset.rb
trackman-0.4.2 lib/trackman/assets/html_asset.rb