Formats code

This commit is contained in:
2026-05-19 20:21:43 -04:00
parent f8114af4a9
commit 43e1299616
7 changed files with 48 additions and 20 deletions
+1 -1
View File
@@ -4,5 +4,5 @@ module Roux (
module X, module X,
) where ) where
import Roux.Server (app)
import Data.CookLang as X import Data.CookLang as X
import Roux.Server (app)
+1 -1
View File
@@ -28,8 +28,8 @@ import qualified Text.Blaze.Html.Renderer.Utf8 as R
import Text.Blaze.Html5 as H import Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes as A import Text.Blaze.Html5.Attributes as A
import qualified Roux.RecipeIndex as Idx
import Data.CookLang import Data.CookLang
import qualified Roux.RecipeIndex as Idx
-- --------------------------------------------------------------------------- -- ---------------------------------------------------------------------------
-- Sort mode for the index page -- Sort mode for the index page
+42 -13
View File
@@ -254,8 +254,9 @@ ingredientGroupToSection group =
, sectionBody = SecStep step :| [] , sectionBody = SecStep step :| []
} }
-- | Convert a single NYT ingredient into Cooklang step items. {- | Convert a single NYT ingredient into Cooklang step items.
-- Produces something like: @ingredient{quantity} — rest of description Produces something like: @ingredient{quantity} — rest of description
-}
ingredientToStepItems :: NYTIngredientItem -> [StepItem] ingredientToStepItems :: NYTIngredientItem -> [StepItem]
ingredientToStepItems item = ingredientToStepItems item =
let quantity = nytIngredientQuantity item let quantity = nytIngredientQuantity item
@@ -265,7 +266,9 @@ ingredientToStepItems item =
name = extractIngredientName fullText name = extractIngredientName fullText
qty = parseNYTQuantity quantity qty = parseNYTQuantity quantity
in if T.null quantity in if T.null quantity
then [ StepText ", ", StepIngredient (Ingredient (simplifyText fullText) Nothing Nothing) then
[ StepText ", "
, StepIngredient (Ingredient (simplifyText fullText) Nothing Nothing)
] ]
else else
[ StepText ", " [ StepText ", "
@@ -334,21 +337,47 @@ parseNYTQuantity t
} }
Nothing -> Nothing Nothing -> Nothing
-- | Try to extract the core ingredient name from a descriptive text. {- | Try to extract the core ingredient name from a descriptive text.
-- E.g. @"tablespoons neutral oil, like canola or grapeseed"@ -> @"oil"@ E.g. @"tablespoons neutral oil, like canola or grapeseed"@ -> @"oil"@
-- This is a heuristic; for complex cases the full text is used. This is a heuristic; for complex cases the full text is used.
-}
extractIngredientName :: Text -> Text extractIngredientName :: Text -> Text
extractIngredientName t = extractIngredientName t =
let cleaned = simplifyText t let cleaned = simplifyText t
toks = T.words cleaned toks = T.words cleaned
-- Filter out common unit/quantity words to find the core ingredient -- Filter out common unit/quantity words to find the core ingredient
skipWords = skipWords =
[ "tablespoons", "tablespoon", "teaspoons", "teaspoon" [ "tablespoons"
, "cups", "cup", "ounces", "ounce", "pounds", "pound" , "tablespoon"
, "grams", "gram", "cloves", "clove", "slices", "slice" , "teaspoons"
, "large", "medium", "small", "fresh", "dried", "minced" , "teaspoon"
, "chopped", "diced", "peeled", "grated", "crushed" , "cups"
, "ground", "whole", "skinless", "boneless" , "cup"
, "ounces"
, "ounce"
, "pounds"
, "pound"
, "grams"
, "gram"
, "cloves"
, "clove"
, "slices"
, "slice"
, "large"
, "medium"
, "small"
, "fresh"
, "dried"
, "minced"
, "chopped"
, "diced"
, "peeled"
, "grated"
, "crushed"
, "ground"
, "whole"
, "skinless"
, "boneless"
] ]
meaningful = dropWhile (`elem` skipWords) toks meaningful = dropWhile (`elem` skipWords) toks
in case meaningful of in case meaningful of
@@ -377,7 +406,7 @@ breakOn delim t =
_ -> (t, T.empty) _ -> (t, T.empty)
-- | Simple read wrapper. -- | Simple read wrapper.
readMaybe :: Read a => String -> Maybe a readMaybe :: (Read a) => String -> Maybe a
readMaybe s = case reads s of readMaybe s = case reads s of
[(x, "")] -> Just x [(x, "")] -> Just x
_ -> Nothing _ -> Nothing
+1 -1
View File
@@ -9,8 +9,8 @@ import qualified Data.Text as T
import System.Directory (listDirectory) import System.Directory (listDirectory)
import System.FilePath (takeBaseName, takeExtension, (</>)) import System.FilePath (takeBaseName, takeExtension, (</>))
import Roux.Parser (parseCookFile)
import Data.CookLang import Data.CookLang
import Roux.Parser (parseCookFile)
-- | Metadata about a single recipe discovered on disk. -- | Metadata about a single recipe discovered on disk.
data RecipeInfo = RecipeInfo data RecipeInfo = RecipeInfo
+1 -2
View File
@@ -1,5 +1,4 @@
{- | Re-exports all types from 'Data.CookLang' for backward compatibility. -- | Re-exports all types from 'Data.CookLang' for backward compatibility.
-}
module Roux.Types (module X) where module Roux.Types (module X) where
import Data.CookLang as X import Data.CookLang as X
+1 -1
View File
@@ -3,8 +3,8 @@ module Roux.NYTimesSpec (spec) where
import qualified Data.Text.IO as TIO import qualified Data.Text.IO as TIO
import Test.Hspec (Spec, describe, it, shouldBe, shouldSatisfy) import Test.Hspec (Spec, describe, it, shouldBe, shouldSatisfy)
import Roux.NYTimes
import Data.CookLang import Data.CookLang
import Roux.NYTimes
spec :: Spec spec :: Spec
spec = do spec = do
+1 -1
View File
@@ -6,8 +6,8 @@ import Data.Ratio ((%))
import qualified Data.Text.IO as TIO import qualified Data.Text.IO as TIO
import Test.Hspec (Spec, describe, expectationFailure, it, shouldBe) import Test.Hspec (Spec, describe, expectationFailure, it, shouldBe)
import Roux.Parser (parseCookFile)
import Data.CookLang import Data.CookLang
import Roux.Parser (parseCookFile)
spec :: Spec spec :: Spec
spec = do spec = do