Skip to content

Commit 6e3920d

Browse files
committed
document after_initialize
1 parent d1753cf commit 6e3920d

File tree

3 files changed

+2
-2
lines changed

3 files changed

+2
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ For more examples of customizing the sanitization process to include the tags yo
203203

204204
`NodeFilters`s can operate either on HTML elements or text nodes using CSS selectors. Each `NodeFilter` must define a method named `selector` which provides an instance of `Selma::Selector`. If elements are being manipulated, `handle_element` must be defined, taking one argument, `element`; if text nodes are being manipulated, `handle_text_chunk` must be defined, taking one argument, `text_chunk`. `@config`, and `@result` are available to use, and any changes made to these ivars are passed on to the next filter.
205205

206+
`NodeFilter` also has an optional method, `after_initialize`, which is run after the filter initializes. This can be useful in setting up a custom state for `result` to take advantage of.
207+
206208
Here's an example `NodeFilter` that adds a base url to images that are root relative:
207209

208210
```ruby

lib/html_pipeline/node_filter/mention_filter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def mentioned_logins_in(text, username_pattern = USERNAME_PATTERN)
6363

6464
SELECTOR = Selma::Selector.new(match_text_within: "*", ignore_text_within: IGNORE_PARENTS)
6565

66-
# TODO: document this
6766
def after_initialize
6867
result[:mentioned_usernames] ||= []
6968
end

lib/html_pipeline/node_filter/team_mention_filter.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def mentioned_teams_in(text, team_pattern = TEAM_PATTERN)
5353

5454
SELECTOR = Selma::Selector.new(match_text_within: "*", ignore_text_within: IGNORE_PARENTS)
5555

56-
# TODO: document this
5756
def after_initialize
5857
result[:mentioned_teams] = []
5958
end

0 commit comments

Comments
 (0)