<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 問題 你有一組數據,你需要對它們進行多次不同可處理。 ## 方法 使用裝飾者模式來構建你的處理方式。 ~~~ miniMarkdown = (line) -> if match = line.match /^(#+)\s*(.*)$/ headerLevel = match[1].length headerText = match[2] "<h#{headerLevel}>#{headerText}</h#{headerLevel}>" else if line.length > 0 "<p>#{line}</p>" else '' stripComments = (line) -> line.replace /\s*\/\/.*$/, '' # Removes one-line, double-slash C-style comments TextProcessor = (@processors) -> reducer: (existing, processor) -> if processor processor(existing or '') else existing processLine: (text) -> @processors.reduce @reducer, text processString: (text) -> (@processLine(line) for line in text.split("\n")).join("\n") exampleText = ''' # A level 1 header A regular line // a comment ## A level 2 header A line // with a comment ''' processor = new TextProcessor [stripComments, miniMarkdown] processor.processString exampleText # => "<h1>A level 1 header</h1>\n<p>A regular line</p>\n\n<h2>A level 2 header</h2>\n<p>A line</p>" ~~~ ### 結果 ~~~ <h1>A level 1 header</h1> <p>A regular line</p> <h2>A level 1 header</h2> <p>A line</p> ~~~ ## 詳解 TextProcessor正在這里就是一個裝飾者的角色,把獨立的不同的文本處理方式放到了一起。miniMarkdown和stripComments這兩個組件被解放出來,專注于處理單行文本。其他開發者只需要編寫這樣的函數,返回一個字符串,并且把這個函數添加到處理器組中。 我們甚至可以隨時修改現有的裝飾者: ~~~ smilies = ':)' : "smile" ':D' : "huge_grin" ':(' : "frown" ';)' : "wink" smilieExpander = (line) -> if line (line = line.replace symbol, "<img src='#{text}.png' alt='#{text}' />") for symbol, text of smilies line processor.processors.unshift smilieExpander processor.processString "# A header that makes you :) // you may even laugh" # => "<h1>A header that makes you <img src='smile.png' alt='smile' /></h1>" processor.processors.shift() # => "<h1>A header that makes you :)</h1>" ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看