Sha256: 9166d26e655c1e4aa33b7b3607d13d5af591a07c780e4cea425fefb659ce2af5
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
require 'polymer-rails/component' require "polymer-rails/processors/sprockets_processor" module Polymer module Rails module Processors class Component < Polymer::Rails::SprocketsProcessor def process inline_styles inline_javascripts require_imports @component.stringify end private def require_imports @component.html_imports.each do |import| @context.require_asset absolute_asset_path(import.attributes['href'].value) import.remove end end def inline_javascripts @component.javascripts.each do |script| @component.replace_node(script, 'script', asset_content(script.attributes['src'].value)) end end def inline_styles @component.stylesheets.each do |link| @component.replace_node(link, 'style', asset_content(link.attributes['href'].value)) end end def asset_content(file) asset_path = absolute_asset_path(file) asset = find_asset(asset_path) unless asset.blank? @context.depend_on_asset asset_path asset.to_s else nil end end def absolute_asset_path(file) search_file = file.sub(/^(\.\.\/)+/, '/').sub(/^\/*/, '') @@sprockets_env.paths.each do |path| file_list = Dir.glob( "#{File.absolute_path search_file, path }*") return file_list.first unless file_list.blank? end components = Dir.glob("#{File.absolute_path file, File.dirname(@context.pathname)}*") return components.blank? ? nil : components.first end def find_asset(asset_path) @@sprockets_env.find_asset(asset_path) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
polymer-rails-1.3.0 | lib/polymer-rails/processors/component.rb |
polymer-rails-1.2.4.1 | lib/polymer-rails/processors/component.rb |