helloh 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/helloh CHANGED
@@ -11,18 +11,7 @@ require "helloh"
11
11
 
12
12
  directory = ARGV[0] || "./config/locales"
13
13
 
14
- helloh = Helloh.new
14
+ helloh = Helloh::Compare.new
15
15
  helloh.files = Dir.glob(File.join(directory, "*.yml"))
16
16
  helloh.compare!
17
-
18
- status_code = 0
19
-
20
- helloh.results.each_pair do |file, errors|
21
- if errors[:missing].any?
22
- status_code = 1
23
- puts "\nMissing keys in #{file}"
24
- puts errors[:missing].map{ |key| "- #{key}" }
25
- end
26
- end
27
-
28
- exit status_code
17
+ helloh.output_results!
@@ -1,48 +1,15 @@
1
1
  require "yaml"
2
2
 
3
- class Helloh
4
- attr_accessor :files
5
- attr_reader :results
3
+ module Helloh
4
+ VERSION = "0.2"
6
5
 
7
- def initialize # {{{
8
- @results = {}
9
- @files = []
10
- end # }}}
6
+ autoload :Compare, "helloh/compare"
7
+ autoload :Railtie, "helloh/railtie"
11
8
 
12
- def compare! # {{{
13
- files.each do |file|
14
- @file = File.basename(file)
15
-
16
- files.each do |other_file|
17
- next if file == other_file
18
- @other_file = File.basename(other_file)
19
- @results[@other_file] ||= { :missing => [] }
20
- compare_yaml_hash(YAML.load_file(file)[Helloh.lang_from_filename(file)], YAML.load_file(other_file)[Helloh.lang_from_filename(other_file)])
21
- end
22
-
23
- end
24
- end # }}}
25
-
26
- private
27
-
28
- def compare_yaml_hash(content1, content2, context = []) # {{{
29
- content1.each do |key, value|
30
-
31
- path = "#{(context+[key]).join(".")}"
32
- unless content2.include?(key)
33
- @results[@other_file][:missing] << path unless @results[@other_file][:missing].include?(path)
34
- next
35
- end
36
-
37
- if value.is_a?(Hash)
38
- compare_yaml_hash(value, content2[key], (context.dup << key))
39
- next
40
- end
41
- end
42
- end # }}}
43
-
44
- def self.lang_from_filename(file) # {{{
45
- file.match(/([^\/]+)\.yml$/)[1]
46
- end # }}}
9
+ def self.lang_from_filename(file) # {{{
10
+ file.match(/([^\/]+)\.yml$/)[1]
11
+ end # }}}
47
12
 
48
13
  end
14
+
15
+ require "helloh/railtie" if defined?(Rails)
@@ -0,0 +1,54 @@
1
+ module Helloh
2
+ class Compare
3
+
4
+ attr_accessor :files
5
+ attr_reader :results
6
+
7
+ def initialize # {{{
8
+ @results = {}
9
+ @files = []
10
+ end # }}}
11
+
12
+ def compare! # {{{
13
+ files.each do |file|
14
+ @file = File.basename(file)
15
+
16
+ files.each do |other_file|
17
+ next if file == other_file
18
+ @other_file = File.basename(other_file)
19
+ @results[@other_file] ||= { :missing => [] }
20
+ compare_yaml_hash(YAML.load_file(file)[Helloh.lang_from_filename(file)], YAML.load_file(other_file)[Helloh.lang_from_filename(other_file)])
21
+ end
22
+
23
+ end
24
+ end # }}}
25
+
26
+ def output_results! # {{{
27
+ @results.each_pair do |file, errors|
28
+ if errors[:missing].any?
29
+ puts "\nMissing keys in #{file}"
30
+ puts errors[:missing].map{ |key| "- #{key}" }
31
+ end
32
+ end
33
+ end # }}}
34
+
35
+ private
36
+
37
+ def compare_yaml_hash(content1, content2, context = []) # {{{
38
+ content1.each do |key, value|
39
+
40
+ path = "#{(context+[key]).join(".")}"
41
+ unless content2.include?(key)
42
+ @results[@other_file][:missing] << path unless @results[@other_file][:missing].include?(path)
43
+ next
44
+ end
45
+
46
+ if value.is_a?(Hash)
47
+ compare_yaml_hash(value, content2[key], (context.dup << key))
48
+ next
49
+ end
50
+ end
51
+ end # }}}
52
+
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ require "helloh"
2
+ require "rails"
3
+
4
+ module Helloh
5
+ class Railtie < Rails::Railtie
6
+
7
+ rake_tasks do # {{{
8
+ load "tasks/helloh.rake"
9
+ end # }}}
10
+
11
+ end
12
+ end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helloh
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- version: "0.1"
8
+ - 2
9
+ version: "0.2"
10
10
  platform: ruby
11
11
  authors:
12
12
  - "R\xC3\xA9mi Pr\xC3\xA9vost"
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-09-03 00:00:00 Z
17
+ date: 2011-09-04 00:00:00 Z
18
18
  dependencies: []
19
19
 
20
20
  description: Helloh compares Rails localization files and looks for missing keys.
@@ -26,6 +26,8 @@ extensions: []
26
26
  extra_rdoc_files: []
27
27
 
28
28
  files:
29
+ - lib/helloh/compare.rb
30
+ - lib/helloh/railtie.rb
29
31
  - lib/helloh.rb
30
32
  - README.mkd
31
33
  - LICENSE