Skip to content

Commit

Permalink
Fix findings
Browse files Browse the repository at this point in the history
  • Loading branch information
treagod committed Nov 25, 2024
1 parent 5795e65 commit e60918f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion spec/marten/template/tag/localize_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe Marten::Template::Tag::Localize do

expect_raises(
Marten::Template::Errors::UnsupportedValue,
"Localization requires an Array with exactly 3 elements, but received 4 elements." +
"Localization of dates requires an Array with exactly 3 elements, but received 4 elements." +
" Ensure the Array follows the format [year, month, day]."
) do
tag.render(Marten::Template::Context{"unsupported_date" => {2024, 11, 19, 12}})
Expand Down
8 changes: 5 additions & 3 deletions src/marten/template/tag/localize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module Marten
# {% localize 100000 format: "short" %}
# ```
#
# The `format` argument must match a key defined in the locale file.
#
# Optionally, the result of the localization can be assigned to a variable using `as` keyword:
#
# ```
Expand Down Expand Up @@ -51,7 +53,7 @@ module Marten
def render(context : Context) : String
value = @value_expression.resolve(context).raw

if format_value = @kwargs.delete("format")
if format_value = @kwargs["format"]?
format = format_value.resolve(context).to_s
end

Expand All @@ -73,8 +75,8 @@ module Marten
when Array(Marten::Template::Value)
if value.size != 3
raise Errors::UnsupportedValue.new(
"Localization requires an Array with exactly 3 elements, but received #{value.size} elements. " +
"Ensure the Array follows the format [year, month, day]."
"Localization of dates requires an Array with exactly 3 elements, but received #{value.size}" +
" elements. Ensure the Array follows the format [year, month, day]."
)
end

Expand Down

0 comments on commit e60918f

Please sign in to comment.