encoding_magic 0.0.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/CHANGELOG +3 -0
- data/LICENCE +5 -0
- data/README.md +29 -0
- data/bin/encoding_magic +7 -0
- data/lib/encoding_magic.rb +59 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c283f4c09418df4298e68b3183c9d16db1724f1
|
4
|
+
data.tar.gz: 7a36b8ae3ede215d27254288647db0b26323326f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3d76cbade4ac22a430952eb4b3dfaa6754ef7b22c64ef9eb641dad9fcad7927d9de0caa7d01516d6c214c7822e727d1af8ced6b7a104f4b5a3330893d9e02b56
|
7
|
+
data.tar.gz: caee6b38d922162f17db4c10eae0a83bd7ec633987840baf59261c1361d58d97254e1e4e51c9b78ba2fcfdad9bc4b2c503cecb7d407b446ac56af8024b456ab3
|
data/CHANGELOG
ADDED
data/LICENCE
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
Copyright (c) 2012 Pokka
|
2
|
+
> This song is Copyrighted in U.S., under Seal of Copyright #154085, for a period of 28
|
3
|
+
> years, and anybody caught singin it without our permission, will be mighty good friends
|
4
|
+
> of ourn, cause we don’t give a dern. Publish it. Write it. Sing it. Swing to it. Yodel
|
5
|
+
> it. We wrote it, that’s all we wanted to do.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= encoding Magic
|
2
|
+
|
3
|
+
revert magic_encoding
|
4
|
+
|
5
|
+
just little modify from [magic_encoding](https://github.com/m-ryan/magic_encoding)
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
gem install encoding_magic
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
you can call the tool from the console with default parameters like so
|
14
|
+
|
15
|
+
encoding_magic
|
16
|
+
|
17
|
+
this will striped every ".rb" file in the working directory (recursively) with the following line :
|
18
|
+
|
19
|
+
# -*- encoding : utf-8 -*-
|
20
|
+
|
21
|
+
Notes :
|
22
|
+
- Don't use without git
|
23
|
+
- Don't commit with other changes
|
24
|
+
- existing magic comments are replaced
|
25
|
+
- the rest of the file remains unchanged
|
26
|
+
|
27
|
+
you can pass options to the tool to specify the desired encoding and the path where you want the tool to run, for example :
|
28
|
+
|
29
|
+
encoding_magic 'utf-8' /path/to/ruby/project
|
data/bin/encoding_magic
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# A simple library to remove magic comments for encoding to multiple ".rb" files
|
2
|
+
|
3
|
+
module StripMagicComment
|
4
|
+
|
5
|
+
# Options :
|
6
|
+
# 1 : Encoding
|
7
|
+
# 2 : Path
|
8
|
+
def self.process(options)
|
9
|
+
|
10
|
+
# defaults
|
11
|
+
encoding = options[0] || "utf-8"
|
12
|
+
directory = options[1] || Dir.pwd
|
13
|
+
|
14
|
+
prefix = "-*- encoding : #{encoding} -*-\n"
|
15
|
+
|
16
|
+
|
17
|
+
extensions = {
|
18
|
+
'rb' => '# {text}',
|
19
|
+
'rake' => '# {text}',
|
20
|
+
'haml' => '-# {text}',
|
21
|
+
}
|
22
|
+
|
23
|
+
count = 0
|
24
|
+
extensions.each do |ext, comment_style|
|
25
|
+
rbfiles = File.join(directory ,'**', '*.'+ext)
|
26
|
+
Dir.glob(rbfiles).each do |filename|
|
27
|
+
file = File.new(filename, "r+")
|
28
|
+
|
29
|
+
lines = file.readlines.to_a
|
30
|
+
striped = 0
|
31
|
+
# remove current encoding comment(s)
|
32
|
+
while lines[0].respond_to?(:match) && lines[0].match(/#{encoding}/)
|
33
|
+
lines.shift
|
34
|
+
striped += 1
|
35
|
+
end
|
36
|
+
|
37
|
+
if striped > 0
|
38
|
+
count += 1
|
39
|
+
end
|
40
|
+
|
41
|
+
file.pos = 0
|
42
|
+
file.truncate(0)
|
43
|
+
file.puts(lines.join)
|
44
|
+
file.close
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
puts "Magic comments striped for #{count} source files"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
class String
|
54
|
+
|
55
|
+
def starts_with?(s)
|
56
|
+
self[0..s.length-1] == s
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: encoding_magic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Manuel Ryan
|
8
|
+
- Pokka
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
- ifunafu@gmail.com
|
17
|
+
executables:
|
18
|
+
- encoding_magic
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- CHANGELOG
|
23
|
+
- LICENCE
|
24
|
+
- README.md
|
25
|
+
- bin/encoding_magic
|
26
|
+
- lib/encoding_magic.rb
|
27
|
+
homepage: https://github.com/pokka/encoding_magic
|
28
|
+
licenses:
|
29
|
+
- Woody Guthrie free culture
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.3.6
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.2.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Easily strip magic comments for encoding on multiple ruby source files
|
51
|
+
test_files: []
|