Improve docs for strict_locals! [ci-skip]

The docs didn't say much about what strict locals are or why you would
use them. This adds docs on usage and what the functionality does.
This commit is contained in:
eileencodes 2022-12-14 15:05:19 -05:00
parent 4f7772ad40
commit 171fea857d
No known key found for this signature in database
GPG Key ID: BA5C575120BBE8DF

@ -256,8 +256,14 @@ def encode!
end end
# This method is responsible for marking a template as having strict locals # This method is responsible for marking a template as having strict locals
# and extracting any arguments declared in the format # which means the template can only accept the locals defined in a magic
# locals: (message:, label: "My Message") # comment. For example, if your template acceps that locals +title+ and
# +comment_count+, add the following to your template file:
#
# <%# locals: (title: "Default title", comment_count: 0) %>
#
# Strict locals are useful for validating template arguments and for
# specifying defaults.
def strict_locals! def strict_locals!
if @strict_locals == NONE if @strict_locals == NONE
self.source.sub!(STRICT_LOCALS_REGEX, "") self.source.sub!(STRICT_LOCALS_REGEX, "")
@ -271,6 +277,7 @@ def strict_locals!
@strict_locals @strict_locals
end end
# Returns whether a template is using strict locals.
def strict_locals? def strict_locals?
strict_locals! strict_locals!
end end