You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the TextProcessor object ready to wrangle all of the text processors together, the miniMarkdown, stripComments, and any future functions can focus exclusively on handling nothing but a single line of text. Future developers only have to write functions that return a string and add it to the array of processors in order to partake in the process.
60
+
The TextProcessor serves the role of Decorator and binds the individual, specialized text processors together. This frees up the miniMarkdown, stripComments, and any future components to focus on handling nothing but a single line of text. Future developers only have to write functions that return a string and add it to the array of processors.
61
61
62
-
We can even modify the existing Decorator object on the fly:
62
+
We can even modify the existing Decorator object on the fly. We could add a processor for transforming text smilies into images, for example, but only when the end user enables the feature:
63
63
64
64
{% highlight coffeescript %}
65
65
smilies =
@@ -70,12 +70,16 @@ smilies =
70
70
71
71
smilieExpander = (line) ->
72
72
if line
73
-
(line = line.replace symbol, "{#{text}}") for symbol, text of smilies
73
+
(line = line.replace symbol, "<img src='#{text}.png' alt='#{text}' />") for symbol, text of smilies
74
74
line
75
75
76
76
processor.processors.unshift smilieExpander
77
77
78
78
processor.processString "# A header that makes you :) // you may even laugh"
79
79
80
-
# => '<h1>A header that makes you {smile}</h1>'
80
+
# => "<h1>A header that makes you <img src='smile.png' alt='smile' /></h1>"
0 commit comments