slimkeyfy 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ee5c9bad4a4451f742d2dd6cc4b58200fccc293
4
- data.tar.gz: fb7116389730093d186eed6e347653d73651191a
3
+ metadata.gz: d7b087050604856e414040ee52a0f0f6193d6262
4
+ data.tar.gz: fda6549ae39e62bc4a14d90a87aa416e8a62cf8a
5
5
  SHA512:
6
- metadata.gz: ec2d6e0334284b0b23dbdbde0b7e6642ed9bfb2356cfa25171b3b2fcde8b61294b6fce9c4cc809c22014291b74e2436062641086e6d28bd58dc30f9baa76ed1c
7
- data.tar.gz: ccb8f003cfd001ece01588eb6186aebd3902ff93a159f4c667b952a5c03baabc9e6dae4e05647fa3cb7c5e69ec94afa25e314165a656b58b1e004261482cf686
6
+ metadata.gz: 1789730769336204cfd93fefaa65bd6e01c4e086d6114b79468c73f71e2582288d7baea132ae2219569782f82a428470b56b8f30efbfedd7dc144003ab41000a
7
+ data.tar.gz: b115559e8670e99b43c50805b935d162d698b820a187751880bdba8c7a2fcc63f44c8f849fdf3c43facf9d0dba436075a90977b389ba386936669b0744adb2c6
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
1
  Slimkeyfy
2
2
  =
3
3
  Extract plain Strings from .slim views and Rails controllers to replace them with I18n's t() method. Keys with it's translations will be streamed to a YAML file.
4
+
5
+ Read more in this blog post: [PhraseApp Blog: Make your Rails App localizable with Slimkeyfy](http://blog.phraseapp.com/post/96450272307/make-your-rails-app-localizable-with-slimkeyfy)
6
+
4
7
  ```ruby
5
8
  slimkeyfy app/views/users/show.html.slim en
6
9
  # users/show.html.slim
7
10
  h1 Hello World!
8
11
  # converts to
9
- h1= t('.hello_world')
12
+ h1= t('.hello_world')
10
13
  # config/locales/users.en.yaml
11
- # en:
14
+ # en:
12
15
  # user:
13
16
  # show:
14
17
  # hello_world: Hello World!
@@ -79,7 +82,7 @@ your_app_name/
79
82
 
80
83
  > pwd
81
84
  ../your_app_name/
82
-
85
+
83
86
  > slimkeyfy app/views/users/ en
84
87
  ... choose your changes here (y/n/x/a)
85
88
 
@@ -88,22 +91,22 @@ your_app_name/
88
91
  show.html.slim
89
92
  new.html.slim.bak
90
93
  show.html.slim.bak
91
-
94
+
92
95
  > ls config/locales/
93
96
  user.en.yml
94
97
  en.yml
95
-
98
+
96
99
  > cat ../users/new.html.slim.bak
97
100
  h1 Hello World!
98
-
101
+
99
102
  > cat ../users/new.html.slim
100
103
  h1= t('.hello_world')
101
-
104
+
102
105
  > cat config/locales/en.yml
103
106
  --
104
107
  en:
105
108
  keys..
106
-
109
+
107
110
  > cat config/locales/users.en.yml
108
111
  ---
109
112
  en:
@@ -117,13 +120,13 @@ Suggested Workflow
117
120
  -
118
121
  As HTML is not 100% parsable there will be errors in the conversion. To minimize your error rate we suggest to approach each view or view_folder individually. The i18n-tasks gem helped a lot by finding errors. Always double check your views and make sure that everything went smoothly. Especially double check all your links. Here is an example workflow:
119
122
  ```ruby
120
- # 1. create a branch for a view folder
123
+ # 1. create a branch for a view folder
121
124
  > git checkout -b users_localization
122
125
 
123
126
  # 2. slimkeyfy the view folder you would like to tag
124
127
  > slimkeyfy app/views/users/ en
125
128
 
126
- # 3. go through all files and verify/add missing translations
129
+ # 3. go through all files and verify/add missing translations
127
130
  # (check against the .bak files (use git diff))
128
131
  > git diff app/views/users/views.html.slim
129
132
 
@@ -52,9 +52,9 @@ class SlimKeyfy::Console::Commandline
52
52
 
53
53
  wrong_usage if (input.nil? or locale.nil?)
54
54
 
55
- if File.directory?(input) then
55
+ if File.directory?(input)
56
56
  directory_translate(input)
57
- elsif File.file?(input) then
57
+ elsif File.file?(input)
58
58
  translate
59
59
  else
60
60
  raise "Please provide a file or directory!"
@@ -65,7 +65,7 @@ class SlimKeyfy::Console::Commandline
65
65
  def directory_translate(input)
66
66
  rec = @options.fetch(:recursive, false)
67
67
  SlimKeyfy::Slimutils::MFileUtils.walk(input, rec).each do |rec_input|
68
- if File.file?(rec_input) and SlimKeyfy::Slimutils::MFileUtils.is_valid_extension?(rec_input) then
68
+ if File.file?(rec_input) and SlimKeyfy::Slimutils::MFileUtils.is_valid_extension?(rec_input)
69
69
  @options[:input] = rec_input
70
70
  translate
71
71
  end
@@ -73,7 +73,7 @@ class SlimKeyfy::Console::Commandline
73
73
  end
74
74
 
75
75
  def translate
76
- unless SlimKeyfy::Slimutils::MFileUtils.is_valid_extension?(@options[:input]) then
76
+ unless SlimKeyfy::Slimutils::MFileUtils.is_valid_extension?(@options[:input])
77
77
  puts "invalid extension!"
78
78
  return
79
79
  end
@@ -2,9 +2,9 @@ class SlimKeyfy::Console::IOAction
2
2
  def self.yes_or_no?(msg)
3
3
  puts "#{msg} (y|n)"
4
4
  arg = STDIN.gets.chomp
5
- if arg =~ /[yY](es)?/ then
5
+ if arg =~ /[yY](es)?/
6
6
  true
7
- elsif arg =~ /[nN]o?/ then
7
+ elsif arg =~ /[nN]o?/
8
8
  false
9
9
  else
10
10
  puts "Provide either (y)es or (n)o!"
@@ -14,13 +14,13 @@ class SlimKeyfy::Console::IOAction
14
14
  def self.choose(msg)
15
15
  puts "#{msg} (y|n) (x for tagging | (a)bort)"
16
16
  arg = STDIN.gets.chomp
17
- if arg =~ /[yY](es)?/ then
17
+ if arg =~ /[yY](es)?/
18
18
  "y"
19
- elsif arg =~ /[nN]o?/ then
19
+ elsif arg =~ /[nN]o?/
20
20
  "n"
21
- elsif arg =~ /x/ then
21
+ elsif arg =~ /x/
22
22
  "x"
23
- elsif arg =~ /a/ then
23
+ elsif arg =~ /a/
24
24
  "a"
25
25
  else
26
26
  puts "Either (y)es, (n)o, (x) for tagging or (a) to abort"
@@ -7,12 +7,12 @@ class SlimKeyfy::Console::Printer
7
7
  def self.unix_diff(bak_path, file_path)
8
8
  result = "Please install colordiff or diff (brew install colordiff)"
9
9
  colordiff, diff = `which colordiff`, `which diff`
10
- if not colordiff.empty? then
10
+ if not colordiff.empty?
11
11
  result = `colordiff #{bak_path} #{file_path}`
12
- elsif not diff.empty? then
12
+ elsif not diff.empty?
13
13
  result =`diff #{bak_path} #{file_path}`
14
14
  end
15
- if result.nil? or result.strip.empty? then
15
+ if result.nil? or result.strip.empty?
16
16
  puts "No changes for comparison found!"
17
17
  else
18
18
  puts "#{result}"
@@ -17,9 +17,9 @@ class SlimKeyfy::Console::Translate
17
17
  end
18
18
 
19
19
  def transformer
20
- if @extension == "slim" then
20
+ if @extension == "slim"
21
21
  SlimKeyfy::Transformer::SlimTransformer
22
- elsif @extension == "rb" then
22
+ elsif @extension == "rb"
23
23
  SlimKeyfy::Transformer::ControllerTransformer
24
24
  else
25
25
  puts "Unknown extension type!"
@@ -69,11 +69,11 @@ class SlimKeyfy::Console::Translate
69
69
  end
70
70
 
71
71
  def finalize!
72
- if @changes then
73
- if SlimKeyfy::Console::IOAction.yes_or_no?("Do you like to review your changes?") then
72
+ if @changes
73
+ if SlimKeyfy::Console::IOAction.yes_or_no?("Do you like to review your changes?")
74
74
  SlimKeyfy::Console::Printer.unix_diff(@bak_path, @original_file_path)
75
75
  end
76
- if SlimKeyfy::Console::IOAction.yes_or_no?("Do you like to save your changes?") then
76
+ if SlimKeyfy::Console::IOAction.yes_or_no?("Do you like to save your changes?")
77
77
  @yaml_processor.store!
78
78
  puts "Saved! at #{@original_file_path}"
79
79
  SlimKeyfy::Slimutils::MFileUtils.rm(@bak_path) if @no_backup
@@ -39,9 +39,8 @@ class SlimKeyfy::Slimutils::MFileUtils
39
39
  file_path.split(".").last
40
40
  end
41
41
  def self.is_valid_extension?(file_path)
42
- ext = self.file_extension(file_path)
43
- return false if (ext.nil? or ext.empty?)
44
- (ext.end_with?("slim") or ext.end_with?("rb"))
42
+ return false if (file_path.nil? or file_path.empty?)
43
+ (file_path.end_with?(".slim") or file_path.end_with?(".rb"))
45
44
  end
46
45
  end
47
46
 
@@ -12,12 +12,12 @@ class SlimKeyfy::Slimutils::YamlProcessor
12
12
  end
13
13
 
14
14
  def process_output_file(yaml_output)
15
- if yaml_output.nil? then
15
+ if yaml_output.nil?
16
16
  dir_of_key = @key_base.split(".").first
17
17
  yaml_output = default_yaml(dir_of_key, @locale)
18
18
  end
19
19
  path = File.expand_path(yaml_output.to_s)
20
- if File.exist?(path) then
20
+ if File.exist?(path)
21
21
  path
22
22
  else
23
23
  SlimKeyfy::Slimutils::FileWriter.write(path, "---")
@@ -32,8 +32,11 @@ class SlimKeyfy::Slimutils::YamlProcessor
32
32
 
33
33
  def load_hash
34
34
  h = YAML::load_file(@yaml_output)
35
- if h then h[@locale]
36
- else {} end
35
+ if h
36
+ h[@locale]
37
+ else
38
+ {}
39
+ end
37
40
  end
38
41
 
39
42
  def default_yaml(key, locale)
@@ -1,7 +1,7 @@
1
1
  class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTransformer
2
2
 
3
3
  HTML_TAGS = /^(?<html_tag>'|\||([a-z\.]+[0-9\-]*)+)/
4
- EQUALS = /(([a-z\.]+[0-9\-]*)*=.*)/
4
+ EQUALS = /#?([a-z0-9\.\-\s]+)?\=.*/
5
5
 
6
6
  BEFORE = /(?<before>.*)/
7
7
  TRANSLATION = /(?<translation>(".*?"|'.*?'))/
@@ -32,9 +32,9 @@ class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTran
32
32
  unindented_line = @word.unindented_line
33
33
 
34
34
  result =
35
- if unindented_line.match(EQUALS) then
35
+ if unindented_line.match(EQUALS)
36
36
  parse_html_arguments(unindented_line)
37
- elsif @word.head.match(HTML_TAGS) then
37
+ elsif @word.head.match(HTML_TAGS)
38
38
  parse_html
39
39
  else nil_elem end
40
40
 
@@ -50,7 +50,7 @@ class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTran
50
50
  body = @word.tail.join(" ")
51
51
  body, tagged_with_equals = SlimKeyfy::Transformer::Whitespacer.convert_nbsp(body, tagged_with_equals)
52
52
 
53
- if body.match(LINK_TO) != nil then
53
+ if body.match(LINK_TO) != nil
54
54
  body = link_tos(body)
55
55
  end
56
56
 
@@ -72,7 +72,7 @@ class SlimKeyfy::Transformer::SlimTransformer < SlimKeyfy::Transformer::BaseTran
72
72
 
73
73
  def link_tos(line)
74
74
  m = line.match(LINK_TO)
75
- if m != nil then
75
+ if m != nil
76
76
  _, translation = m[:html_tag], match_string(m[:translation])
77
77
  translation_key = update_hashes(translation)
78
78
  line = line.gsub(m[:translation], translation_key)
@@ -27,7 +27,7 @@ class SlimKeyfy::Transformer::Word
27
27
  end
28
28
 
29
29
  def i18nString(translation_key)
30
- if @extension == "rb" then
30
+ if @extension == "rb"
31
31
  "t('#{@key_base}.#{translation_key}')"
32
32
  else
33
33
  "t('.#{translation_key}')"
@@ -1,3 +1,3 @@
1
1
  module SlimKeyfy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimkeyfy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dynport GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  version: '0'
146
146
  requirements: []
147
147
  rubyforge_project:
148
- rubygems_version: 2.4.1
148
+ rubygems_version: 2.2.2
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Extract plain strings from slim templates to replace them with calls to I18n's