class Polymer::Rails::Processors::Component

Public Instance Methods

process() click to toggle source
# File lib/polymer-rails/processors/component.rb, line 9
def process
  inline_styles
  inline_javascripts
  require_imports
  @component.stringify
end

Private Instance Methods

absolute_asset_path(file) click to toggle source
# File lib/polymer-rails/processors/component.rb, line 48
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
asset_content(file) click to toggle source
# File lib/polymer-rails/processors/component.rb, line 37
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
find_asset(asset_path) click to toggle source
# File lib/polymer-rails/processors/component.rb, line 58
def find_asset(asset_path)
  @@sprockets_env.find_asset(asset_path)
end
inline_javascripts() click to toggle source
# File lib/polymer-rails/processors/component.rb, line 25
def inline_javascripts
  @component.javascripts.each do |script|
    @component.replace_node(script, 'script', asset_content(script.attributes['src'].value))
  end
end
inline_styles() click to toggle source
# File lib/polymer-rails/processors/component.rb, line 31
def inline_styles
  @component.stylesheets.each do |link|
    @component.replace_node(link, 'style', asset_content(link.attributes['href'].value))
  end
end
require_imports() click to toggle source
# File lib/polymer-rails/processors/component.rb, line 18
def require_imports
  @component.html_imports.each do |import|
    @context.require_asset absolute_asset_path(import.attributes['href'].value)
    import.remove
  end
end