magic-comment 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/CHANGELOG +16 -0
- data/LICENCE +25 -0
- data/README.md +37 -0
- data/bin/magic-comment +9 -0
- data/lib/magic-comment.rb +62 -0
- data/magic-comment.gemspec +14 -0
- metadata +52 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8759d94126074281260c6967480931af6007b40f
|
4
|
+
data.tar.gz: 03d5dcd730d9749aa756ae29902108eae2c09795
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1dbda8d5034ba96b1b1eef45476fef5462fb688f70a815dbbba96bc740cb8fd8c471dda7db8f45abcf37f4e7d68fb45562f48a3055e00e3e13e6439f52d61be4
|
7
|
+
data.tar.gz: 9fe193e86528cf25620653fe21b81d4745177b3ae10cf52b23c0b89bc58479f6f0eba3c51885b5ff633e661a737a266b697c293e94a780092180bcb0809d8e8f
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.gem
|
data/CHANGELOG
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## 0.0.1 (August 3, 2010)
|
2
|
+
|
3
|
+
Initial Version
|
4
|
+
|
5
|
+
## 0.0.2 (August 3, 2010)
|
6
|
+
|
7
|
+
Existing magic comments are now erased before the file is prepended with the desired magic comment
|
8
|
+
Bugfixes
|
9
|
+
|
10
|
+
## 0.0.3 (December 12, 2014)
|
11
|
+
|
12
|
+
Supporting for Multiple paths
|
13
|
+
|
14
|
+
## 0.1.0 (December 12, 2014)
|
15
|
+
|
16
|
+
Rename to magic_comment
|
data/LICENCE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Copyright (c) 2014 Lohn IMAI
|
2
|
+
|
3
|
+
|
4
|
+
ORIGINAL PROGRAM
|
5
|
+
https://github.com/m-ryan/magic_encoding
|
6
|
+
Copyright (c) 2010 Manuel Ryan
|
7
|
+
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
9
|
+
a copy of this software and associated documentation files (the
|
10
|
+
"Software"), to deal in the Software without restriction, including
|
11
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
12
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
13
|
+
permit persons to whom the Software is furnished to do so, subject to
|
14
|
+
the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be
|
17
|
+
included in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
21
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
23
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
24
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
25
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Magic Comment
|
2
|
+
|
3
|
+
Magic Comment is a little tool that allows you to quickly
|
4
|
+
add or modify the magic comments that indicate source file
|
5
|
+
encoding for an entire directory structure, please note that
|
6
|
+
this tool only sets the comments, and does not perform any
|
7
|
+
file encoding conversion whatsoever.
|
8
|
+
|
9
|
+
If you are looking for a way to convert files to a specific encoding, check out iconv (GNU)
|
10
|
+
|
11
|
+
I originally wrote this to get rid of "invalid multibyte char (US-ASCII)"
|
12
|
+
errors when writing strings containing non ascii characters like éöàüèä
|
13
|
+
in ruby on rails controllers
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
```
|
18
|
+
gem install magic-comment
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
you can pass the path to where you want the tool to run.
|
24
|
+
|
25
|
+
```
|
26
|
+
magic-comment [path1 [path2 ...]]
|
27
|
+
```
|
28
|
+
|
29
|
+
this will prepend every ".rb", ".rake" and ".haml" file in the working directory (recursively) with the following line :
|
30
|
+
|
31
|
+
```
|
32
|
+
# coding: utf-8
|
33
|
+
```
|
34
|
+
|
35
|
+
Notes :
|
36
|
+
- existing magic comments are replaced
|
37
|
+
- the rest of the file remains unchanged
|
data/bin/magic-comment
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# A simple library to prepend magic comments for encoding to multiple ".rb" files
|
3
|
+
require 'pathname'
|
4
|
+
|
5
|
+
module MagicComment
|
6
|
+
|
7
|
+
# Options :
|
8
|
+
# - paths
|
9
|
+
def self.process(*paths)
|
10
|
+
# defaults
|
11
|
+
paths.flatten!
|
12
|
+
paths.push Dir.pwd if paths.empty?
|
13
|
+
|
14
|
+
encoding = "coding: utf-8"
|
15
|
+
default_comment = "# {encoding}\n"
|
16
|
+
|
17
|
+
# TODO : add options for recursivity (and application of the script to a single file)
|
18
|
+
extensions = {
|
19
|
+
'.rb' => default_comment,
|
20
|
+
'.rake' => default_comment,
|
21
|
+
'.haml' => "-#{default_comment}",
|
22
|
+
}
|
23
|
+
|
24
|
+
files = []
|
25
|
+
paths.each do |path|
|
26
|
+
path = Pathname.new path
|
27
|
+
if path.file?
|
28
|
+
files.push path
|
29
|
+
elsif path.directory?
|
30
|
+
files += Dir.glob path.join('**', "*{#{extensions.keys.join ','}}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
default_comment.sub! '{encoding}', encoding
|
35
|
+
extensions.each_key do |key|
|
36
|
+
extensions[key].sub! '{encoding}', encoding
|
37
|
+
end
|
38
|
+
|
39
|
+
files.each do |filename|
|
40
|
+
file = File.new(filename, "r+")
|
41
|
+
magic_comment = extensions[ File.extname(file) ] || default_comment
|
42
|
+
lines = file.readlines
|
43
|
+
|
44
|
+
# remove current encoding comment(s)
|
45
|
+
while lines[0].match(/^-?# ?(-\*-)? ?(en)?coding/)
|
46
|
+
lines.shift
|
47
|
+
end
|
48
|
+
|
49
|
+
# set current encoding
|
50
|
+
lines.unshift magic_comment
|
51
|
+
|
52
|
+
body = lines.join
|
53
|
+
|
54
|
+
file.pos = 0
|
55
|
+
file.write body
|
56
|
+
file.truncate(body.bytesize)
|
57
|
+
file.close
|
58
|
+
end
|
59
|
+
|
60
|
+
puts "Magic comments set for #{files.length} source files"
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = 'magic-comment'
|
4
|
+
gem.version = "0.1.1"
|
5
|
+
gem.authors = ["Lohn IMAI"]
|
6
|
+
gem.email = ["mail@lohn.me"]
|
7
|
+
gem.homepage = 'http://github.com/m8x/magic-comment'
|
8
|
+
gem.summary = 'Easily add magic comments for encoding on multiple ruby source files'
|
9
|
+
gem.licenses = ['MIT']
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($/)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{|f| File.basename(f) }
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: magic-comment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lohn IMAI
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- mail@lohn.me
|
16
|
+
executables:
|
17
|
+
- magic-comment
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".gitignore"
|
22
|
+
- CHANGELOG
|
23
|
+
- LICENCE
|
24
|
+
- README.md
|
25
|
+
- bin/magic-comment
|
26
|
+
- lib/magic-comment.rb
|
27
|
+
- magic-comment.gemspec
|
28
|
+
homepage: http://github.com/m8x/magic-comment
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata: {}
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 2.2.2
|
49
|
+
signing_key:
|
50
|
+
specification_version: 4
|
51
|
+
summary: Easily add magic comments for encoding on multiple ruby source files
|
52
|
+
test_files: []
|