mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor: Use copy_asset() to copy html_static_path
This commit is contained in:
parent
bb1e6f9044
commit
02dbf860c2
@ -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)
|
||||
|
@ -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']
|
1
tests/roots/test-html_assets/extra/API.html_t
Normal file
1
tests/roots/test-html_assets/extra/API.html_t
Normal file
@ -0,0 +1 @@
|
||||
{{ project }}-{{ version }}
|
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 218 B |
1
tests/roots/test-html_assets/static/API.html_t
Normal file
1
tests/roots/test-html_assets/static/API.html_t
Normal file
@ -0,0 +1 @@
|
||||
{{ project }}-{{ version }}
|
0
tests/roots/test-html_assets/static/css/style.css
Normal file
0
tests/roots/test-html_assets/static/css/style.css
Normal file
Before Width: | Height: | Size: 218 B After Width: | Height: | Size: 218 B |
BIN
tests/roots/test-html_assets/subdir/background.png
Normal file
BIN
tests/roots/test-html_assets/subdir/background.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 218 B |
@ -976,10 +976,23 @@ def test_jsmath(app, status, warning):
|
||||
assert '<div class="math">\na + 1 < 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()
|
||||
|
Loading…
Reference in New Issue
Block a user