zendesk_apps_tools 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
data/features/new.feature CHANGED
@@ -6,6 +6,7 @@ Feature: create a template for a new zendesk app
6
6
  | author name | John Citizen |
7
7
  | author email | john@example.com |
8
8
  | app name | John Test App |
9
+ | app dir | tmp/aruba |
9
10
 
10
11
  Then the app file "tmp/aruba/manifest.json" is created with:
11
12
  """
@@ -11,16 +11,16 @@ Given /^an app is created in directory "(.*?)"$/ do |app_dir|
11
11
  | author name | John Citizen |
12
12
  | author email | john@example.com |
13
13
  | app name | John Test App |
14
+ | app dir | #{app_dir} |
14
15
  }
15
16
  end
16
17
 
17
18
  When /^I run "(.*?)" command with the following details:$/ do |cmd, table|
18
19
  IO.popen(cmd, "w+") do |pipe|
19
- key = table.rows_hash
20
- pipe.puts key["author name"]
21
- pipe.puts key["author email"]
22
- pipe.puts key["app name"]
23
- pipe.puts @app_dir
20
+ # [ ['parameter name', 'value'] ]
21
+ table.raw.each do |row|
22
+ pipe.puts row.last
23
+ end
24
24
  pipe.close_write
25
25
  @output = pipe.readlines
26
26
  @output.each {|line| puts line}
@@ -0,0 +1,34 @@
1
+ Feature: Translate app strings
2
+ As a Zendesk admin
3
+ To enable many languages
4
+ I want to be able to map between json and yaml
5
+
6
+ Scenario: Attempt to generate invalid package name
7
+ Given an app is created in directory "tmp/aruba"
8
+ When I run "cd tmp/aruba && zat translate create" command with the following details:
9
+ | package name | This is wrong |
10
+ Then the command output should contain "Invalid package name, try again:"
11
+
12
+ Scenario: Generate template yaml from en.json
13
+ Given an app is created in directory "tmp/aruba"
14
+ When I run "cd tmp/aruba && zat translate create" command with the following details:
15
+ | package name | test_package |
16
+ Then the app file "tmp/aruba/translations/en.yml" is created with:
17
+ """
18
+ title: "John Test App"
19
+ packages:
20
+ - default
21
+ - app_test_package
22
+
23
+ parts:
24
+ - translation:
25
+ key: "txt.apps.test_package.app.description"
26
+ title: ""
27
+ value: "Play the famous zen tunes in your help desk."
28
+ - translation:
29
+ key: "txt.apps.test_package.app.name"
30
+ title: ""
31
+ value: "Buddha Machine"
32
+
33
+ """
34
+
@@ -1,4 +1,5 @@
1
1
  module ZendeskAppsTools
2
2
  autoload :Command, 'zendesk_apps_tools/command'
3
+ autoload :Translate, 'zendesk_apps_tools/translate'
3
4
  end
4
5
 
@@ -16,6 +16,9 @@ module ZendeskAppsTools
16
16
 
17
17
  source_root File.expand_path(File.join(File.dirname(__FILE__), "../.."))
18
18
 
19
+ desc 'translate SUBCOMMAND', 'Manage translation files', :hide => true
20
+ subcommand 'translate', Translate
21
+
19
22
  desc "new", "Generate a new app"
20
23
  def new
21
24
  puts "Enter this app author's name:"
@@ -39,7 +42,7 @@ module ZendeskAppsTools
39
42
  end
40
43
  end
41
44
 
42
- directory('template', @app_dir)
45
+ directory('app_template', @app_dir)
43
46
  end
44
47
 
45
48
  desc "validate", "Validate your app"
@@ -0,0 +1,76 @@
1
+ require 'thor'
2
+
3
+ module ZendeskAppsTools
4
+ class Translate < Thor
5
+ include Thor::Shell
6
+ include Thor::Actions
7
+
8
+ desc 'create', 'Create Zendesk translation file from en.json'
9
+ def create
10
+ manifest = JSON.parse(File.open('manifest.json').read)
11
+ app_name = manifest['name']
12
+
13
+ unless app_name
14
+ app_name = get_value_from_stdin('What is the name of this app?', /^\w.*$/, "Invalid name, try again:")
15
+ end
16
+
17
+ package = get_value_from_stdin('What is the package name for this app?', /^[a-z_]+$/, "Invalid package name, try again:")
18
+
19
+ write_yaml(app_name, package)
20
+ end
21
+
22
+ def self.source_root
23
+ File.expand_path(File.join(File.dirname(__FILE__), "../.."))
24
+ end
25
+
26
+ no_commands do
27
+
28
+ def get_value_from_stdin(prompt, valid_regex, error_msg)
29
+ while input = ask(prompt)
30
+ unless input =~ valid_regex
31
+ say(error_msg, :red)
32
+ else
33
+ break
34
+ end
35
+ end
36
+
37
+ return input
38
+ end
39
+
40
+ def write_yaml(app_name, package)
41
+ user_translations = JSON.parse(File.open('translations/en.json').read)
42
+ @translations = user_translations.keys.inject({}) do |translations, key|
43
+ translations.merge( get_translations_for(user_translations, key) )
44
+ end
45
+
46
+ @app_name = app_name
47
+ @package_name = package
48
+ template(File.join(Translate.source_root, 'templates/translation.erb.tt'), "translations/en.yml")
49
+ end
50
+
51
+ def get_translations_for(scope, scope_key, keys = [], translations = {})
52
+ hash_or_value = scope[scope_key]
53
+
54
+ if hash_or_value.is_a?(Hash)
55
+ keys << scope_key
56
+ hash_or_value.each_key do |key|
57
+
58
+ if hash_or_value[key].is_a?(Hash)
59
+ get_translations_for(hash_or_value, key, keys, translations)
60
+ keys = keys[0...-1]
61
+ else
62
+ translation_key = (keys + [key]).join('.')
63
+ translations[translation_key] = hash_or_value[key]
64
+ end
65
+
66
+ end
67
+ else
68
+ translations[scope_key] = hash_or_value
69
+ end
70
+
71
+ translations
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,12 @@
1
+ title: "<%= @app_name %>"
2
+ packages:
3
+ - default
4
+ - app_<%= @package_name %>
5
+
6
+ parts:
7
+ <% @translations.each do |key, value| -%>
8
+ - translation:
9
+ key: "txt.apps.<%= @package_name %>.<%= key %>"
10
+ title: ""
11
+ value: "<%= value %>"
12
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_apps_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-05-16 00:00:00.000000000 Z
15
+ date: 2013-06-14 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: thor
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 0.15.2
24
+ version: 0.18.0
25
25
  type: :runtime
26
26
  prerelease: false
27
27
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 0.15.2
32
+ version: 0.18.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rubyzip
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -110,6 +110,22 @@ dependencies:
110
110
  - - ! '>='
111
111
  - !ruby/object:Gem::Version
112
112
  version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec
115
+ requirement: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
113
129
  description: Tools to help you develop Zendesk Apps.
114
130
  email:
115
131
  - dev@zendesk.com
@@ -121,14 +137,17 @@ files:
121
137
  - bin/zat
122
138
  - lib/zendesk_apps_tools/command.rb
123
139
  - lib/zendesk_apps_tools/server.rb
140
+ - lib/zendesk_apps_tools/translate.rb
124
141
  - lib/zendesk_apps_tools.rb
125
- - template/app.css
126
- - template/app.js
127
- - template/assets/logo-small.png
128
- - template/assets/logo.png
129
- - template/manifest.json.tt
130
- - template/templates/layout.hdbs
131
- - template/translations/en.json
142
+ - app_template/app.css
143
+ - app_template/app.js
144
+ - app_template/assets/logo-small.png
145
+ - app_template/assets/logo.png
146
+ - app_template/assets/promotion-image.png
147
+ - app_template/manifest.json.tt
148
+ - app_template/templates/layout.hdbs
149
+ - app_template/translations/en.json
150
+ - templates/translation.erb.tt
132
151
  - README.md
133
152
  - LICENSE
134
153
  - features/clean.feature
@@ -136,6 +155,7 @@ files:
136
155
  - features/package.feature
137
156
  - features/step_definitions/app_steps.rb
138
157
  - features/support/env.rb
158
+ - features/translate.feature
139
159
  - features/validate.feature
140
160
  homepage: http://github.com/zendesk/zendesk_apps_tools
141
161
  licenses:
@@ -158,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
178
  version: 1.3.6
159
179
  requirements: []
160
180
  rubyforge_project:
161
- rubygems_version: 1.8.25
181
+ rubygems_version: 1.8.24
162
182
  signing_key:
163
183
  specification_version: 3
164
184
  summary: Tools to help you develop Zendesk Apps.
@@ -168,4 +188,5 @@ test_files:
168
188
  - features/package.feature
169
189
  - features/step_definitions/app_steps.rb
170
190
  - features/support/env.rb
191
+ - features/translate.feature
171
192
  - features/validate.feature