slimkeyfy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +3 -0
  4. data/Gemfile +6 -0
  5. data/Gemfile.lock +22 -0
  6. data/LICENSE +21 -0
  7. data/README.md +172 -0
  8. data/bin/slimkeyfy +5 -0
  9. data/lib/.DS_Store +0 -0
  10. data/lib/slimkeyfy/console/command_line.rb +90 -0
  11. data/lib/slimkeyfy/console/io_action.rb +30 -0
  12. data/lib/slimkeyfy/console/printer.rb +50 -0
  13. data/lib/slimkeyfy/console/translate.rb +101 -0
  14. data/lib/slimkeyfy/console.rb +8 -0
  15. data/lib/slimkeyfy/slimutils/file_utils.rb +61 -0
  16. data/lib/slimkeyfy/slimutils/hash_merging.rb +84 -0
  17. data/lib/slimkeyfy/slimutils/key_generator.rb +70 -0
  18. data/lib/slimkeyfy/slimutils/yaml_processor.rb +56 -0
  19. data/lib/slimkeyfy/slimutils.rb +8 -0
  20. data/lib/slimkeyfy/transformer/base_transformer.rb +42 -0
  21. data/lib/slimkeyfy/transformer/controller_transformer.rb +20 -0
  22. data/lib/slimkeyfy/transformer/slim_transformer.rb +92 -0
  23. data/lib/slimkeyfy/transformer/whitespacer.rb +48 -0
  24. data/lib/slimkeyfy/transformer/word.rb +49 -0
  25. data/lib/slimkeyfy/transformer.rb +9 -0
  26. data/lib/slimkeyfy/version.rb +3 -0
  27. data/lib/slimkeyfy.rb +12 -0
  28. data/slimkeyfy.gemspec +21 -0
  29. data/vendor/bundle/bin/htmldiff +25 -0
  30. data/vendor/bundle/bin/ldiff +25 -0
  31. data/vendor/bundle/bin/rspec +23 -0
  32. data/vendor/bundle/build_info/diff-lcs-1.2.5.info +1 -0
  33. data/vendor/bundle/build_info/rspec-3.0.0.info +1 -0
  34. data/vendor/bundle/build_info/rspec-core-3.0.2.info +1 -0
  35. data/vendor/bundle/build_info/rspec-expectations-3.0.2.info +1 -0
  36. data/vendor/bundle/build_info/rspec-mocks-3.0.2.info +1 -0
  37. data/vendor/bundle/build_info/rspec-support-3.0.2.info +1 -0
  38. data/vendor/bundle/gems/diff-lcs-1.2.5/.autotest +3 -0
  39. data/vendor/bundle/gems/diff-lcs-1.2.5/.gemtest +0 -0
  40. data/vendor/bundle/gems/diff-lcs-1.2.5/.hoerc +2 -0
  41. data/vendor/bundle/gems/diff-lcs-1.2.5/.rspec +2 -0
  42. data/vendor/bundle/gems/diff-lcs-1.2.5/.travis.yml +22 -0
  43. data/vendor/bundle/gems/diff-lcs-1.2.5/Contributing.rdoc +64 -0
  44. data/vendor/bundle/gems/diff-lcs-1.2.5/Gemfile +20 -0
  45. data/vendor/bundle/gems/diff-lcs-1.2.5/History.rdoc +152 -0
  46. data/vendor/bundle/gems/diff-lcs-1.2.5/License.rdoc +39 -0
  47. data/vendor/bundle/gems/diff-lcs-1.2.5/Manifest.txt +38 -0
  48. data/vendor/bundle/gems/diff-lcs-1.2.5/README.rdoc +85 -0
  49. data/vendor/bundle/gems/diff-lcs-1.2.5/Rakefile +41 -0
  50. data/vendor/bundle/gems/diff-lcs-1.2.5/autotest/discover.rb +1 -0
  51. data/vendor/bundle/gems/diff-lcs-1.2.5/bin/htmldiff +32 -0
  52. data/vendor/bundle/gems/diff-lcs-1.2.5/bin/ldiff +6 -0
  53. data/vendor/bundle/gems/diff-lcs-1.2.5/docs/COPYING.txt +339 -0
  54. data/vendor/bundle/gems/diff-lcs-1.2.5/docs/artistic.txt +127 -0
  55. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/array.rb +7 -0
  56. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/block.rb +37 -0
  57. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/callbacks.rb +322 -0
  58. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/change.rb +177 -0
  59. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/htmldiff.rb +149 -0
  60. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/hunk.rb +276 -0
  61. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/internals.rb +301 -0
  62. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/ldiff.rb +195 -0
  63. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs/string.rb +5 -0
  64. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff/lcs.rb +805 -0
  65. data/vendor/bundle/gems/diff-lcs-1.2.5/lib/diff-lcs.rb +3 -0
  66. data/vendor/bundle/gems/rspec-3.0.0/License.txt +24 -0
  67. data/vendor/bundle/gems/rspec-3.0.0/README.md +47 -0
  68. data/vendor/bundle/gems/rspec-3.0.0/lib/rspec.rb +3 -0
  69. data/vendor/bundle/gems/rspec-core-3.0.2/.document +5 -0
  70. data/vendor/bundle/gems/rspec-core-3.0.2/.yardopts +7 -0
  71. data/vendor/bundle/gems/rspec-core-3.0.2/Changelog.md +1466 -0
  72. data/vendor/bundle/gems/rspec-core-3.0.2/License.txt +25 -0
  73. data/vendor/bundle/gems/rspec-core-3.0.2/README.md +243 -0
  74. data/vendor/bundle/gems/rspec-core-3.0.2/exe/rspec +4 -0
  75. data/vendor/bundle/gems/rspec-expectations-3.0.2/.document +5 -0
  76. data/vendor/bundle/gems/rspec-expectations-3.0.2/.yardopts +6 -0
  77. data/vendor/bundle/gems/rspec-expectations-3.0.2/Changelog.md +749 -0
  78. data/vendor/bundle/gems/rspec-expectations-3.0.2/License.txt +24 -0
  79. data/vendor/bundle/gems/rspec-expectations-3.0.2/README.md +278 -0
  80. data/vendor/bundle/gems/rspec-mocks-3.0.2/.document +5 -0
  81. data/vendor/bundle/gems/rspec-mocks-3.0.2/.yardopts +6 -0
  82. data/vendor/bundle/gems/rspec-mocks-3.0.2/Changelog.md +733 -0
  83. data/vendor/bundle/gems/rspec-mocks-3.0.2/License.txt +24 -0
  84. data/vendor/bundle/gems/rspec-mocks-3.0.2/README.md +380 -0
  85. data/vendor/bundle/gems/rspec-support-3.0.2/Changelog.md +30 -0
  86. data/vendor/bundle/gems/rspec-support-3.0.2/LICENSE.txt +22 -0
  87. data/vendor/bundle/gems/rspec-support-3.0.2/README.md +17 -0
  88. data/vendor/bundle/specifications/diff-lcs-1.2.5.gemspec +68 -0
  89. data/vendor/bundle/specifications/rspec-3.0.0.gemspec +43 -0
  90. data/vendor/bundle/specifications/rspec-core-3.0.2.gemspec +66 -0
  91. data/vendor/bundle/specifications/rspec-expectations-3.0.2.gemspec +51 -0
  92. data/vendor/bundle/specifications/rspec-mocks-3.0.2.gemspec +48 -0
  93. data/vendor/bundle/specifications/rspec-support-3.0.2.gemspec +42 -0
  94. metadata +153 -0
@@ -0,0 +1,84 @@
1
+ class SlimKeyfy::Slimutils::Merger
2
+ def self.merge_hashes(old_translations={}, new_translations={})
3
+ key = new_translations.keys.first
4
+ new_translations[key].keys.each do |top_key|
5
+ new_translations[key][top_key]
6
+ end
7
+ old_translations.merge(new_translations["translation_key"])
8
+ end
9
+
10
+ def self.merge_single_translation(translations, translation_key, translation)
11
+ k = translation_key
12
+ name = k.split(".").last
13
+ value = extract_value(k, translations)
14
+ if value != nil and value != translation then
15
+ name = enhance_key_on_collision(translations, name)
16
+ k = generate_dotted_key(k, name)
17
+ end
18
+ h = key_to_hash(k, translation)
19
+ translations = translations.deep_merge(h)
20
+ [translations, k, translation]
21
+ end
22
+
23
+ def self.enhance_key_on_collision(translations, translation_key_name)
24
+ num = 1
25
+ k = "#{translation_key_name}_#{num}"
26
+ while extract_value(k, translations) != nil do
27
+ k = "#{translation_key_name}_#{num}"
28
+ num += 1
29
+ end
30
+ k
31
+ end
32
+
33
+ def self.generate_dotted_key(old_dotted_key, new_name)
34
+ "#{old_dotted_key.split(".")[0..-2].join(".")}.#{new_name}"
35
+ end
36
+
37
+ def self.key_to_hash(dotted_key, translation)
38
+ {dotted_key => translation}.explode
39
+ end
40
+
41
+ def self.extract_value(dotted_key, translations, default=nil)
42
+ key, value = dotted_key.split(".", 2)
43
+ if key != nil and translations.has_key?(key) then
44
+ if value != nil then
45
+ extract_value(value, translations[key])
46
+ else
47
+ translations[key]
48
+ end
49
+ else
50
+ default
51
+ end
52
+ end
53
+ end
54
+
55
+ class Object
56
+ def recursive_send(*args)
57
+ args.inject(self) { |obj, m| obj.send(m.shift, *m) }
58
+ end
59
+ end
60
+
61
+ class Hash
62
+ def deep_merge(second)
63
+ merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
64
+ self.merge(second, &merger)
65
+ end
66
+
67
+ # https://gist.github.com/potatosalad/760726
68
+ # auto creates children
69
+ # from: http://rubyworks.github.com/facets/doc/api/core/Hash.html
70
+ def self.autonew(*args)
71
+ leet = lambda { |hsh, key| hsh[key] = new( &leet ) }
72
+ new(*args,&leet)
73
+ end
74
+
75
+ def explode(divider = '.')
76
+ h = Hash.autonew
77
+ for k,v in self.dup
78
+ tree = k.split(divider).map { |x| [ :[], x ] }
79
+ tree.push([ :[]=, tree.pop[1], v ])
80
+ h.recursive_send(*tree)
81
+ end
82
+ h
83
+ end
84
+ end
@@ -0,0 +1,70 @@
1
+ class SlimKeyfy::Slimutils::BaseKeyGenerator
2
+ def self.generate_key_base_from_path(file_path, file_extension)
3
+ key_name = case file_extension
4
+ when "slim" then
5
+ [subdir_name(file_path), filename(file_path)].join(".")
6
+ when "rb" then
7
+ sub = subdir_name(file_path, "controllers")
8
+ fname = filename(file_path)
9
+ if sub != nil and !sub.strip.empty? then
10
+ "#{sub}.#{fname}"
11
+ else
12
+ fname
13
+ end
14
+ else nil end
15
+ key_name
16
+ end
17
+ def self.filename(file_path)
18
+ return "" if file_path.nil?
19
+ if file_path.end_with?(".html.slim") then
20
+ fname = File.basename(file_path, ".html.slim")
21
+ elsif file_path.end_with?(".slim") then
22
+ fname = File.basename(file_path, ".slim")
23
+ elsif file_path.end_with?(".rb") then
24
+ fname = File.basename(file_path, ".rb")
25
+ else return "" end
26
+ fname = fname[1..-1] if fname.start_with?("_")
27
+ fname
28
+ end
29
+ def self.subdir_name(file_path, delim="views")
30
+ return "" if file_path.nil?
31
+ dirs = file_path.split("/").drop_while{|e| e != delim }
32
+ return "" if dirs.empty?
33
+ strip_dirs_and_file = dirs.pop(dirs.size-1)
34
+ strip_dirs_and_file[0..-2].join(".")
35
+ end
36
+ end
37
+
38
+ class SlimKeyfy::Slimutils::TranslationKeyGenerator
39
+ VALID = /[^0-9a-z]/i
40
+ DEFAULT_KEY_NAME = "default_key"
41
+
42
+ def initialize(translation)
43
+ @translation = translation
44
+ end
45
+
46
+ def generate_key_name
47
+ normalized_translation = ""
48
+ if not (@translation.nil? or @translation.empty?) then
49
+ normalized_translation = @translation.gsub(VALID, "_").gsub(/[_]+/, "_").downcase
50
+ normalized_translation = normalized_translation.split("_")[0..3].join("_")
51
+ end
52
+ return DEFAULT_KEY_NAME if is_not_valid?(normalized_translation.strip)
53
+ strip_underscores(normalized_translation)
54
+ end
55
+
56
+ def is_not_valid?(normalized_translation)
57
+ (normalized_translation.strip == "_" or normalized_translation.empty?)
58
+ end
59
+
60
+ def strip_underscores(s)
61
+ if s.start_with?("_") then
62
+ s = s[1..-1]
63
+ end
64
+ if s.end_with?("_") then
65
+ s = s[0..-2]
66
+ end
67
+ s
68
+ end
69
+ end
70
+
@@ -0,0 +1,56 @@
1
+ require 'yaml'
2
+
3
+ class SlimKeyfy::Slimutils::YamlProcessor
4
+
5
+ attr_reader :locale, :yaml_output, :yaml_hash
6
+
7
+ def initialize(locale, key_base, yaml_output=nil)
8
+ @locale = locale
9
+ @key_base = key_base
10
+ @yaml_output = process_output_file(yaml_output)
11
+ @yaml_hash = load_hash
12
+ end
13
+
14
+ def process_output_file(yaml_output)
15
+ if yaml_output.nil? then
16
+ dir_of_key = @key_base.split(".").first
17
+ yaml_output = default_yaml(dir_of_key, @locale)
18
+ end
19
+ path = File.expand_path(yaml_output.to_s)
20
+ if File.exist?(path) then
21
+ path
22
+ else
23
+ SlimKeyfy::Slimutils::FileWriter.write(path, "---")
24
+ path
25
+ end
26
+ end
27
+
28
+ def store!
29
+ merged = {@locale => @yaml_hash}
30
+ SlimKeyfy::Slimutils::FileWriter.write(@yaml_output, merged.to_yaml)
31
+ end
32
+
33
+ def load_hash
34
+ h = YAML::load_file(@yaml_output)
35
+ if h then h[@locale]
36
+ else {} end
37
+ end
38
+
39
+ def default_yaml(key, locale)
40
+ File.expand_path("./config/locales/#{key}.#{locale}.yml")
41
+ end
42
+
43
+ def merge!(translation_key, translation)
44
+ @yaml_hash, translation_key, translation = SlimKeyfy::Slimutils::Merger.merge_single_translation(@yaml_hash, translation_key, translation)
45
+ [translation_key, translation]
46
+ end
47
+
48
+ def delete_translations(translations)
49
+ return if translations.nil? or translations.empty? or @yaml_hash.empty?
50
+ translations.each do |k, v|
51
+ path = k.split('.')
52
+ leaf = path.pop
53
+ path.inject(@yaml_hash){|h, el| h[el]}.delete(leaf)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,8 @@
1
+ module SlimKeyfy::Slimutils
2
+
3
+ end
4
+
5
+ require 'slimkeyfy/slimutils/file_utils'
6
+ require 'slimkeyfy/slimutils/hash_merging'
7
+ require 'slimkeyfy/slimutils/key_generator'
8
+ require 'slimkeyfy/slimutils/yaml_processor'
@@ -0,0 +1,42 @@
1
+ class SlimKeyfy::Transformer::BaseTransformer
2
+ TRANSLATED = /t\s*\(?\s*(".*?"|'.*?')\s*\)?/
3
+ STRING = /(\".*\"|\'.*\')/
4
+ STRING_WITHOUT_QUOTES = /("(?<double_quot>.*)"|'(?<single_quot>.*)')/
5
+
6
+ def initialize(word, yaml_processor=nil)
7
+ @word = word
8
+ @yaml_processor = yaml_processor
9
+ end
10
+
11
+ def nil_elem
12
+ [nil, nil]
13
+ end
14
+
15
+ def should_not_be_processed?(tokens)
16
+ (tokens.nil? or tokens.size < 2)
17
+ end
18
+
19
+ def matches_string?(translation)
20
+ m = translation.match(STRING_WITHOUT_QUOTES)
21
+ return false if m.nil?
22
+ (m[:double_quot] != nil or m[:single_quot] != nil)
23
+ end
24
+
25
+ def match_string(translation)
26
+ m = translation.match(STRING_WITHOUT_QUOTES)
27
+ return translation if m.nil?
28
+ (m[:double_quot] != nil) ? m[:double_quot] : ((m[:single_quot] != nil) ? m[:single_quot] : translation)
29
+ end
30
+
31
+ def update_hashes(translation)
32
+ @word.update_translation_key_hash(@yaml_processor, translation)
33
+ end
34
+
35
+ def controller?
36
+ false
37
+ end
38
+
39
+ def slim?
40
+ false
41
+ end
42
+ end
@@ -0,0 +1,20 @@
1
+ class SlimKeyfy::Transformer::ControllerTransformer < SlimKeyfy::Transformer::BaseTransformer
2
+ TAGS = /(text|notice|message|alert|raise|subject|flash\[:[a-z]+\])/
3
+ CONNECTING_SYMBOLS = /\s*(:|=>?)?\s*/
4
+ REGEX = /(?<tag>#{TAGS}#{CONNECTING_SYMBOLS})(?<translation>#{STRING})/
5
+
6
+ def transform
7
+ m = @word.line.match(REGEX)
8
+ if m != nil then
9
+ translation = match_string(m[:translation])
10
+ translation_key = update_hashes(translation)
11
+ localized = @word.line.gsub(m[:translation], translation_key)
12
+ return [localized, @word.translations]
13
+ end
14
+ nil_elem
15
+ end
16
+
17
+ def controller?
18
+ true
19
+ end
20
+ end
@@ -0,0 +1,92 @@
1
+ class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTransformer
2
+
3
+ HTML_TAGS = /^(?<html_tag>'|\||([a-z\.]+[0-9\-]*)+)/
4
+ EQUALS = /(([a-z\.]+[0-9\-]*)*=.*)/
5
+
6
+ BEFORE = /(?<before>.*)/
7
+ TRANSLATION = /(?<translation>(".*?"|'.*?'))/
8
+ AFTER = /(?<after>,?.*)?/
9
+
10
+ HTML_ARGUMENTS = {
11
+ hint: /(?<html_tag>hint:\s*)/,
12
+ link_to: /(?<html_tag>link_to\s*\(?)/,
13
+ inconified: /(?<html_tag>(iconified\s*\(?))/,
14
+ placeholder: /(?<html_tag>placeholder:\s*)/,
15
+ title: /(?<html_tag>title:\s*)/,
16
+ label: /(?<html_tag>[a-z]*_?label:\s*)/,
17
+ optionals: /(?<html_tag>(default|include_blank|alt):\s*)/,
18
+ input: /(?<html_tag>[a-z]*\.?input:?\s*)/,
19
+ button: /(?<html_tag>[a-z]*\.?button:?\s*(\:[a-z]+\s*,\s*)?)/,
20
+ tag: /(?<html_tag>(submit|content)_tag[\:\(]?\s*)/,
21
+ data_naive: /(?<html_tag>data:\s*\{\s*(confirm|content):\s*)/
22
+ }
23
+
24
+ LINK_TO = /#{HTML_ARGUMENTS[:link_to]}#{TRANSLATION}/
25
+
26
+ def regex_list
27
+ HTML_ARGUMENTS.map{|_, regex| /#{BEFORE}#{regex}#{TRANSLATION}#{AFTER}/ }
28
+ end
29
+
30
+ def transform
31
+ return nil_elem if should_not_be_processed?(@word.as_list)
32
+ unindented_line = @word.unindented_line
33
+
34
+ result =
35
+ if unindented_line.match(EQUALS) then
36
+ parse_html_arguments(unindented_line)
37
+ elsif @word.head.match(HTML_TAGS) then
38
+ parse_html
39
+ else nil_elem end
40
+
41
+ return nil_elem if (result.last.nil? or result.last.empty?)
42
+
43
+ result
44
+ end
45
+
46
+ def parse_html
47
+ return nil_elem if @word.line.match(TRANSLATED)
48
+
49
+ tagged_with_equals = SlimKeyfy::Transformer::Whitespacer.convert_slim(@word.head)
50
+ body = @word.tail.join(" ")
51
+ body, tagged_with_equals = SlimKeyfy::Transformer::Whitespacer.convert_nbsp(body, tagged_with_equals)
52
+
53
+ if body.match(LINK_TO) != nil then
54
+ body = link_tos(body)
55
+ end
56
+
57
+ translation_key = update_hashes(body)
58
+ normalize_translation("#{tagged_with_equals} #{translation_key}")
59
+ end
60
+
61
+ def parse_html_arguments(line)
62
+ regex_list.each do |regex|
63
+ line.scan(regex) do |m_data|
64
+ before, html_tag = m_data[0], m_data[1]
65
+ translation, after = match_string(m_data[2]), m_data[3]
66
+ translation_key = update_hashes(translation)
67
+ line = "#{before}#{html_tag}#{translation_key}#{after}"
68
+ end
69
+ end
70
+ normalize_translation(line)
71
+ end
72
+
73
+ def link_tos(line)
74
+ m = line.match(LINK_TO)
75
+ if m != nil then
76
+ _, translation = m[:html_tag], match_string(m[:translation])
77
+ translation_key = update_hashes(translation)
78
+ line = line.gsub(m[:translation], translation_key)
79
+ link_tos(line)
80
+ else
81
+ line
82
+ end
83
+ end
84
+
85
+ def normalize_translation(translation)
86
+ ["#{@word.indentation}#{translation}", @word.translations]
87
+ end
88
+
89
+ def slim?
90
+ true
91
+ end
92
+ end
@@ -0,0 +1,48 @@
1
+ class SlimKeyfy::Transformer::Whitespacer
2
+
3
+ HTML = /([a-z\.]+[0-9\-]*)+/
4
+ HTML_TAGS = /^(?<html_tag>'|\||#{HTML})/
5
+
6
+ def self.convert_slim(s)
7
+ m = s.match(HTML_TAGS)
8
+
9
+ return s if m.nil? or m[:html_tag].nil?
10
+ return s if has_equals_tag?(s, m[:html_tag])
11
+ tag = m[:html_tag]
12
+
13
+ case tag
14
+ when /\|/ then
15
+ s.gsub("|", "=")
16
+ when /\'/ then
17
+ s.gsub("'", "=>")
18
+ when HTML then
19
+ s.gsub(s, "#{s}=")
20
+ else s end
21
+ end
22
+
23
+ def self.convert_nbsp(body, tag)
24
+ lead = leading_nbsp(body)
25
+ trail = trailing_nsbp(body, tag)
26
+
27
+ body = lead ? body.sub("&nbsp;", "") : body
28
+ body = trail ? body.reverse.sub(";psbn&", "").reverse : body
29
+
30
+ tag = tag.gsub(tag, "#{tag}#{lead}#{trail}")
31
+ [body.gsub("&nbsp;", " "), tag.gsub("=><", "=<>")]
32
+ end
33
+
34
+ def self.leading_nbsp(body)
35
+ return "<" if body.start_with?("&nbsp;")
36
+ ""
37
+ end
38
+
39
+ def self.trailing_nsbp(body, tag)
40
+ return "" if tag.start_with?("=>")
41
+ return ">" if body.end_with?("&nbsp;")
42
+ ""
43
+ end
44
+
45
+ def self.has_equals_tag?(s, html_tag)
46
+ s.gsub(html_tag, "").strip.start_with?("=")
47
+ end
48
+ end
@@ -0,0 +1,49 @@
1
+ class SlimKeyfy::Transformer::Word
2
+ attr_reader :line, :tokens, :indentation
3
+ attr_accessor :translations
4
+
5
+ def initialize(line, key_base, extension)
6
+ @line = line
7
+ @key_base = key_base
8
+ @extension = extension
9
+ @indentation = " " * (@line.size - unindented_line.size)
10
+ @translations = {}
11
+ end
12
+
13
+ def as_list(delim=" ")
14
+ @line.split(delim)
15
+ end
16
+
17
+ def unindented_line
18
+ @line.sub(/^\s*/, "")
19
+ end
20
+
21
+ def head
22
+ as_list.first
23
+ end
24
+
25
+ def tail
26
+ as_list.drop(1)
27
+ end
28
+
29
+ def i18nString(translation_key)
30
+ if @extension == "rb" then
31
+ "t('#{@key_base}.#{translation_key}')"
32
+ else
33
+ "t('.#{translation_key}')"
34
+ end
35
+ end
36
+
37
+ def update_translation_key_hash(yaml_processor, translation)
38
+ translation_key = SlimKeyfy::Slimutils::TranslationKeyGenerator.new(translation).generate_key_name
39
+ translation_key_with_base = "#{@key_base}.#{translation_key}"
40
+ translation_key_with_base, translation = yaml_processor.merge!(translation_key_with_base, translation) unless yaml_processor.nil?
41
+ @translations.merge!({translation_key_with_base => translation})
42
+ i18nString(extract_updated_key(translation_key_with_base))
43
+ end
44
+
45
+ def extract_updated_key(translation_key_with_base)
46
+ return "" if (translation_key_with_base.nil? or translation_key_with_base.empty?)
47
+ translation_key_with_base.split(".").last
48
+ end
49
+ end
@@ -0,0 +1,9 @@
1
+ module SlimKeyfy::Transformer
2
+
3
+ end
4
+
5
+ require 'slimkeyfy/transformer/word'
6
+ require 'slimkeyfy/transformer/whitespacer'
7
+ require 'slimkeyfy/transformer/base_transformer'
8
+ require 'slimkeyfy/transformer/slim_transformer'
9
+ require 'slimkeyfy/transformer/controller_transformer'
@@ -0,0 +1,3 @@
1
+ module SlimKeyfy
2
+ VERSION = "0.0.1"
3
+ end
data/lib/slimkeyfy.rb ADDED
@@ -0,0 +1,12 @@
1
+
2
+ module SlimKeyfy
3
+
4
+ def self.translate(args)
5
+ SlimKeyfy::Console::Commandline.new(args).run
6
+ end
7
+
8
+ end
9
+
10
+ require 'slimkeyfy/slimutils'
11
+ require 'slimkeyfy/console'
12
+ require 'slimkeyfy/transformer'
data/slimkeyfy.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib/', __FILE__)
2
+ $:.unshift lib unless $:.include?(lib)
3
+
4
+ require 'slimkeyfy/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "slimkeyfy"
8
+ s.version = SlimKeyfy::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.homepage = %q{https://phraseapp.com/}
11
+ s.authors = ["Dynport GmbH"]
12
+ s.summary = %q{Extract plain strings from slim templates to replace them with calls to I18n's t() method.}
13
+ s.description = %q{Replace plain text strings in your slim templates and Rails controllers with calls to I18n t() method. Keys and YAML output files will be automatically generated and filled in.}
14
+ s.email = ["info@phraseapp.com"]
15
+ git_files = `git ls-files | grep -v spec/`.split("\n") rescue ''
16
+ s.files = git_files
17
+ s.test_files = s.files.grep(%r{^(spec)/})
18
+ s.executables = ["slimkeyfy"]
19
+ s.require_paths = ["lib"]
20
+ s.add_development_dependency('rspec')
21
+ end
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ 'exec' "ruby" '-x' "$0" "$@"
3
+ #!/Users/matthias/.rvm/rubies/ruby-2.1.1/bin/ruby
4
+ #
5
+ # This file was generated by RubyGems.
6
+ #
7
+ # The application 'diff-lcs' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ version = ">= 0"
14
+
15
+ if ARGV.first
16
+ str = ARGV.first
17
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
18
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
19
+ version = $1
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ gem 'diff-lcs', version
25
+ load Gem.bin_path('diff-lcs', 'htmldiff', version)
@@ -0,0 +1,25 @@
1
+ #!/bin/sh
2
+ 'exec' "ruby" '-x' "$0" "$@"
3
+ #!/Users/matthias/.rvm/rubies/ruby-2.1.1/bin/ruby
4
+ #
5
+ # This file was generated by RubyGems.
6
+ #
7
+ # The application 'diff-lcs' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'rubygems'
12
+
13
+ version = ">= 0"
14
+
15
+ if ARGV.first
16
+ str = ARGV.first
17
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
18
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
19
+ version = $1
20
+ ARGV.shift
21
+ end
22
+ end
23
+
24
+ gem 'diff-lcs', version
25
+ load Gem.bin_path('diff-lcs', 'ldiff', version)
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'rspec-core' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+
11
+ version = ">= 0"
12
+
13
+ if ARGV.first
14
+ str = ARGV.first
15
+ str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
16
+ if str =~ /\A_(.*)_\z/ and Gem::Version.correct?($1) then
17
+ version = $1
18
+ ARGV.shift
19
+ end
20
+ end
21
+
22
+ gem 'rspec-core', version
23
+ load Gem.bin_path('rspec-core', 'rspec', version)
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+
3
+ # vim: syntax=ruby
File without changes
@@ -0,0 +1,2 @@
1
+ ---
2
+ exclude: !ruby/regexp /(tmp|swp)$|CVS|TAGS|\.(svn|git|hg|DS_Store|idea)|Gemfile\.lock|research\/|\.gemspec$/
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
@@ -0,0 +1,22 @@
1
+ ---
2
+ after_script:
3
+ - rake travis:after -t
4
+ before_script:
5
+ - gem install hoe-travis --no-rdoc --no-ri
6
+ - rake travis:before -t
7
+ language: ruby
8
+ notifications:
9
+ email: true
10
+ rvm:
11
+ - 2.0.0
12
+ - 1.9.3
13
+ - 1.9.2
14
+ - ruby-head
15
+ - 1.8.7
16
+ - jruby-19mode
17
+ - jruby-head
18
+ - jruby-18mode
19
+ - rbx-19mode
20
+ - rbx-18mode
21
+ - ree
22
+ script: rake travis