# Copyright (C) 2006, 2007, 2008  Andrey Golovizin
#
# This file is part of pybtex.
#
# pybtex is free software; you can redistribute it and/or modify
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# pybtex is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pybtex; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

"""name formatting styles
"""
from pybtex.richtext import Symbol
from pybtex.style.template import join, together

def plain(person, abbr=False):
    r"""
    >>> from pybtex.core import Person
    >>> name = Person(string=r"Charles Louis Xavier Joseph de la Vall{\'e}e Poussin")
    >>> print plain(name).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, Charles Louis Xavier<nbsp>Joseph
    >>> print plain(name, abbr=True).format().plaintext()
    de<nbsp>la Vall{\'e}e<nbsp>Poussin, C.<nbsp>L. X.<nbsp>J.
    >>> name = Person(first='First', last='Last', middle='Middle')
    >>> print plain(name).format().plaintext()
    Last, First<nbsp>Middle
    >>> print plain(name, abbr=True).format().plaintext()
    Last, F.<nbsp>M.

    """
    nbsp = Symbol('nbsp')
    return together(last_tie=False) [
        together [person.prelast()],
        join(sep=', ') [
            together [person.last()],
            together [person.lineage()],
            together [person.first(abbr) + person.middle(abbr)],
        ],
    ]

@@ -825,16 +825,28 @@
 t Symbol
+, Text, nbsp
 %0Afrom py
@@ -886,16 +886,355 @@
 together
+, node, _format_list%0Afrom pybtex.bibtex.name import tie_or_space%0A%0A@node%0Adef name_part(children, data, before='', tie=False):%0A    parts = together %5Bchildren%5D.format_data(data)%0A    if not parts:%0A        return Text()%0A    if tie:%0A        return Text(before, parts, tie_or_space(parts, nbsp, ' '))%0A    else:%0A        return Text(before, parts)%0A
 %0A%0Adef pl
@@ -1870,150 +1870,87 @@
     
-nbsp = Symbol('nbsp')%0A    return together(last_tie=False) %5B%0A        together %5Bperson.prelast()%5D,%0A        join(sep=', ') %5B%0A            together
+return join %5B%0A        name_part(tie=True) %5Bperson.prelast()%5D,%0A        name_part
  %5Bpe
@@ -1967,36 +1967,46 @@
 )%5D,%0A        
-    together
+name_part(before=', ')
  %5Bperson.lin
@@ -2026,20 +2026,30 @@
     
-    together
+name_part(before=', ')
  %5Bpe
@@ -2093,19 +2093,8 @@
 )%5D,%0A
-        %5D,%0A
     

Add names.name_part template node to simplify porting BibTeX name formatting patterns.