Beispiel #1
0
  def LoadImage(self, abs_path):
    if abs_path in self.loaded_images:
      return self.loaded_images[abs_path]

    if not os.path.exists(abs_path):
      raise module.DepsException("url('%s') did not exist" % abs_path)

    res = self.FindResourceGivenAbsolutePath(abs_path, binary=True)
    if res is None:
      raise module.DepsException("url('%s') was not in search path" % abs_path)

    image = style_sheet_module.Image(res)
    self.loaded_images[abs_path] = image
    return image
Beispiel #2
0
  def LoadModule(self, module_name=None, module_filename=None,
                 excluded_scripts=None):
    assert bool(module_name) ^ bool(module_filename), (
        'Must provide either module_name or module_filename.')
    if module_filename:
      resource = self.FindResource(module_filename)
      if not resource:
        raise Exception('Could not find %s in %s' % (
            module_filename, repr(self.source_paths)))
      module_name = resource.name
    else:
      resource = None  # Will be set if we end up needing to load.

    if module_name in self.loaded_modules:
      assert self.loaded_modules[module_name].contents
      return self.loaded_modules[module_name]

    if not resource:  # happens when module_name was given
      resource = self.FindModuleResource(module_name)
      if not resource:
        raise module.DepsException('No resource for module "%s"' % module_name)

    m = html_module.HTMLModule(self, module_name, resource)
    self.loaded_modules[module_name] = m

    # Fake it, this is probably either polymer.min.js or platform.js which are
    # actually .js files....
    if resource.absolute_path.endswith('.js'):
      return m

    m.Parse(excluded_scripts)
    m.Load(excluded_scripts)
    return m
Beispiel #3
0
def GetInlineScriptContentWithPolymerizingApplied(inline_script):
    polymer_element_name = GetPolymerElementNameFromOpenTags(
        inline_script.open_tags)
    if polymer_element_name is None:
        raise module.DepsException(
            'Tagless Polymer() call must be made inside a <polymer-element> tag'
        )

    return UpdatePolymerCallsGivenElementName(inline_script.stripped_contents,
                                              polymer_element_name)
def _HRefToResource(loader, module_name, module_dir_name, href,
                    tag_for_err_msg):
    if href[0] == '/':
        resource = loader.FindResourceGivenRelativePath(
            os.path.normpath(href[1:]))
    else:
        abspath = os.path.normpath(
            os.path.join(module_dir_name, os.path.normpath(href)))
        resource = loader.FindResourceGivenAbsolutePath(abspath)

    if not resource:
        raise module.DepsException('In %s, the %s cannot be loaded because '
                                   'it is not in the search path' %
                                   (module_name, tag_for_err_msg))
    try:
        resource.contents
    except:
        raise module.DepsException('In %s, %s points at a nonexistent file ' %
                                   (module_name, tag_for_err_msg))
    return resource
Beispiel #5
0
  def LoadStyleSheet(self, name):
    if name in self.loaded_style_sheets:
      return self.loaded_style_sheets[name]

    resource = self._FindResourceGivenNameAndSuffix(
        name, '.css', return_resource=True)
    if not resource:
      raise module.DepsException(
          'Could not find a file for stylesheet %s' % name)

    style_sheet = style_sheet_module.StyleSheet(self, name, resource)
    style_sheet.load()
    self.loaded_style_sheets[name] = style_sheet
    return style_sheet
Beispiel #6
0
    def LoadRawScript(self, relative_raw_script_path):
        resource = None
        for source_path in self.source_paths:
            possible_absolute_path = os.path.join(
                source_path, os.path.normpath(relative_raw_script_path))
            if os.path.exists(possible_absolute_path):
                resource = resource_module.Resource(source_path,
                                                    possible_absolute_path)
                break
        if not resource:
            raise module.DepsException(
                'Could not find a file for raw script %s in %s' %
                (relative_raw_script_path, self.source_paths))
        assert relative_raw_script_path == resource.unix_style_relative_path, (
            'Expected %s == %s' %
            (relative_raw_script_path, resource.unix_style_relative_path))

        if resource.absolute_path in self.loaded_raw_scripts:
            return self.loaded_raw_scripts[resource.absolute_path]

        raw_script = module.RawScript(resource)
        self.loaded_raw_scripts[resource.absolute_path] = raw_script
        return raw_script
Beispiel #7
0
 def __init__(self, soup):
     if not soup:
         raise module.DepsException('InlineScript created without soup')
     self._soup = soup
     self._stripped_contents = None
     self._open_tags = None
 def __init__(self, soup):
   if not soup:
     raise module.DepsException('Script object created without soup')
   self._soup = soup