Skip to content

Commit

Permalink
Merge pull request #15 from kallimachos/repeat-option
Browse files Browse the repository at this point in the history
Add image repeat option
  • Loading branch information
kallimachos authored Sep 15, 2016
2 parents 6978ca3 + 1ff9142 commit 30e95c9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
8 changes: 8 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ sphinxmark_div (string)

openstackdocstheme -> ``sphinxmark_div = 'docs-body'``

sphinxmark_repeat (bool)
- ``True`` - image repeats down the page
- ``False`` - image appears once at top of page
- Default = True

``sphinxmark_repeat = True``

sphinxmark_image (string)
- image file in ``html_static_path`` directory to use as watermark
- ``text`` selects the text-based watermark specified in the
Expand Down Expand Up @@ -131,6 +138,7 @@ sphinxmark_text_spacing (int)

``sphinxmark_text_spacing = 400``


Troubleshooting
~~~~~~~~~~~~~~~
You can enable debugging output for sphinxmark by raising the output verbosity
Expand Down
8 changes: 7 additions & 1 deletion sphinxmark/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,12 @@ def watermark(app, env):
else:
div = app.config.sphinxmark_div

css = template('watermark', div=div, image=imagefile)
if app.config.sphinxmark_repeat is True:
repeat = 'repeat-y'
else:
repeat = 'no-repeat'

css = template('watermark', div=div, image=imagefile, repeat=repeat)
app.debug('[sphinxmark] Template: ' + css)
cssname = 'sphinxmark.css'
cssfile = os.path.join(buildpath, cssname)
Expand All @@ -116,6 +121,7 @@ def setup(app):
try:
app.add_config_value('sphinxmark_enable', False, 'html')
app.add_config_value('sphinxmark_div', 'default', 'html')
app.add_config_value('sphinxmark_repeat', True, 'html')
app.add_config_value('sphinxmark_image', 'default', 'html')
app.add_config_value('sphinxmark_text', 'default', 'html')
app.add_config_value('sphinxmark_text_color', (255, 0, 0), 'html')
Expand Down
2 changes: 1 addition & 1 deletion sphinxmark/watermark.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
div.{{div}} {
background-image: url("{{ image }}") !important;
background-repeat: repeat-y !important;
background-repeat: {{ repeat }} !important;
background-position: center top !important;
}
1 change: 1 addition & 0 deletions tests/marktest/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
# Options for sphinxmark
sphinxmark_enable = True
# sphinxmark_div = 'default'
# sphinxmark_repeat = True
# sphinxmark_image = 'default'
# sphinxmark_text = 'default'
# sphinxmark_text_color = (255, 0, 0)
Expand Down
29 changes: 29 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# defaults = {'sphinxmark_enable': True,
# 'sphinxmark_div': 'default',
# 'sphinxmark_repeat': True,
# 'sphinxmark_image': 'default',
# 'sphinxmark_text': 'default',
# 'sphinxmark_text_color': (255, 0, 0),
Expand All @@ -27,6 +28,7 @@ def test_defaults():
app = MakeApp(srcdir='tests/marktest', copy_srcdir_to_tmpdir=True)
app.builder.build_all()
assert app.config.sphinxmark_div == 'default'
assert app.config.sphinxmark_repeat is True
assert app.config.sphinxmark_image == 'default'
assert app.config.sphinxmark_text == 'default'
assert app.config.sphinxmark_text_color == (255, 0, 0)
Expand All @@ -41,6 +43,33 @@ def test_defaults():
assert ('url("watermark-draft.png")') in css


def test_repeat():
"""Text repeat."""
app = MakeApp(srcdir='tests/marktest', copy_srcdir_to_tmpdir=True)
app.builder.build_all()
assert app.config.sphinxmark_repeat is True

html = (app.outdir / htmlfile).read_text()
assert htmlresult in html

css = (app.outdir / cssfile).read_text()
assert ('background-repeat: repeat-y !important;') in css


def test_no_repeat():
"""Text no repeat."""
app = MakeApp(srcdir='tests/marktest', copy_srcdir_to_tmpdir=True,
confoverrides={'sphinxmark_repeat': False})
app.builder.build_all()
assert app.config.sphinxmark_repeat is False

html = (app.outdir / htmlfile).read_text()
assert htmlresult in html

css = (app.outdir / cssfile).read_text()
assert ('background-repeat: no-repeat !important;') in css


def test_textmark():
"""Test textmark."""
app = MakeApp(srcdir='tests/marktest', copy_srcdir_to_tmpdir=True,
Expand Down

0 comments on commit 30e95c9

Please sign in to comment.