Skip to content

kapcsandi/magic_encoding

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magic encoding

Magic Encoding is a little tool that allows you to quickly add or modify the magic comments that indicate source file encoding for an entire directory structure, please note that this tool only sets the comments, and does not perform any file encoding conversion whatsoever.

If you are looking for a way to convert files to a specific encoding, check out iconv (GNU)

I originally wrote this to get rid of “invalid multibyte char (US-ASCII)” errors when writing strings containing non ascii characters like éöàüèä in ruby on rails controllers

Installation

gem install magic_encoding

Usage

you can call the tool from the console with default parameters like so

magic_encoding

this will prepend every “.rb” file in the working directory (recursively) with the following line :

# -*- encoding : utf-8 -*-
  • existing magic comments are replaced

  • the rest of the file remains unchanged

Optional parameters

you can pass options to the tool to specify the desired encoding and the path where you want the tool to run, for example :

--encoding, -e 
Default: utf-8

--path, -p 
Default: . (current directory)

--files, -f
Default: *.rb

Example:

magic_encoding --encoding Shift-JIS --path /path/to/ruby/project --files *.erb

For more information on ruby >= 1.9 encoding features, check out blog.grayproductions.net/articles/ruby_19s_three_default_encodings

About

Easily manage magic comments for encoding for your ruby 1.9 applications

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%