\ProvidesPackage{recipe}[2020/01/30 Recipe Typesetting for OpenCookbook]

\ProcessOptions\relax

\RequirePackage{etoolbox}
\RequirePackage{nicefrac}
\RequirePackage{booktabs}
\RequirePackage{changepage}

\newcommand\half{\nicefrac{1}{2}}
\newcommand\quarter{\nicefrac{1}{4}}
\newcommand\third{\nicefrac{1}{3}}
\newcommand\twothirds{\nicefrac{2}{3}}
\newcommand\threequarters{\nicefrac{3}{4}}

\newcommand\recipe@ingredient[2]{#1 & #2 \\}
\newcommand\recipe@serving[1]{\ifempty{#1}{}{\textit{#1 servings}}}
\newcommand\recipe@contributor[1]{\ifempty{#1}{}{Courtesy of #1}}

\newenvironment{recipe}[3]{%
  \bigskip%
  \begin{adjustwidth}{4em}{4em}%
    \centerline{\textbf{#1}}%
    \recipe@contributor{#2}\hfill\recipe@servings{#3}\\
    \newenvironment{note}{\textit{Note:}}{}
    \newenvironment{ingredients}{%
      \smallskip%
      \begin{center}%
        \let\ingredient=\recipe@ingredient
        \begin{tabular}{lr}
          \toprule%
          }{%
          \bottomrule%
        \end{tabular}%
      \end{center}%
      \smallskip%
    }%
    \smallskip
  }{%
  \end{adjustwidth}%
  \bigskip%
}

\endinput
