Refactor: Use copy_asset() to copy html_static_path

This commit is contained in:
Takeshi KOMIYA 2016-07-03 16:43:18 +09:00
parent bb1e6f9044
commit 02dbf860c2
20 changed files with 26 additions and 9 deletions

View File

@ -33,7 +33,7 @@ from sphinx.util.osutil import SEP, os_path, relative_uri, ensuredir, \
movefile, copyfile
from sphinx.util.nodes import inline_all_toctrees
from sphinx.util.fileutil import copy_asset
from sphinx.util.matching import patmatch, compile_matchers, Matcher
from sphinx.util.matching import patmatch, Matcher
from sphinx.config import string_classes
from sphinx.locale import _, l_
from sphinx.search import js_index
@ -620,15 +620,14 @@ class StandaloneHTMLBuilder(Builder):
copy_static_entry(entry, path.join(self.outdir, '_static'),
self, ctx)
# then, copy over all user-supplied static files
staticentries = [path.join(self.confdir, spath)
for spath in self.config.html_static_path]
matchers = compile_matchers(self.config.exclude_patterns)
for entry in staticentries:
excluded = Matcher(self.config.exclude_patterns + ["**/.*"])
for static_path in self.config.html_static_path:
entry = path.join(self.confdir, static_path)
if not path.exists(entry):
self.warn('html_static_path entry %r does not exist' % entry)
continue
copy_static_entry(entry, path.join(self.outdir, '_static'), self,
ctx, exclude_matchers=matchers)
copy_asset(entry, path.join(self.outdir, '_static'), excluded,
context=ctx, renderer=self.templates)
# copy logo and favicon files if not already in static path
if self.config.html_logo:
logobase = path.basename(self.config.html_logo)

View File

@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
master_doc = 'index'
project = 'Sphinx'
version = '1.4.4'
html_static_path = ['static', 'subdir']
html_extra_path = ['extra', 'subdir']
exclude_patterns = ['**/_build', '**/.htpasswd']

View File

@ -0,0 +1 @@
{{ project }}-{{ version }}

View File

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 218 B

View File

@ -0,0 +1 @@
{{ project }}-{{ version }}

View File

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 218 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B

View File

@ -976,10 +976,23 @@ def test_jsmath(app, status, warning):
assert '<div class="math">\na + 1 &lt; b</div>' in content
@with_app(buildername='html', testroot='html_extra_path')
def test_html_extra_path(app, status, warning):
@with_app(buildername='html', testroot='html_assets')
def test_html_assets(app, status, warning):
app.builder.build_all()
# html_static_path
assert not (app.outdir / '_static' / '.htaccess').exists()
assert not (app.outdir / '_static' / '.htpasswd').exists()
assert (app.outdir / '_static' / 'API.html').exists()
assert (app.outdir / '_static' / 'API.html').text() == 'Sphinx-1.4.4'
assert (app.outdir / '_static' / 'css/style.css').exists()
assert (app.outdir / '_static' / 'rimg.png').exists()
assert not (app.outdir / '_static' / '_build/index.html').exists()
assert (app.outdir / '_static' / 'background.png').exists()
assert not (app.outdir / '_static' / 'subdir' / '.htaccess').exists()
assert not (app.outdir / '_static' / 'subdir' / '.htpasswd').exists()
# html_extra_path
assert (app.outdir / '.htaccess').exists()
assert not (app.outdir / '.htpasswd').exists()
assert (app.outdir / 'API.html_t').exists()