-module(glugify). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/glugify.gleam"). -export([slugify_with/2, try_slugify/1, slugify/1]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. -file("src/glugify.gleam", 69). ?DOC( " Converts text to a URL-friendly slug using custom configuration.\n" " This is the most flexible API that allows full control over the slugification process.\n" " \n" " ## Examples\n" " \n" " ```gleam\n" " import glugify/config\n" " \n" " let custom_config = config.default()\n" " |> config.with_separator(\"_\")\n" " |> config.with_max_length(20)\n" " \n" " slugify_with(\"A Very Long Title\", custom_config)\n" " // -> Ok(\"a_very_long_title\")\n" " ```\n" " \n" " ## Errors\n" " \n" " - `EmptyInput`: When the input text is empty\n" " - `ConfigurationError`: When the configuration is invalid\n" " - `TransliterationFailed`: When a character cannot be transliterated\n" ). -spec slugify_with(binary(), glugify@config:config()) -> {ok, binary()} | {error, glugify@errors:slugify_error()}. slugify_with(Text, Config) -> gleam@result:'try'(case glugify@config:validate_config(Config) of {ok, _} -> {ok, nil}; {error, Msg} -> {error, {configuration_error, Msg}} end, fun(_) -> gleam@result:'try'( glugify@internal@validators:validate_input(Text), fun(Validated) -> gleam@result:'try'( glugify@internal@processors:normalize_whitespace( Validated ), fun(Normalized) -> gleam@result:'try'( glugify@internal@processors:apply_custom_replacements( Normalized, erlang:element(8, Config) ), fun(With_custom_replacements) -> gleam@result:'try'( case erlang:element(6, Config) of true -> glugify@unicode:transliterate_text( With_custom_replacements ); false -> glugify@unicode:validate_ascii_or_unicode( With_custom_replacements, erlang:element(7, Config) ) end, fun(Transliterated) -> gleam@result:'try'( glugify@internal@processors:normalize_whitespace( Transliterated ), fun( Normalized_after_transliteration ) -> gleam@result:'try'( begin Result = case erlang:element( 3, Config ) of true -> string:lowercase( Normalized_after_transliteration ); false -> Normalized_after_transliteration end, {ok, Result} end, fun(Lowercased) -> gleam@result:'try'( glugify@internal@processors:apply_separators( Lowercased, Config ), fun(Separated) -> gleam@result:'try'( glugify@internal@processors:remove_invalid_chars( Separated, Config ), fun( Cleaned ) -> gleam@result:'try'( glugify@internal@processors:collapse_separators( Cleaned, Config ), fun( Collapsed ) -> gleam@result:'try'( glugify@internal@processors:filter_stop_words( Collapsed, erlang:element( 11, Config ), erlang:element( 2, Config ) ), fun( Without_stop_words ) -> gleam@result:'try'( glugify@internal@processors:trim_separators( Without_stop_words, Config ), fun( Trimmed ) -> gleam@result:'try'( case erlang:element( 4, Config ) of {some, Len} -> glugify@internal@processors:truncate_slug( Trimmed, Len, erlang:element( 5, Config ), erlang:element( 2, Config ) ); none -> {ok, Trimmed} end, fun( Truncated ) -> {ok, Truncated} end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end ) end). -file("src/glugify.gleam", 44). ?DOC( " Converts text to a URL-friendly slug with explicit error handling.\n" " Returns `Result(String, SlugifyError)` for cases where you need to handle errors.\n" " \n" " ## Examples\n" " \n" " ```gleam\n" " try_slugify(\"My Blog Post\")\n" " // -> Ok(\"my-blog-post\")\n" " \n" " try_slugify(\"\")\n" " // -> Error(EmptyInput)\n" " ```\n" ). -spec try_slugify(binary()) -> {ok, binary()} | {error, glugify@errors:slugify_error()}. try_slugify(Text) -> slugify_with(Text, glugify@config:default()). -file("src/glugify.gleam", 25). ?DOC( " Converts text to a URL-friendly slug using default configuration.\n" " This is the simplest API that always returns a string.\n" " \n" " ## Examples\n" " \n" " ```gleam\n" " slugify(\"Hello, World!\")\n" " // -> \"hello-world\"\n" " \n" " slugify(\"Café & Restaurant\")\n" " // -> \"cafe-and-restaurant\"\n" " ```\n" " \n" " If the input cannot be processed, returns an empty string.\n" " For error handling, use `try_slugify` instead.\n" ). -spec slugify(binary()) -> binary(). slugify(Text) -> case try_slugify(Text) of {ok, Slug} -> Slug; {error, _} -> <<""/utf8>> end.