i18n_yaml_sorter 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem 'mechanize'
5
+
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+ rcov (0.9.11)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ jeweler (~> 1.6.4)
18
+ rcov
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Bernardo de Pádua
1
+ Copyright (c) 2010-2011 Bernardo de Pádua
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,14 +1,108 @@
1
1
  = i18n_yaml_sorter
2
2
 
3
- A simple and very limited yaml deep sorter that will not mess up your strings and text values. Made exclusively to sort the yaml commonly used in rails apps, specially i18n. It will not sort arrays, yaml objects. It doesn't use the YAML parser, since it would mess up text, but sorts the lines in the yaml file
4
3
 
5
- As your rails i18n app grows, it becomes very boring to keep all locale files in sync. You have to care about adding all keys in the same order, in different files, or you will get yourself into a mess and will lose lots of precious time comparing the files in different locales and looking for the appropriate translation keys whenever you want to change something.
4
+ A simple YAML Hash deep sorter that will not mess with the way your strings and text values were written. Made exclusively to sort the YAML Hash keys commonly used in the i18n gem and Rails' apps. It will not sort arrays, YAML objects, etc.
6
5
 
7
- If you try deserializing/serializing the yml files using the YAML parser, to get them in the same order, you will figure that your strings in the ymls will be "standarized" to whatever the YAML generator prefers (strings in double quotes). It will also mess up your indentation (and use its defaults).
6
+ It doesn't parse the YAML and dumps it again, it just sorts the lines, it's pure and simple magic! That way, it guarantees you can keep using your nice YAML constructs to create large text values, as we usually do in i18n files.
8
7
 
9
- i18n_yaml_sorter to the rescue! Add it to Textmate and you will be able to sort your yaml file in nanoseconds. Your file will look pristine, like it was human edited.
8
+ It includes a simple TextMate bundle and a rake task for Rails, so you can keep all those .yml files sorted in no time.
10
9
 
11
- == Example
10
+ == Motivation
11
+
12
+ As your rails i18n app grows, it becomes very boring to keep all locale files in sync. You have to add all keys in the same order, in different languages, or you will get yourself into a mess and will lose precious time comparing the files in different locales and looking for the appropriate translation keys whenever you want to change something or see if a key is missing.
13
+
14
+ If you try deserializing/serializing the yml files using the YAML parser, to get them in the same order, you will figure that your strings in the YAMLs will be "standarized" to whatever the YAML generator prefers (eg.: strings in double quotes, character escapes, etc). It will also mess up your indentation (and use its defaults) and remove your comments.
15
+
16
+ i18n_yaml_sorter to the rescue! Add it to TextMate and you will be able to sort your yaml file in nanoseconds. Your file will look pristine, like it was human edited.
17
+
18
+ Tested in ruby-1.8.7-p334 and ruby-1.9.2-p290, should work everywhere since it is so simple. Rake task works in Rails 3.1, not sure about older versions though (patch updates are welcome, if you find it doesn't).
19
+
20
+ == Simple Example
21
+ This:
22
+
23
+ pt-BR:
24
+ # Note how this is a nice way of inputing
25
+ # paragraphs of text in YAML.
26
+ apples: >
27
+ Maçãs são boas,
28
+ só não coma
29
+ seus iPods!
30
+ grapes: Não comemos elas.
31
+ bananas: |
32
+ Bananas são "legais":
33
+ - Elas são <b> doces </b>.
34
+ isto: não é chave
35
+
36
+ Por isto todos gostam de bananas!
37
+ en-US:
38
+ # Note that our comments are important:
39
+ # Don't let your yaml sorter delete them!
40
+ grapes: We dont' eat them.
41
+ bananas: |
42
+ Bananas are "nice":
43
+ - They are <b> sweet </b>.
44
+ this: not a key
45
+
46
+ That is why everyone like bananas!
47
+ apples: >
48
+ Apples are fine,
49
+ just don't eat your
50
+ iPods!
51
+
52
+
53
+ Becomes:
54
+
55
+ en-US:
56
+ # Note that our comments are important:
57
+ # Don't let your yaml sorter delete them!
58
+ apples: >
59
+ Apples are fine,
60
+ just don't eat your
61
+ iPods!
62
+ bananas: |
63
+ Bananas are "nice":
64
+ - They are <b> sweet </b>.
65
+ this: not a key
66
+
67
+ That is why everyone like bananas!
68
+ grapes: We dont' eat them.
69
+ pt-BR:
70
+ # Note how this is a nice way of inputing
71
+ # paragraphs of text in YAML.
72
+ apples: >
73
+ Maçãs são boas,
74
+ só não coma
75
+ seus iPods!
76
+ bananas: |
77
+ Bananas são "legais":
78
+ - Elas são <b> doces </b>.
79
+ isto: não é chave
80
+
81
+ Por isto todos gostam de bananas!
82
+ grapes: Não comemos elas.
83
+
84
+
85
+ What if you use some method that employ's Ruby's YAML library to help
86
+ do the task for you? You would get an output like that (note it removes your comments):
87
+
88
+ en-US:
89
+ apples: Apples are fine, just don't eat your iPods!
90
+ bananas: |
91
+ Bananas are "nice":
92
+ - They are <b> sweet </b>.
93
+ this: not a key
94
+
95
+ That is why everyone like bananas!
96
+
97
+ grapes: We dont' eat them.
98
+ pt-BR:
99
+ apples: "Ma\xC3\xA7\xC3\xA3s s\xC3\xA3o boas, s\xC3\xB3 n\xC3\xA3o coma seus iPods!\n"
100
+ bananas: "Bananas s\xC3\xA3o \"legais\":\n - Elas s\xC3\xA3o <b> doces </b>.\n isto: n\xC3\xA3o \xC3\xA9 chave\n\n\
101
+ Por isto todos gostam de bananas!\n"
102
+ grapes: "N\xC3\xA3o comemos elas."
103
+
104
+
105
+ == More complex example
12
106
 
13
107
  This:
14
108
 
@@ -23,7 +117,7 @@ This:
23
117
  lines in the same indentation.
24
118
  d_four: "We can also
25
119
  use the boring \"
26
- accross multiple lines
120
+ across multiple lines
27
121
  but have to escape then."
28
122
  e_five: Or you can do it
29
123
  like that as well, it also works.
@@ -64,7 +158,7 @@ Becomes:
64
158
  lines in the same indentation.
65
159
  d_four: "We can also
66
160
  use the boring \"
67
- accross multiple lines
161
+ across multiple lines
68
162
  but have to escape then."
69
163
  c_three:
70
164
  a: "Marcelo"
@@ -79,44 +173,53 @@ Becomes:
79
173
  e_five: Or you can do it
80
174
  like that as well, it also works.
81
175
 
82
- == Instaling
176
+ == Installing
83
177
 
84
178
  Easy, just install the gem:
85
179
 
86
180
  $ gem install i18n_yaml_sorter
87
181
 
88
- Then the +sort_yaml+ command line tool will be available. If you prefer using Ruby (in your rakes, etc), use the simple +I18nYamlSorter+ class.
182
+ Then the +sort_yaml+ command line tool will be available. If you prefer using Ruby (in your rakes, etc), use the simple +I18nYamlSorter::Sort+ class.
89
183
 
90
184
  == Textmate Bundle
91
185
 
92
- Run the Bundle Editor (Bundles > Bundle Editor > Show), and create a new command ( + > New Command ).
186
+ Run this command in the Terminal to install it:
93
187
 
94
- Erase the template code and write this command (no more, no less):
188
+ $ sort_yaml -i
95
189
 
96
- sort_yaml
190
+ A TextMate bundle, named "Yaml Sort" will be installed in your user home path. Press "Shift+Command+S" or use the Bundles menu to invoke it. The opened yaml file (or just the part of it that is selected) will be sorted. To edit the selected part of the file, make sure it is valid YAML by itself, or your yaml file might be corrupted (you can always Undo if you mess up).
97
191
 
98
- Add a key binding and a scope selector (source.yaml) if you which. Now, when you run this command, the opened yaml file (or just the part of it that is selected) will be sorted. To edit selected part of the file, make sure it is valid YAML by itself, or your yaml file might be corrupt (you can always Undo if you mess up).
192
+ == Rails Rake Taks
99
193
 
100
- == Command line
194
+ Declare it as a dependency in your app Gemfile, under the development group:
195
+
196
+ gem 'i18n_yaml_sorter', :group => :development
197
+
198
+ Run bundle install under your Rails' app:
199
+
200
+ $ bundle install
201
+
202
+ Now run the rake task under your Rails' app to sort all the i18n files in your +config/locales+ dir:
203
+
204
+ $rake i18n:sort
205
+
206
+ == Command line Input / Output
101
207
 
102
208
  +sort_yaml+ will operate on STDIN and STDOUT, so sorting an existing yaml file should be as easy as:
103
209
 
104
210
  $ sort_yaml < in.yml > out.yml
105
211
 
106
- TODO: Add command line arguments parsing and options (so you can, for instance, sort a whole dir of yaml) and inline help.
107
-
108
- == Rake task
212
+ TODO: Add command line arguments parsing and options, so you can, for instance, sort a whole dir of yaml files.
109
213
 
110
- If you don't use textmate, it should be trivial to add a rake task to sort all the i18n yaml files of a rails app (eg.: in the dir config/locale/ ), using the +sort_yaml+ command.
214
+ == Changelog
111
215
 
112
- TODO: Write the code here once I have time!
216
+ * 0.2 - Improves gem, tests, adds TextMate Bundle, adds Rails' Rake task.
217
+ * 0.1 - Initial release
113
218
 
114
219
  == Future improvements (Forks Welcome!)
115
220
 
116
221
  * Make +sort_yaml+ smart, take directories, etc
117
- * Make it a "gem plugin" so it will add rake tasks that will sort all yml files in your +I18n.load_path+ (make it configurable, since we usually don't want to sort all locale yamls, like the rails default ones).
118
- * Refactoring: code is still ugly, but works
119
- * Gather other existing rails i18n related yaml tools, textmate bundles, etc, make a super gem out of it, and rule the world!
222
+ * Refactoring: internal code is still a bit ugly, but works
120
223
 
121
224
  == Note on Patches/Pull Requests
122
225
 
@@ -130,4 +233,4 @@ TODO: Write the code here once I have time!
130
233
 
131
234
  == Copyright
132
235
 
133
- Copyright (c) 2010 Bernardo de Pádua. See LICENSE for details.
236
+ Copyright (c) 2010-2011 Bernardo de Pádua. MIT License (See LICENCE).
data/Rakefile CHANGED
@@ -1,10 +1,21 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
2
12
  require 'rake'
3
13
 
4
14
  begin
5
15
  require 'jeweler'
6
16
  Jeweler::Tasks.new do |gem|
7
17
  gem.name = "i18n_yaml_sorter"
18
+ gem.license = "MIT"
8
19
  gem.summary = %Q{ A I18n YAML deep sorter that will keep your locales organized and not screw up your text formating }
9
20
  gem.description = %Q{ Allows you to deep sort YAML files that are mainly composed of
10
21
  nested hashes and string values. Great to sort your rails I18n YAML files. You can easily
@@ -27,21 +38,14 @@ Rake::TestTask.new(:test) do |test|
27
38
  test.verbose = true
28
39
  end
29
40
 
30
- begin
31
- require 'rcov/rcovtask'
32
- Rcov::RcovTask.new do |test|
33
- test.libs << 'test'
34
- test.pattern = 'test/**/test_*.rb'
35
- test.verbose = true
36
- end
37
- rescue LoadError
38
- task :rcov do
39
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
- end
41
+ require 'rcov/rcovtask'
42
+ Rcov::RcovTask.new do |test|
43
+ test.libs << 'test'
44
+ test.pattern = 'test/**/test_*.rb'
45
+ test.verbose = true
46
+ test.rcov_opts << '--exclude "gems/*"'
41
47
  end
42
48
 
43
- task :test => :check_dependencies
44
-
45
49
  task :default => :test
46
50
 
47
51
  require 'rake/rdoctask'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,6 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'optparse'
3
+
2
4
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
5
  require 'i18n_yaml_sorter'
4
6
 
5
- sorter = I18nYamlSorter.new(STDIN)
6
- puts sorter.sort
7
+ options = {}
8
+ optparse = OptionParser.new do|opts|
9
+ opts.banner = "Usage: sort_yaml < INPUT > OUTPUT | sort_yaml --install_bundle"
10
+
11
+ # Define the options, and what they do
12
+ options[:install_bundle] = false
13
+ opts.on( '-i', '--install_bundle', 'Installs TextMate for MAC OS X bundle (named "YAML Sort") in the current user home dir.' ) do
14
+ options[:install_bundle] = true
15
+ end
16
+
17
+ # This displays the help screen, all programs are
18
+ # assumed to have this option.
19
+ opts.on( '-h', '--help', 'Display this screen' ) do
20
+ puts opts
21
+ exit
22
+ end
23
+ end
24
+
25
+ optparse.parse!
26
+
27
+ if options[:install_bundle]
28
+ puts "Installing TextMate Bundle in your home dir (~/Library/Application\\ Support/TextMate/Bundles/)..."
29
+ puts
30
+ system "mkdir -p ~/Library/Application\ Support/TextMate/Bundles"
31
+ system "cp -Rfv #{File.join(File.dirname(__FILE__), '..', 'textmate', 'YAML\ Sort.tmbundle')} ~/Library/Application\\ Support/TextMate/Bundles/ "
32
+ puts
33
+ puts "Reloading TextMate bundles..."
34
+ system "osascript -e 'tell app \"TextMate\" to reload bundles'"
35
+ else
36
+ sorter = I18nYamlSorter::Sorter.new(STDIN)
37
+ puts sorter.sort
38
+ end
@@ -1,59 +1,69 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{i18n_yaml_sorter}
8
- s.version = "0.1.1"
7
+ s.name = "i18n_yaml_sorter"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Bernardo de P\303\241dua"]
12
- s.date = %q{2010-03-11}
13
- s.default_executable = %q{sort_yaml}
14
- s.description = %q{ Allows you to deep sort YAML files that are mainly composed of
15
- nested hashes and string values. Great to sort your rails I18n YAML files. You can easily
16
- add it to a textmate bundle, rake task, or just use the included regular comand line tool.
17
- }
18
- s.email = %q{berpasan@gmail.com}
11
+ s.authors = ["Bernardo de P\u{e1}dua"]
12
+ s.date = "2011-11-29"
13
+ s.description = " Allows you to deep sort YAML files that are mainly composed of \n nested hashes and string values. Great to sort your rails I18n YAML files. You can easily\n add it to a textmate bundle, rake task, or just use the included regular comand line tool. \n "
14
+ s.email = "berpasan@gmail.com"
19
15
  s.executables = ["sort_yaml"]
20
16
  s.extra_rdoc_files = [
21
17
  "LICENSE",
22
- "README.rdoc"
18
+ "README.rdoc"
23
19
  ]
24
20
  s.files = [
25
21
  ".document",
26
- ".gitignore",
27
- "LICENSE",
28
- "README.rdoc",
29
- "Rakefile",
30
- "VERSION",
31
- "bin/sort_yaml",
32
- "i18n_yaml_sorter.gemspec",
33
- "lib/i18n_yaml_sorter.rb",
34
- "test/helper.rb",
35
- "test/in.yml",
36
- "test/out.yml",
37
- "test/test_i18n_yaml_sorter.rb"
38
- ]
39
- s.homepage = %q{http://github.com/redealumni/i18n_yaml_sorter}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
- s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.6}
43
- s.summary = %q{A I18n YAML deep sorter that will keep your locales organized and not screw up your text formating}
44
- s.test_files = [
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "bin/sort_yaml",
29
+ "i18n_yaml_sorter.gemspec",
30
+ "lib/i18n_yaml_sorter.rb",
31
+ "lib/i18n_yaml_sorter/railtie.rb",
32
+ "lib/i18n_yaml_sorter/sorter.rb",
33
+ "lib/tasks/i18n_yaml_sorter.rake",
45
34
  "test/helper.rb",
46
- "test/test_i18n_yaml_sorter.rb"
35
+ "test/in.yml",
36
+ "test/in_rails.yml",
37
+ "test/in_simple.yml",
38
+ "test/out.yml",
39
+ "test/out_rails.yml",
40
+ "test/out_simple.yml",
41
+ "test/test_i18n_yaml_sorter.rb",
42
+ "textmate/YAML Sort.tmbundle/Commands/Sort YAML.tmCommand",
43
+ "textmate/YAML Sort.tmbundle/info.plist"
47
44
  ]
45
+ s.homepage = "http://github.com/redealumni/i18n_yaml_sorter"
46
+ s.licenses = ["MIT"]
47
+ s.require_paths = ["lib"]
48
+ s.rubygems_version = "1.8.10"
49
+ s.summary = "A I18n YAML deep sorter that will keep your locales organized and not screw up your text formating"
48
50
 
49
51
  if s.respond_to? :specification_version then
50
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
52
  s.specification_version = 3
52
53
 
53
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_development_dependency(%q<rcov>, [">= 0"])
54
58
  else
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
55
62
  end
56
63
  else
64
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
66
+ s.add_dependency(%q<rcov>, [">= 0"])
57
67
  end
58
68
  end
59
69
 
@@ -1,128 +1,2 @@
1
- class I18nYamlSorter
2
-
3
- def initialize(io_input)
4
- @io_input = io_input
5
- end
6
-
7
- def sort
8
- @array = break_blocks_into_array
9
- @current_array_index = 0
10
- sorted_yaml_from_blocks_array
11
- end
12
-
13
- private
14
-
15
- def break_blocks_into_array
16
- array = []
17
-
18
- loop do
19
-
20
- maybe_next_line = @read_line_again || @io_input.gets || break
21
- @read_line_again = nil
22
- maybe_next_line.chomp!
23
-
24
- #Is it blank? Discard!
25
- next if maybe_next_line.match(/^\s*$/)
26
-
27
- #Does it look like a key: value line?
28
- key_value_parse = maybe_next_line.match(/^(\s*)(["']?[\w\-]+["']?)(: )(\s*)(\S.*\S)(\s*)$/)
29
- if key_value_parse
30
- array << maybe_next_line.concat("\n") #yes, it is the beginning of a key:value block
31
-
32
- #Special cases when it should add extra lines to the array element (multi line quoted strings)
33
-
34
- #Is the value surrounded by quotes?
35
- starts_with_quote = key_value_parse[5].match(/^["']/)[0] rescue nil
36
- ends_with_quote = key_value_parse[5].match(/[^\\](["'])$/)[1] rescue nil
37
- if starts_with_quote and !(starts_with_quote == ends_with_quote)
38
-
39
- loop do #Append next lines until we find the closing quote
40
- content_line = @io_input.gets || break
41
- content_line.chomp!
42
- array.last << content_line.concat("\n")
43
- break if content_line.match(/[^\\][#{starts_with_quote}]\s*$/)
44
- end
45
-
46
- end # if starts_with_quote
47
-
48
- next
49
- end # if key_value_parse
50
-
51
- # Is it a | or > string alue?
52
- is_special_string = maybe_next_line.match(/^(\s*)(["']?[\w\-]+["']?)(: )(\s*)([|>])(\s*)$/)
53
- if is_special_string
54
- array << maybe_next_line.concat("\n") #yes, it is the beginning of a key block
55
- indentation = is_special_string[1]
56
- #Append the next lines until we find one that is not indented
57
- loop do
58
- content_line = @io_input.gets || break
59
- processed_line = content_line.chomp
60
- this_indentation = processed_line.match(/^\s*/)[0] rescue ""
61
- if indentation.size < this_indentation.size
62
- array.last << processed_line.concat("\n")
63
- else
64
- @read_line_again = content_line
65
- break
66
- end
67
- end
68
-
69
- next
70
- end #if is_special_string
71
-
72
- # Is it the begining of a multi level hash?
73
- is_start_of_hash = maybe_next_line.match(/^(\s*)(["']?[\w\-]+["']?)(:)(\s*)$/)
74
- if is_start_of_hash
75
- array << maybe_next_line.concat("\n")
76
- next
77
- end
78
-
79
- #If we got here and nothing was done, this line
80
- # should probably be merged with the previous one.
81
- if array.last
82
- array.last << maybe_next_line.concat("\n")
83
- else
84
- array << maybe_next_line.concat("\n")
85
- end
86
- end #loop
87
-
88
- #debug:
89
- #puts array.join("$$$$$$$$$$$$$$$$$$$$$$\n")
90
-
91
- array
92
- end
93
-
94
- def sorted_yaml_from_blocks_array(current_block = nil)
95
-
96
- unless current_block
97
- current_block = @array[@current_array_index]
98
- @current_array_index += 1
99
- end
100
-
101
- out_array = []
102
- current_match = current_block.match(/^(\s*)(["']?[\w\-]+["']?)(:)/)
103
- current_level = current_match[1] rescue ''
104
- current_key = current_match[2].downcase.tr(%q{"'}, "") rescue ''
105
- out_array << [current_key, current_block]
106
-
107
- loop do
108
- next_block = @array[@current_array_index] || break
109
- @current_array_index += 1
110
-
111
- current_match = next_block.match(/^(\s*)(["']?[\w\-]+["']?)(:)/) || next
112
- current_key = current_match[2].downcase.tr(%q{"'}, "")
113
- next_level = current_match[1]
114
-
115
- if current_level.size < next_level.size
116
- out_array.last.last << sorted_yaml_from_blocks_array(next_block)
117
- elsif current_level.size == next_level.size
118
- out_array << [current_key, next_block]
119
- elsif current_level.size > next_level.size
120
- @current_array_index -= 1
121
- break
122
- end
123
- end
124
-
125
- return out_array.sort.map(&:last).join
126
- end
127
-
128
- end
1
+ require 'i18n_yaml_sorter/sorter'
2
+ require 'i18n_yaml_sorter/railtie'