magic-commenter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in magic-commenter.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,15 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ magic-commenter (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ bundler (>= 1.0.0)
15
+ magic-commenter!
data/README.md ADDED
@@ -0,0 +1,9 @@
1
+ magic-commenter
2
+ ===============
3
+
4
+ Install and execute:
5
+
6
+ $ [sudo] gem install magic-commenter
7
+ $ magic-commenter
8
+
9
+ It will iterate through all your .rb files and add utf8 magic comment if the paring fails with a multibyte error.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+
4
+ require 'magic-commenter'
5
+
6
+ Magic::Commenter.new(Dir["**/*.rb"])
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'stringio'
3
+ require 'open3'
4
+
5
+ module Magic
6
+ class Commenter
7
+
8
+ include Open3
9
+
10
+ def initialize(files)
11
+ for file in files
12
+ errors = []
13
+ popen3("ruby -c #{file}") do |stdin, stdout, stderr|
14
+ errors = stderr.read.split("\n")
15
+ end
16
+
17
+ if errors.any?{|error| error.include?("invalid multibyte char")}
18
+ puts ">> Fixing #{file}"
19
+ add_magic_comment(file)
20
+ end
21
+ end
22
+ end
23
+
24
+ def add_magic_comment(file)
25
+ contents = "# -*- encoding: utf-8 -*-\n" + File.read(file)
26
+ File.open(file,"w") do |f|
27
+ f.write contents
28
+ f.close
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ module Magic
2
+ class Commenter
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/magic-commenter/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "magic-commenter"
6
+ s.version = Magic::Commenter::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Albert llop"]
9
+ s.email = ["mrsimo@gmail.com"]
10
+ s.summary = "Add magic comments to your ruby files"
11
+
12
+ s.required_rubygems_version = ">= 1.3.6"
13
+ s.rubyforge_project = "magic-commenter"
14
+
15
+ s.add_development_dependency "bundler", ">= 1.0.0"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.executables = ["magic-commenter"]
19
+ s.require_path = 'lib'
20
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magic-commenter
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Albert llop
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-15 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ description:
36
+ email:
37
+ - mrsimo@gmail.com
38
+ executables:
39
+ - magic-commenter
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - Gemfile.lock
48
+ - README.md
49
+ - Rakefile
50
+ - bin/magic-commenter
51
+ - lib/magic-commenter.rb
52
+ - lib/magic-commenter/version.rb
53
+ - magic-commenter.gemspec
54
+ has_rdoc: true
55
+ homepage:
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 6
80
+ version: 1.3.6
81
+ requirements: []
82
+
83
+ rubyforge_project: magic-commenter
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Add magic comments to your ruby files
88
+ test_files: []
89
+