Skip to content

Commit

Permalink
Add assets property to documents
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Dec 6, 2014
1 parent 2dfd4ef commit 85189b9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -198,7 +198,7 @@ pep8: .depends-ci

.PHONY: pep257
pep257: .depends-ci
$(PEP257) $(PACKAGE) --ignore=E501,D102
$(PEP257) $(PACKAGE) --ignore=D102

.PHONY: pylint
pylint: .depends-dev
Expand Down
10 changes: 9 additions & 1 deletion doorstop/core/document.py
Expand Up @@ -22,6 +22,7 @@ class Document(BaseValidatable, BaseFileObject): # pylint: disable=R0902

CONFIG = '.doorstop.yml'
SKIP = '.doorstop.skip' # indicates this document should be skipped
ASSETS = 'assets'
INDEX = 'index.yml'

DEFAULT_PREFIX = Prefix('REQ')
Expand Down Expand Up @@ -209,6 +210,13 @@ def config(self):
"""Get the path to the document's file."""
return os.path.join(self.path, Document.CONFIG)

@property
def assets(self):
"""Get the path to the document's assets if they exist else `None`."""
path = os.path.join(self.path, Document.ASSETS)
if os.path.isdir(path):
return path

@property
@auto_load
def prefix(self):
Expand Down Expand Up @@ -306,7 +314,7 @@ def skip(self):
def index(self):
"""Get the path to the document's index if it exists else `None`."""
path = os.path.join(self.path, Document.INDEX)
if os.path.exists(path):
if os.path.isfile(path):
return path

@index.setter
Expand Down
2 changes: 2 additions & 0 deletions doorstop/core/publisher.py
Expand Up @@ -53,6 +53,8 @@ def publish(obj, path, ext=None, linkify=None, index=None, **kwargs):
log.info("publishing to {}...".format(path2))
lines = publish_lines(obj2, ext, linkify=linkify, **kwargs)
common.write_lines(lines, path2)
if obj2.assets:
common.copy(obj2.assets, os.path.join(path2, obj2.ASSETS))

# Create index
if index and count:
Expand Down
2 changes: 2 additions & 0 deletions doorstop/core/test/__init__.py
Expand Up @@ -110,6 +110,7 @@ class MockDataMixIn: # pylint: disable=W0232,R0903
mock_document = MagicMock()
mock_document.prefix = 'MOCK'
mock_document.items = []
mock_document.assets = None
mock_tree = MagicMock()
mock_tree.documents = [mock_document]

Expand Down Expand Up @@ -151,6 +152,7 @@ class MockDataMixIn: # pylint: disable=W0232,R0903
_file="links: [sys1]\ntext: 'Heading 2'\nlevel: 2.1.0\n"
"normative: false"),
]
document.assets = None

item3 = MockItem('path/to/req4.yml', _file=(
"links: [sys4]" + '\n'
Expand Down
2 changes: 1 addition & 1 deletion doorstop/core/test/test_document.py
Expand Up @@ -224,7 +224,7 @@ def test_next_number_server(self):
def test_index_get(self):
"""Verify a document's index can be retrieved."""
self.assertIs(None, self.document.index)
with patch('os.path.exists', Mock(return_value=True)):
with patch('os.path.isfile', Mock(return_value=True)):
path = os.path.join(self.document.path, self.document.INDEX)
self.assertEqual(path, self.document.index)

Expand Down

0 comments on commit 85189b9

Please sign in to comment.