Permalink
Browse files

Add support for ERB.

  • Loading branch information...
1 parent cb50e67 commit 44bbbf03f6009d2bc59e8f3510080beb161c35ef @airblade committed Nov 15, 2012
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/magic_encoding.rb
View
@@ -1,5 +1,3 @@
-# -*- encoding : utf-8 -*-
-
# A simple library to prepend magic comments for encoding to multiple ".rb" files
module AddMagicComment
@@ -15,14 +13,15 @@ def self.process(options)
encoding = options[0] || "utf-8"
directory = options[1] || Dir.pwd
- prefix = "-*- encoding : #{encoding} -*-\n"
+ prefix = "-*- encoding : #{encoding} -*-"
# TODO : add options for recursivity (and application of the script to a single file)
extensions = {
'rb' => '# {text}',
'rake' => '# {text}',
'haml' => '-# {text}',
+ 'erb' => '<%# {text} %>',
}
count = 0
@@ -34,12 +33,12 @@ def self.process(options)
lines = file.readlines
# remove current encoding comment(s)
- while lines[0].match(/^-?# ?(-\*-)? ?(en)?coding/)
+ while lines[0].match(/^(<%|-)?# ?(-\*-)? ?(en)?coding/)
lines.shift
end
# set current encoding
- lines.insert(0,comment_style.sub('{text}', prefix))
+ lines.insert(0, comment_style.sub('{text}', prefix) + "\n")
count += 1
file.pos = 0

0 comments on commit 44bbbf0

Please sign in to comment.