From 171fea857d42c88dca100632fd921c48da399609 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Wed, 14 Dec 2022 15:05:19 -0500 Subject: [PATCH] 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. --- actionview/lib/action_view/template.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index acadc4ac82..918d747211 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -256,8 +256,14 @@ def encode! end # This method is responsible for marking a template as having strict locals - # and extracting any arguments declared in the format - # locals: (message:, label: "My Message") + # which means the template can only accept the locals defined in a magic + # 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! if @strict_locals == NONE self.source.sub!(STRICT_LOCALS_REGEX, "") @@ -271,6 +277,7 @@ def strict_locals! @strict_locals end + # Returns whether a template is using strict locals. def strict_locals? strict_locals! end