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,
) where
import Roux.Server (app)
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.Attributes as A
import qualified Roux.RecipeIndex as Idx
import Data.CookLang
import qualified Roux.RecipeIndex as Idx
-- ---------------------------------------------------------------------------
-- Sort mode for the index page
+42 -13
View File
@@ -254,8 +254,9 @@ ingredientGroupToSection group =
, sectionBody = SecStep step :| []
}
-- | Convert a single NYT ingredient into Cooklang step items.
-- Produces something like: @ingredient{quantity} — rest of description
{- | Convert a single NYT ingredient into Cooklang step items.
Produces something like: @ingredient{quantity} — rest of description
-}
ingredientToStepItems :: NYTIngredientItem -> [StepItem]
ingredientToStepItems item =
let quantity = nytIngredientQuantity item
@@ -265,7 +266,9 @@ ingredientToStepItems item =
name = extractIngredientName fullText
qty = parseNYTQuantity quantity
in if T.null quantity
then [ StepText ", ", StepIngredient (Ingredient (simplifyText fullText) Nothing Nothing)
then
[ StepText ", "
, StepIngredient (Ingredient (simplifyText fullText) Nothing Nothing)
]
else
[ StepText ", "
@@ -334,21 +337,47 @@ parseNYTQuantity t
}
Nothing -> Nothing
-- | Try to extract the core ingredient name from a descriptive text.
-- E.g. @"tablespoons neutral oil, like canola or grapeseed"@ -> @"oil"@
-- This is a heuristic; for complex cases the full text is used.
{- | Try to extract the core ingredient name from a descriptive text.
E.g. @"tablespoons neutral oil, like canola or grapeseed"@ -> @"oil"@
This is a heuristic; for complex cases the full text is used.
-}
extractIngredientName :: Text -> Text
extractIngredientName t =
let cleaned = simplifyText t
toks = T.words cleaned
-- Filter out common unit/quantity words to find the core ingredient
skipWords =
[ "tablespoons", "tablespoon", "teaspoons", "teaspoon"
, "cups", "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"
[ "tablespoons"
, "tablespoon"
, "teaspoons"
, "teaspoon"
, "cups"
, "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
in case meaningful of
@@ -377,7 +406,7 @@ breakOn delim t =
_ -> (t, T.empty)
-- | Simple read wrapper.
readMaybe :: Read a => String -> Maybe a
readMaybe :: (Read a) => String -> Maybe a
readMaybe s = case reads s of
[(x, "")] -> Just x
_ -> Nothing
+1 -1
View File
@@ -9,8 +9,8 @@ import qualified Data.Text as T
import System.Directory (listDirectory)
import System.FilePath (takeBaseName, takeExtension, (</>))
import Roux.Parser (parseCookFile)
import Data.CookLang
import Roux.Parser (parseCookFile)
-- | Metadata about a single recipe discovered on disk.
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
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 Test.Hspec (Spec, describe, it, shouldBe, shouldSatisfy)
import Roux.NYTimes
import Data.CookLang
import Roux.NYTimes
spec :: Spec
spec = do
+1 -1
View File
@@ -6,8 +6,8 @@ import Data.Ratio ((%))
import qualified Data.Text.IO as TIO
import Test.Hspec (Spec, describe, expectationFailure, it, shouldBe)
import Roux.Parser (parseCookFile)
import Data.CookLang
import Roux.Parser (parseCookFile)
spec :: Spec
spec = do