\ProvidesFile{droit-fr.bbx}[2014/01/30 v0.4 style droit francais]

\RequireBibliographyStyle{verbose-ibid}
\RequireBiber[3]

% l'editor ne remplace pas un champ author laissé vide.
% il reste imprimé à sa place (généralement après le title).
\ExecuteBibliographyOptions{useeditor=false}

% classement par nom, année titre (voir plus bas pour customisation du tri nytx)
\ExecuteBibliographyOptions{sorting=nyt}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% REDEFINITIONS/AJOUT DE MOTS-CLES %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\NewBibliographyString{byobservator}
\NewBibliographyString{bychronicler}
\NewBibliographyString{numbers}

\DefineBibliographyStrings{french}{%
  in               = {in},
  byeditor         = {sous la dir\adddot\ de},
  bycommentator    = {comm\adddot},
  byannotator      = {note},
  byobservator     = {obs\adddot},
  byredactor       = {rapp\adddot},
  bychronicler     = {chron\adddot},
  withafterword    = {concl\adddot},
  thiscite         = {spéc\adddot},
  section          = {art\adddot},
  sections         = {art\adddot},
  numbers          = {{num\'eros}{n\textsuperscript{os}}}
}

\DefineBibliographyStrings{british}{%
  in               = {in},
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% REDEFINITIONS DE BIBLATEX.DEF %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setlength{\bibitemsep}{1.5\itemsep} % espacement entre 2 références
\renewcommand*{\newunitpunct}{\addcomma\space} % separation des units par une virgule
\renewcommand*{\mkbibnamelast}[1]{\textsc{\textnohyphenation{#1}}} % petites maj. pour toutes les langues.
\renewcommand*{\subtitlepunct}{\addcolon\space} % separation entre titre et sous-titre


% ------------------------------------------------------------------
% FIELD FORMATS
% ------------------------------------------------------------------

% Used in citations

% book, thesis, collection, report, jurisdiction, case = italique
% legislation = normal
% inbook, incollection, article, commentary = guillemets
\DeclareFieldFormat{citetitle}{\mkbibemph{#1\isdot}}
\DeclareFieldFormat[legislation]{citetitle}{#1\isdot}
\DeclareFieldFormat
  [article,inbook,incollection,inproceedings,patent,unpublished]
  {citetitle}{\mkbibquote{#1\isdot}}

% pas de P. majuscule
\DeclareFieldFormat{postnote}{\midsentence\mkpageprefix[pagination]{#1}}
\DeclareFieldFormat{volcitepages}{\midsentence\mkpageprefix[pagination]{#1}}
\DeclareFieldFormat{multipostnote}{\midsentence\mkpageprefix[pagination]{#1}}

% Used in the bibliography

% pas de P. majuscule
\DeclareFieldFormat{pages}{\midsentence\mkpageprefix[bookpagination]{#1}}
\DeclareFieldFormat{pagetotal}{\midsentence\mkpagetotal[bookpagination]{#1}}

% tout italique, sauf legislation
\DeclareFieldFormat{title}{\mkbibemph{#1\isdot}}
\DeclareFieldFormat[thesis]{title}{\mkbibemph{#1\isdot}}
\DeclareFieldFormat[legislation]{title}{#1\isdot}

\DeclareFieldFormat{chapter}{#1} % pas de 'chap.'
\DeclareFieldFormat[jurisdiction,legislation]{number}{\biblcstring{number}~#1}% no de l'arret
\DeclareFieldFormat[case]{journaltitle}{#1}% pas d'italique'
\DeclareFieldFormat[case]{volume}{#1}% pas de 't.'
\DeclareFieldFormat[case]{pages}{#1} % pas de 'p.'

% ------------------------------------------------------------------
% LIST FORMATS
% ------------------------------------------------------------------

% institution entre parentheses dans les cases de type legacy
\DeclareListFormat{parenslist}{%
  \mkbibparens{\usebibmacro{list:delim}{#1}%
  #1\isdot
  \usebibmacro{list:andothers}}}

% ------------------------------------------------------------------
% NAME LIST FORMATS
% ------------------------------------------------------------------
% #1 = last name
% #2 = last name (initials)
% #3 = first name
% #4 = first name (initials)
% #5 = name prefix, a.k.a. 'von part'
% #6 = name prefix (initials)
% #7 = name affix, a.k.a. 'junior part'
% #8 = name affix (initials)

% Forcer l'affichage du prénom en initiales, suivi du nom pour les auteurs dans les citations.
\DeclareNameFormat{labelname}{%
  \ifuseprefix
    {\usebibmacro{name:first-last}{#1}{#4}{#5}{#8}}
    {\usebibmacro{name:first-last}{#1}{#4}{#6}{#8}}%
  \usebibmacro{name:andothers}}

% modification pour obtenir "NOM, (Prénom particule)" pour les auteurs dans la bibliographie.
\renewbibmacro*{name:last-first}[4]{%
  \ifuseprefix
    {\usebibmacro{name:delim}{#3#1}%
     \ifblank{#3}{}{%
       \mkbibnameprefix{\MakeCapital{#3}\isdot}%
       \ifpunctmark{'}{}{\addhighpenspace}}%
     \mkbibnamelast{#1\isdot}%
     \ifblank{#4}{}{\addlowpenspace\mkbibnameaffix{#4}\isdot}%
     \ifblank{#2}{}{\addlowpenspace\mkbibparens{\mkbibnamefirst{#2}\isdot}}}
    {\usebibmacro{name:delim}{#1}%
     \mkbibnamelast{#1}\isdot
     \ifblank{#4}{}{\addlowpenspace\mkbibnameaffix{#4}\isdot}%
     \ifblank{#2#3}{}{}%
     \ifblank{#2}{}{%
       \ifblank{#3}
         {\addlowpenspace\mkbibparens{\mkbibnamefirst{#2}\isdot}}%
         {\addlowpenspace\mkbibparens{\mkbibnamefirst{#2}\addlowpenspace\mkbibnameprefix{#3}\isdot}}}}}

% affichage du prénom en initiales, suivi du nom pour les autres champs (editor, translator, etc).
\DeclareNameFormat{first-last}{%
  \usebibmacro{name:first-last}{#1}{#4}{#5}{#7}
  \usebibmacro{name:andothers}}


% caractère de séparation entre plusieurs entrées référencées dans "related"
\renewcommand*{\relateddelim}{\addsemicolon\addspace}

% modification du champ "related" pour les commentaires d'arrêt
\newbibmacro*{related:default}[1]{%
  \entrydata{#1}{\usedriver{}{commentary}}}

% indexation des auteurs seulement
\renewbibmacro*{bibindex}{%
  \ifbibindex
    {\indexnames{labelname}}
    {}}

\renewcommand*{\mkbibindexname}[4]{%
  \ifuseprefix
    {\ifblank{#3}{}{#3 }%
     \@firstofone #1% remove spurious braces
     \ifblank{#4}{}{ #4}%
     \ifblank{#2}{}{, #2}%
     \actualoperator
     \ifblank{#3}{}{\MakeCapital{#3} }%
     #1%
     \ifblank{#4}{}{ #4}%
     \ifblank{#2}{}{, #2}}
    {\@firstofone #1% remove spurious braces
     \ifblank{#4}{}{ #4}% ajouté
     \ifblank{#2#3}{}{,}% ajouté
     \ifblank{#2}{}{ #2}% ajouté
     \ifblank{#3}{}{ #3} % ajouté
      \actualoperator % ajouté
      \textsc{#1}%
     \ifblank{#4}{}{ #4}%
     \ifblank{#2#3}{}{,}%
     \ifblank{#2}{}{ #2}%
     \ifblank{#3}{}{ #3}}}

% schéma de tri destiné à la jurisprudence: institution, date de décision
\DeclareSortingScheme{iymd}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{institution}
  }
  \sort{
    \field{eventyear}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{eventmonth}
    \literal{00}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{eventday}
    \literal{00}
  }
}


% schéma de tri destiné à la jurisprudence: titre (nom d'affaire), date de décision, institution
\DeclareSortingScheme{tymdi}{
  \sort{
    \field{presort}
  }
  \sort[final]{
    \field{sortkey}
  }
  \sort{
    \field{sorttitle}
    \field{title}
  }
  \sort{
    \field{eventyear}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{eventmonth}
    \literal{00}
  }
  \sort{
    \field[padside=left,padwidth=2,padchar=0]{eventday}
    \literal{00}
  }
  \sort{
    \field{institution}
  }
}

%TODO: abrévations de prénoms
% digrammes (deux consonnes pour un seul son): Ch, Gh, Ph, Th
% consonne ou digramme suivi de L ou R:


%%%%%%%%%%%
% DRIVERS %
%%%%%%%%%%%

% loi
\DeclareBibliographyDriver{legislation}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \usebibmacro{journal+issuetitle}%
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \printfield{pages}
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

% rapport officiel
% ajout de l'editor (byeditor)
\DeclareBibliographyDriver{report}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byauthor}%
  \newunit\newblock
  \usebibmacro{byeditor}%
  \newunit\newblock
  \printfield{type}%
  \setunit*{\addspace}%
  \printfield{number}%
  \newunit\newblock
  \printfield{version}%
  \newunit
  \printfield{note}%
  \newunit\newblock
  \usebibmacro{institution+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit
  \printfield{pagetotal}%
  \newunit\newblock
  \iftoggle{bbx:isbn}
    {\printfield{isrn}}
    {}%
  \newunit\newblock
  \usebibmacro{doi+eprint+url}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \setunit{\bibpagerefpunct}\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

% thèse:
% ajout du directeur de thèse (byeditor)
\DeclareBibliographyDriver{thesis}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{author}%
  \setunit{\labelnamepunct}\newblock
  \usebibmacro{title}%
  \newunit
  \printlist{language}%
  \newunit\newblock
  \usebibmacro{byeditor}%
  \newunit\newblock  
  \printfield{note}%
  \newunit\newblock
  \printfield{type}%
  \newunit
  \usebibmacro{institution+location+date}%
  \newunit\newblock
  \usebibmacro{chapter+pages}%
  \newunit\newblock
  \printlist{publisher}
  \newunit
  \printfield{pagetotal}
  \setunit*{\addcomma\space}
  \newblock
  \printfield{doi}%
  \newunit\newblock
  \usebibmacro{url+urldate}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

% cas de jurisprudence générique
\DeclareBibliographyAlias{jurisdiction}{case}
\DeclareBibliographyDriver{case}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \iffieldequalstr{hyphenation}{british}
    {\usebibmacro{case:british}}
    {\usebibmacro{case:french}}
  \newunit\newblock
  \printfield{note}%
  \newunit\newblock
  \printfield{addendum}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \setunit{\addsemicolon\addspace}\newblock
  \usebibmacro{related}%
  \usebibmacro{finentry}}

% cas de jurisprudence anglaise
% - avec neutral citation: format adopté depuis 2001 par certaines juridictions
% - sans neutral citation: format historique
\newbibmacro*{case:british}{%
  \iffieldundef{number}
    {\usebibmacro{case:british:legacy}}
    {\usebibmacro{case:british:withneutral}}
}

% jurisprudence anglaise sans neutral citation:
% title | [year] OR (eventyear) | volume | journal | page | (jurisdiction)
\newbibmacro*{case:british:legacy}{%
  \usebibmacro{title}%
  \setunit{\addspace}\newblock
  \iffieldundef{year}
    {\printfield[parens]{eventyear}}
    {\printfield[brackets]{year}}
  \setunit{\addspace}
  \printfield{volume}%
  \setunit{\addspace}
  \usebibmacro{journal}%
  \setunit{\addspace}\newblock
  \printfield{pages}
  \setunit{\addspace}\newblock
  \printlist[parenslist]{institution}}

% case avec neutral citation (depuis 2001 et pour certaines juridictions)
% <neutral citation>, | <infos de publications dans un law report>
\newbibmacro*{case:british:withneutral}{%
  \usebibmacro{case:british:neutral}%
  \iffieldundef{journaltitle}
    {}
    {\usebibmacro{case:british:report}}}

% neutral citation
% title | [eventyear] | jurisdiction | number
\newbibmacro*{case:british:neutral}{%
  \usebibmacro{title}%
  \setunit{\addspace}\newblock
  \printfield[brackets]{eventyear}%
  \setunit{\addspace}
  \printlist{institution}%
  \setunit{\addspace}
  \printfield{number}%
}

% informations de publication relatives à un law report
% dans un arrêt de jurisprudence anglaise avec neutral citation.
% [year] OR (eventyear) | volume | journal | page
\newbibmacro*{case:british:report}{%
  \setunit{\addcomma\space}\newblock
  \iffieldundef{year}
    {\printfield[parens]{eventyear}}
    {\printfield[brackets]{year}}
  \setunit{\addspace}
  \printfield{volume}%
  \setunit{\addspace}
  \usebibmacro{journal}%
  \setunit{\addspace}\newblock
  \printfield{pages}
}

% arrêt de jurisprudence française.
% institution, | titre, | eventdate, | number, | journal, | date, | volume, | chapter, | pages
% - eventdate: date de décision rendue
% - date: date de publication dans un journal officiel
% - number: numéro de requête ou de l'arrêt (si non publié)
% - chapter: section logique du journal dans laquelle se trouve l'arrêt
\newbibmacro{case:french}{%
  \printlist{institution}%
  \newunit\newblock
  \usebibmacro{title}%
  \newunit\newblock
  \printeventdate%
  \newunit\newblock
  \printfield{number}%
  \newunit\newblock
  \usebibmacro{journal}%
  \newunit
  \printfield{volume}%
  \printfield{part}
  \newunit\newblock
  \usebibmacro{chapter+pages}}

% commentaire d'arrêt
\DeclareBibliographyDriver{commentary}{%
  \usebibmacro{bibindex}%
  \usebibmacro{begentry}%
  \usebibmacro{journal+issuetitle}%
  \setunit{\bibpagespunct}%
  \printfield{pages}%
  \newunit\newblock
  \usebibmacro{byeditor+others}%
  \newunit\newblock
  \usebibmacro{addendum+pubstate}%
  \newunit\newblock
  \usebibmacro{pageref}%
  \usebibmacro{finentry}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% REDEFINITIONS DU STYLE STANDARD.BBX %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% mot-clé "in" non présent dans les articles.
% présent dans les autres types (inbook, incollection...):
% - pas de : 
% - pas de virgule (ni avant ni après)
\renewbibmacro*{in:}{%
  \ifentrytype{article}
    {\newunit}
    {\setunit{\addspace}
     \biblcstring[\mkbibemph]{in}
     \setunit{\addspace}
     \nopunct}
  }

% date imprimée sans parenthèses
\renewbibmacro*{issue+date}{%
  \printtext{% [parens]
    \iffieldundef{issue}
      {\printdate}
      {\printfield{issue}%
       \setunit{\addspace}%
       \printfield{year}}}%
  \newunit}

% macro utilisée dans article, legislation, commentary.
% - journal et date toujours séparés par un espace.
% - ajout de "part" et "chapter", pour des journaux comprenant des partie thématiques (Dalloz, JCP, etc)
\renewbibmacro*{journal+issuetitle}{%
  \usebibmacro{journal}%
  \setunit{\addspace}%
  \usebibmacro{issue+date}%
  \newunit\newblock
  \usebibmacro{issue}%
  \newunit
  \printfield{volume}%
  \newunit
  \printfield{part}%
  \newunit
  \printfield{chapter}%
  \newunit
  \iffieldundef{series}
    {}
    {\printfield{series}%
     \newunit}%
  \printfield{number}%
  \newunit
  \printfield{eid}%
  \newunit}

% macro utilisée dans les (in)proceedings.
% date imprimée sans parenthèses
\renewbibmacro*{event+venue+date}{%
  \printfield{eventtitle}%
  \ifboolexpr{
    test {\iffieldundef{venue}}
    and
    test {\iffieldundef{eventyear}}
  }
    {}
    {\setunit*{\addspace}%
     \printtext{% [parens]
       \printfield{venue}%
       \setunit*{\addcomma\space}%
       \printeventdate}}%
  \newunit}

\endinput
