Skip to content

Commit

Permalink
Rename OrgNode.props attribute to .properties
Browse files Browse the repository at this point in the history
  • Loading branch information
jlumpe committed Sep 4, 2019
1 parent c1ccfc4 commit fae1add
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion docs/ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ref
A unique string ID assigned by Org mode during the export process. Can be used
to look up targets of internal links.

props
properties
A dictionary of named properties that depends on the node's type. See Org
mode's documentation on the
`Element API <https://orgmode.org/worg/dev/org-element-api.html>`_ for a
Expand Down
2 changes: 1 addition & 1 deletion docs/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Check third headline's properties to get the TODO information and tags:


>>> hl3 = doc.root[3]
>>> hl3.props
>>> hl3.properties
{'title': ['A headline with a TODO and tags'],
'deadline': OrgTimestampNode(type='timestamp'),
'post-affiliated': 301,
Expand Down
26 changes: 13 additions & 13 deletions pyorg/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class OrgNode:
type: .OrgNodeType
Node type, obtained from `org-element-type`.
props : dict
properties : dict
Dictionary of property values, obtained from `org-element-property`.
contents : list
List of contents (org nodes or strings), obtained from
Expand All @@ -210,14 +210,14 @@ class OrgNode:

is_outline = False

def __init__(self, type_, props=None, contents=None, keywords=None, ref=None, meta=None):
def __init__(self, type_, properties=None, contents=None, keywords=None, ref=None, meta=None):
if isinstance(type_, str):
type_ = ORG_NODE_TYPES[type_]
if not isinstance(type_, OrgNodeType):
raise TypeError(type(type_))
self.type = type_

self.props = dict(props or {})
self.properties = dict(properties or {})
self.keywords = dict(keywords or {})
self.ref = ref
self.contents = list(contents or [])
Expand All @@ -227,7 +227,7 @@ def __copy__(self, deep=False):
cp = deepcopy if deep else copy
return type(self)(
self.type,
props=cp(self.props),
properties=cp(self.properties),
contents=cp(self.contents),
keywords=cp(self.keywords),
ref=self.ref,
Expand Down Expand Up @@ -261,7 +261,7 @@ def _iter_children_recursive(obj):
@property
def children(self):
"""Iterator over all child AST nodes (in contents or keyword/property values."""
for collection in (self.props.values(), self.keywords.values(), self.contents):
for collection in (self.properties.values(), self.keywords.values(), self.contents):
yield from self._iter_children_recursive(collection)

def __repr__(self):
Expand All @@ -277,7 +277,7 @@ def __getitem__(self, key):
if isinstance(key, int):
return self.contents[key]
elif isinstance(key, str):
return self.props[key]
return self.properties[key]
else:
raise TypeError('Expected str or int, got %r' % type(key))

Expand All @@ -292,8 +292,8 @@ def dump(self, index=None, properties=False, indent=' ', _level=0):
print(index, self.type.name)

if properties:
for key in sorted(self.props):
value = self.props[key]
for key in sorted(self.properties):
value = self.properties[key]
print('%s:%-15s = %r' % (indent * (_level + 1), key, value))

for i, child in enumerate(self.contents):
Expand Down Expand Up @@ -437,8 +437,8 @@ def __init__(self, type_, *args, **kwargs):
OrgTimestamp.__init__(
self,
self['type'],
start=parse_iso_date(self['start']) if self.props.get('start') else None,
end=parse_iso_date(self['end']) if self.props.get('end') else None,
start=parse_iso_date(self['start']) if self.properties.get('start') else None,
end=parse_iso_date(self['end']) if self.properties.get('end') else None,
)


Expand Down Expand Up @@ -547,16 +547,16 @@ class OrgDocument:
----------
root : OrgOutlineNode
The root of the document's Abstract Syntax Tree.
props : dict
properties : dict
Additional file-level properties attached to the document, such as the
author or date. Values may be strings or secondary strings.
meta : dict
A dictionary containing arbitrary application-specific metadata.
"""

def __init__(self, root, props=None, meta=None):
def __init__(self, root, properties=None, meta=None):
self.root = root
self.props = dict(props or [])
self.properties = dict(properties or [])
self.meta = dict(meta or [])

def assign_header_ids(self, depth=3):
Expand Down
8 changes: 4 additions & 4 deletions pyorg/convert/html/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def _make_elem(self, node, ctx, tag=None, **kwargs):

if node.type.name in self.INLINE_NODES:
kwargs.setdefault('inline', True)
kwargs.setdefault('post_ws', node.props.get('post-blank', 0) > 0)
kwargs.setdefault('post_ws', node.properties.get('post-blank', 0) > 0)

html = self._make_elem_base(tag, **kwargs)
html.add_class(self.default_classes(node.type))
Expand All @@ -159,7 +159,7 @@ def _make_text(self, node, text, ctx):
Takes care of adding whitespace after if needed.
"""
return TextNode(text, post_ws=node.props.get('post-blank', 0) > 0)
return TextNode(text, post_ws=node.properties.get('post-blank', 0) > 0)

def make_headline_text(self, node, ctx=None, dom=False):
"""Make HTML element for text content of headline node."""
Expand Down Expand Up @@ -254,7 +254,7 @@ def _make_headline_planning(self, headline, ctx):
rows = []

for key in ['closed', 'scheduled', 'deadline']:
if headline.props.get(key) is not None:
if headline.properties.get(key) is not None:
row = self._make_elem_base('tr')
row.children.append(self._make_elem_base('th', text=key.title()))

Expand Down Expand Up @@ -479,7 +479,7 @@ def _convert_latex_fragment(self, node, ctx):

@_convert_node.register('src-block')
def _convert_src_block(self, node, ctx):
# params = node.props.get('parameters', {'export': 'both'})
# params = node.properties.get('parameters', {'export': 'both'})
params = {'export': 'both'}

export = params.get('export', 'both')
Expand Down
2 changes: 1 addition & 1 deletion pyorg/convert/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _convert_outline_node(self, node, ctx):
def _convert_properties(self, node, ctx):
return {
key: self._convert(value, ctx._push(key))
for key, value in node.props.items()
for key, value in node.properties.items()
}

@dispatch_node_type()
Expand Down
4 changes: 2 additions & 2 deletions pyorg/convert/plaintext.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def _convert_contents(self, contents, ctx, blanks=False, sep=None):
if isinstance(item, OrgNode):
txt = self._convert(item, ctx._push(i))
if blanks:
pre = ' ' * item.props.get('pre-blank', 0)
post = ' ' * item.props.get('post-blank', 0)
pre = ' ' * item.properties.get('pre-blank', 0)
post = ' ' * item.properties.get('post-blank', 0)
txt = pre + txt + post
contents_str.append(txt)

Expand Down
4 changes: 2 additions & 2 deletions pyorg/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _node_from_json(data, ctx, recurse_contents=True):
keywords = _mapping_from_json(data.get('keywords', {}), ctx)

cls = NODE_CLASSES.get(type_, OrgNode)
node = cls(type_, props=props, contents=contents, keywords=keywords, ref=ref)
node = cls(type_, properties=props, contents=contents, keywords=keywords, ref=ref)

return node

Expand Down Expand Up @@ -100,7 +100,7 @@ def org_doc_from_json(data):
contents = _list_from_json(data['contents'], ctx)
root = OrgDataNode('org-data', contents=contents)

doc = OrgDocument(root, props=data['properties'])
doc = OrgDocument(root, properties=data['properties'])
if ctx.errors:
doc.meta['export_errors'] = ctx.errors

Expand Down

0 comments on commit fae1add

Please sign in to comment.