[前][次][番号順一覧][スレッド一覧]

ruby-changes:26129

From: seki <ko1@a...>
Date: Wed, 5 Dec 2012 00:10:29 +0900 (JST)
Subject: [ruby-changes:26129] seki:r38186 (trunk): * lib/erb.rb (make_compiler, add_put_cmd, add_insert_cmd): extract

seki	2012-12-05 00:10:17 +0900 (Wed, 05 Dec 2012)

  New Revision: 38186

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38186

  Log:
    * lib/erb.rb (make_compiler, add_put_cmd, add_insert_cmd): extract
      methods.

  Modified files:
    trunk/ChangeLog
    trunk/lib/erb.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38185)
+++ ChangeLog	(revision 38186)
@@ -1,3 +1,8 @@
+Wed Dec  5 00:05:47 2012  Masatoshi SEKI  <m_seki@m...>
+
+	* lib/erb.rb (make_compiler, add_put_cmd, add_insert_cmd): extract
+	  methods.
+
 Tue Dec  4 18:21:04 2012  Naohisa Goto  <ngotogenome@g...>
 
 	* test/ruby/memory_status.rb (Memory): use fiddle/types if available.
Index: lib/erb.rb
===================================================================
--- lib/erb.rb	(revision 38185)
+++ lib/erb.rb	(revision 38186)
@@ -583,6 +583,14 @@
       end
     end
 
+    def add_put_cmd(out, content)
+      out.push("#{@put_cmd} #{content_dump(content)}")
+    end
+    
+    def add_insert_cmd(out, content)
+      out.push("#{@insert_cmd}((#{content}).to_s)")
+    end
+
     # Compiles an ERB template into Ruby code.  Returns an array of the code
     # and encoding like ["code", Encoding].
     def compile(s)
@@ -600,7 +608,7 @@
         if scanner.stag.nil?
           case token
           when PercentLine
-            out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+            add_put_cmd(out, content) if content.size > 0
             content = ''
             out.push(token.to_s)
             out.cr
@@ -608,11 +616,11 @@
             out.cr
           when '<%', '<%=', '<%#'
             scanner.stag = token
-            out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+            add_put_cmd(out, content) if content.size > 0
             content = ''
           when "\n"
             content << "\n"
-            out.push("#{@put_cmd} #{content_dump(content)}")
+            add_put_cmd(out, content)
             content = ''
           when '<%%'
             content << '<%'
@@ -632,7 +640,7 @@
                 out.push(content)
               end
             when '<%='
-              out.push("#{@insert_cmd}((#{content}).to_s)")
+              add_insert_cmd(out, content)
             when '<%#'
               # out.push("# #{content_dump(content)}")
             end
@@ -645,7 +653,7 @@
           end
         end
       end
-      out.push("#{@put_cmd} #{content_dump(content)}") if content.size > 0
+      add_put_cmd(out, content) if content.size > 0
       out.close
       return out.script, enc
     end
@@ -785,12 +793,16 @@
   #
   def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
     @safe_level = safe_level
-    compiler = ERB::Compiler.new(trim_mode)
+    compiler = make_compiler(trim_mode)
     set_eoutvar(compiler, eoutvar)
     @src, @enc = *compiler.compile(str)
     @filename = nil
   end
 
+  def make_compiler(trim_mode)
+    ERB::Compiler.new(trim_mode)
+  end
+
   # The Ruby code generated by ERB
   attr_reader :src
 
@@ -806,16 +818,8 @@
   def set_eoutvar(compiler, eoutvar = '_erbout')
     compiler.put_cmd = "#{eoutvar}.concat"
     compiler.insert_cmd = "#{eoutvar}.concat"
-
-    cmd = []
-    cmd.push "#{eoutvar} = ''"
-
-    compiler.pre_cmd = cmd
-
-    cmd = []
-    cmd.push("#{eoutvar}.force_encoding(__ENCODING__)")
-
-    compiler.post_cmd = cmd
+    compiler.pre_cmd = ["#{eoutvar} = ''"]
+    compiler.post_cmd = ["#{eoutvar}.force_encoding(__ENCODING__)"]
   end
 
   # Generate results and print them. (see ERB#result)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]