konjac 0.2.6.8 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,116 @@
1
+ #!/usr/bin/osascript
2
+ -- round up ASCII characters used for formatting in Word
3
+ global bell
4
+ global line_feed
5
+ global form_feed
6
+ global carriage_return
7
+ global format_chars
8
+
9
+ -- strip line breaks and formatting characters
10
+ to strip_line_breaks(this_line)
11
+ try
12
+ -- remove last character until no it's no longer an excluded character
13
+ repeat while last character of this_line is in format_chars
14
+ set this_line to characters 1 thru -2 of this_line as string
15
+ end repeat
16
+ return this_line as text
17
+ on error
18
+ return ""
19
+ end try
20
+ end strip_line_breaks
21
+
22
+ to get_posix_path(mac_path)
23
+ set result to POSIX path of mac_path
24
+ end get_posix_path
25
+
26
+ to extract(filename)
27
+ tell application "Microsoft PowerPoint"
28
+ activate
29
+ open filename
30
+ set active_presentation to active presentation
31
+ set ignored_content to {missing value, "", line_feed}
32
+
33
+ -- set tags path to full path to active presentation with a .tags extension
34
+ set presentation_path to (path of active_presentation) & ":" & ¬
35
+ (name of active_presentation)
36
+ set tags_path to presentation_path & ".diff"
37
+
38
+ -- delete tags file if it already exists
39
+ tell application "Finder"
40
+ if exists file tags_path then
41
+ delete file tags_path
42
+ end if
43
+ end tell
44
+
45
+ -- open tags file for writing
46
+ set tags_file to open for access file tags_path with write permission
47
+ set eof of tags_file to 0
48
+
49
+ write ("--- " & my get_posix_path(presentation_path)) to tags_file
50
+ write line_feed to tags_file
51
+ write ("+++ " & my get_posix_path(presentation_path)) to tags_file
52
+ write line_feed to tags_file
53
+
54
+ -- iterate through slides
55
+ set slide_index to 1
56
+ set slide_count to count of slides in active_presentation
57
+
58
+ repeat while slide_index is less than or equal to slide_count
59
+ set current_slide to slide slide_index in active_presentation
60
+
61
+ -- iterate through shapes
62
+ set shape_index to 1
63
+ set shape_count to count of shapes in current_slide
64
+
65
+ repeat while shape_index is less than or equal to shape_count
66
+ -- set current shape
67
+ set current_shape to shape shape_index of current_slide
68
+
69
+ -- get text content if it's available
70
+ set text_content to my strip_line_breaks(content of text range of text frame of current_shape) as string
71
+
72
+ -- replace "soft returns" (vertical tabs) with real returns
73
+ set old_delimiters to AppleScript's text item delimiters
74
+ set AppleScript's text item delimiters to carriage_return
75
+ set split_content to every text item of text_content
76
+ set AppleScript's text item delimiters to old_delimiters
77
+
78
+ if text_content is not in ignored_content then
79
+ write ("@@ " & slide_index & "," & shape_index & " @@") to tags_file
80
+ write line_feed to tags_file
81
+ repeat with text_line in split_content
82
+ write ("-" & text_line) to tags_file as «class utf8»
83
+ write line_feed to tags_file
84
+ end repeat
85
+ repeat with text_line in split_content
86
+ write ("+" & text_line) to tags_file as «class utf8»
87
+ write line_feed to tags_file
88
+ end repeat
89
+ end if
90
+
91
+ set shape_index to (shape_index + 1)
92
+ end repeat
93
+
94
+ -- increment slide index
95
+ set slide_index to (slide_index + 1)
96
+ end repeat
97
+
98
+ -- close everything
99
+ close access tags_file
100
+ end tell
101
+ end extract
102
+
103
+ -- initialize global variables, just formatting characters here
104
+ to init_globals()
105
+ set bell to ASCII character 7
106
+ set line_feed to ASCII character 10
107
+ set form_feed to ASCII character 12
108
+ set carriage_return to ASCII character 13
109
+ set format_chars to {bell, line_feed, form_feed, carriage_return}
110
+ end init_globals
111
+
112
+ -- main()
113
+ on run argv
114
+ init_globals()
115
+ extract(item 1 of argv)
116
+ end
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/osascript
2
+ global numbers_as_text
3
+ global line_feed
4
+ global vertical_tab
5
+ global carriage_return
6
+
7
+ -- parses the headers/separators inside the tags file
8
+ to parse_header(header, begin)
9
+ set at_offset to begin
10
+
11
+ repeat while character at_offset of header is in my numbers_as_text
12
+ set at_offset to (at_offset + 1)
13
+ end repeat
14
+
15
+ return at_offset
16
+ end parse_header
17
+
18
+ to get_posix_path(mac_path)
19
+ set result to POSIX path of mac_path
20
+ end get_posix_path
21
+
22
+ to import(filename)
23
+ tell application "Microsoft PowerPoint"
24
+ activate
25
+ open filename
26
+ set active_presentation to active presentation
27
+ set ignored_content to {missing value, "", line_feed}
28
+
29
+ -- set tags path to full path to active presentation with a .tags extension
30
+ set presentation_path to (path of active_presentation) & ":" & ¬
31
+ (name of active_presentation)
32
+ set tags_path to presentation_path & ".diff"
33
+
34
+ -- read in tags
35
+ set tags_file to open for access file tags_path
36
+ set tags to (read tags_file for (get eof tags_file) ¬
37
+ as «class utf8» using delimiter line_feed)
38
+ set tag_index to 0
39
+ set tag_length to length of tags
40
+ close access tags_file
41
+
42
+ set text_content to ""
43
+
44
+ -- iterate through slides
45
+ set slide_index to 0
46
+ set prev_slide_index to 0
47
+ set shape_index to 0
48
+ set prev_shape_index to 0
49
+ set is_new_tag to false
50
+
51
+ repeat with current_line in tags
52
+ if current_line starts with "@@ " then
53
+ set comma_offset to my parse_header(current_line, 4)
54
+ set slide_index to text 4 thru (comma_offset - 1) ¬
55
+ of current_line as number
56
+ set space_offset to my parse_header(current_line, comma_offset + 1)
57
+ set shape_index to text (comma_offset + 1) thru (space_offset - 1) ¬
58
+ of current_line as number
59
+ set is_new_tag to true
60
+ else if current_line starts with "+" then
61
+ if slide_index is not 0 then
62
+ set prev_slide_index to slide_index
63
+ set prev_shape_index to shape_index
64
+
65
+ -- handle blank lines with soft returns
66
+ if length of current_line is less than 2
67
+ set this_content to ""
68
+ else
69
+ set this_content to text 2 thru (length of current_line) ¬
70
+ of current_line
71
+ end if
72
+
73
+ -- add to text content, joining with a soft return for multiple lines
74
+ if text_content is "" then
75
+ set text_content to this_content
76
+ else
77
+ set text_content to (text_content & carriage_return & this_content)
78
+ end if
79
+ set is_new_tag to false
80
+ end if
81
+ end if
82
+
83
+ -- increment tag index
84
+ set tag_index to tag_index + 1
85
+
86
+ -- write if we've moved to a new tag or reached the end of the file
87
+ if text_content is not "" and (tag_index is tag_length or is_new_tag)
88
+ set content of text range of text frame of shape prev_shape_index ¬
89
+ of slide prev_slide_index ¬
90
+ of active presentation to text_content
91
+ set text_content to ""
92
+ end if
93
+ end repeat
94
+ end tell
95
+ end import
96
+
97
+ -- initialize global variables
98
+ to init_globals()
99
+ set numbers_as_text to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
100
+ set line_feed to ASCII character 10
101
+ set vertical_tab to ASCII character 11
102
+ set carriage_return to ASCII character 13
103
+ end init_globals
104
+
105
+ -- main()
106
+ on run argv
107
+ init_globals()
108
+ import(item 1 of argv)
109
+ end run
data/lib/konjac/cli.rb CHANGED
@@ -12,8 +12,8 @@ module Konjac
12
12
 
13
13
  class << self
14
14
  # A list of valid subcommands
15
- SUB_COMMANDS = ["add", "edit", "export", "import", "language", "list",
16
- "suggest", "translate", "use"]
15
+ SUB_COMMANDS = ["add", "export", "import", "language", "list", "suggest",
16
+ "translate", "use"]
17
17
 
18
18
  # The minimum amount by which to offset subcommands in standard display.
19
19
  # Should be equal to the length of the longest top-level flag (e.g. the
@@ -68,13 +68,6 @@ eos
68
68
  opt :help, I18n.t(:help, :scope => :opts)
69
69
  end
70
70
  Dictionary.add_word opts
71
- when "edit"
72
- Trollop::options do
73
- banner sc_banner % I18n.t(:filenames_arg)
74
- opt :editor, I18n.t(:editor, :scope => :opts), :type => :string
75
- opt :help, I18n.t(:help, :scope => :opts)
76
- end
77
- Word.edit_docx_tags ARGV, opts
78
71
  when "export"
79
72
  opts = Trollop::options do
80
73
  banner sc_banner % I18n.t(:filenames_arg)
@@ -87,14 +80,14 @@ eos
87
80
  :default => Config.dictionary, :multi => true
88
81
  opt :help, I18n.t(:help, :scope => :opts)
89
82
  end
90
- Word.export_tags ARGV, opts
83
+ Office.export_tags ARGV, opts
91
84
  when "import"
92
85
  opts = Trollop::options do
93
86
  banner sc_banner % I18n.t(:filenames_arg)
94
87
  opt :output, I18n.t(:output, :scope => :opts), :type => :string
95
88
  opt :help, I18n.t(:help, :scope => :opts)
96
89
  end
97
- Word.import_tags ARGV, opts
90
+ Office.import_tags ARGV, opts
98
91
  when "language"
99
92
  Trollop::options do
100
93
  banner sc_banner % I18n.t(:word_arg)
@@ -200,7 +200,7 @@ module Konjac
200
200
  result << term
201
201
 
202
202
  # Either last letter is a word character or it's not escaped
203
- result << "\\b" if term[0..1] =~ /\w$|[^\\].$/
203
+ result << "\\b" if term[-2..-1] =~ /(\w|[^\\].)$/
204
204
  result
205
205
  end
206
206
 
@@ -1,10 +1,9 @@
1
1
  module Konjac
2
- # A singleton for dealing with extracting and importing tags from {Microsoft
3
- # Word}[http://office.microsoft.com/en-us/word/] 2003+ documents
4
- module Word
2
+ # A singleton for dealing with extracting and importing tags from Microsoft
3
+ # Office documents
4
+ module Office
5
5
  class << self
6
- # Imports the text content of a tag file into a {Microsoft
7
- # Word}[http://office.microsoft.com/en-us/word/] 2003+ document
6
+ # Imports the text content of a tag file into a Microsoft Office
8
7
  def import_tags(files, opts = {})
9
8
  sub_files = Utils.parse_files(files)
10
9
  return if sub_files.empty?
@@ -12,6 +11,8 @@ module Konjac
12
11
  case File.extname(sub_file)
13
12
  when ".doc"
14
13
  system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_import"), sub_file
14
+ when ".ppt"
15
+ system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_powerpoint_import"), sub_file
15
16
  when ".docx"
16
17
  # Build the list of paths we need to work with
17
18
  dirname = File.dirname(sub_file)
@@ -55,8 +56,7 @@ module Konjac
55
56
  end
56
57
  end
57
58
 
58
- # Exports the text content of {Microsoft
59
- # Word}[http://office.microsoft.com/en-us/word/] documents
59
+ # Exports the text content of Microsoft Office document
60
60
  def export_tags(files, opts = {})
61
61
  # Determine whether to attempt translating
62
62
  if opts[:from_given] && opts[:to_given]
@@ -76,6 +76,10 @@ module Konjac
76
76
  break unless Utils.user_allows_overwrite?(sub_file + ".diff")
77
77
 
78
78
  system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_word_export"), sub_file
79
+ when ".ppt"
80
+ break unless Utils.user_allows_overwrite?(sub_file + ".diff")
81
+
82
+ system File.join(File.dirname(__FILE__), "..", "applescripts", "konjac_powerpoint_export"), sub_file
79
83
  when ".docx"
80
84
  # Build a list of all the paths we're working with
81
85
  dirname = File.dirname(sub_file)
@@ -138,14 +142,6 @@ module Konjac
138
142
  end
139
143
  end
140
144
 
141
- # Opens the .konjac tag files for the specified .docx files
142
- def edit_docx_tags(files)
143
- sub_files = Utils.force_extension(files, ".konjac")
144
- sub_files.each do |sub_file|
145
- system "$EDITOR #{sub_file}"
146
- end
147
- end
148
-
149
145
  private
150
146
 
151
147
  # Performs a comparison between two nodes and accepts them as equivalent
@@ -1,4 +1,4 @@
1
1
  module Konjac
2
2
  # The current version number of Konjac
3
- VERSION = "0.2.6.8"
3
+ VERSION = "0.2.7"
4
4
  end
data/lib/konjac.rb CHANGED
@@ -15,12 +15,12 @@ module Konjac
15
15
  autoload :Config, "konjac/config"
16
16
  autoload :Dictionary, "konjac/dictionary"
17
17
  autoload :Language, "konjac/language"
18
+ autoload :Office, "konjac/office"
18
19
  autoload :Suggestor, "konjac/suggestor"
19
20
  autoload :Tag, "konjac/tag"
20
21
  autoload :TagManager, "konjac/tag_manager"
21
22
  autoload :Translator, "konjac/translator"
22
23
  autoload :Utils, "konjac/utils"
23
- autoload :Word, "konjac/word"
24
24
 
25
25
  Config.load
26
26
  end
data/lib/locales/en.yml CHANGED
@@ -30,7 +30,6 @@ en:
30
30
  word: Translate a word or phrase
31
31
  subcommands:
32
32
  add: Add a definition to translation memory
33
- edit: Edit the tags file for a .doc or .docx file
34
33
  export: Export text tags from a .doc or .docx file
35
34
  import: Import text tags into a .doc or .docx file
36
35
  language: Sets the default language
data/lib/locales/ja.yml CHANGED
@@ -30,7 +30,6 @@ ja:
30
30
  word: 文字列を翻訳する
31
31
  subcommands:
32
32
  add: 翻訳メモリに定義を追加する
33
- edit: .docまたは.docxファイルに当たるタグファイルを編集する
34
33
  export: .docまたは.docxファイルからタグを抽出する
35
34
  import: .docまたは.docxファイルにタグをインポートする
36
35
  language: 言語を設定する
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: konjac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6.8
4
+ version: 0.2.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-26 00:00:00.000000000 Z
12
+ date: 2012-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: amatch
16
- requirement: &70288827576500 !ruby/object:Gem::Requirement
16
+ requirement: &70314005857720 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70288827576500
24
+ version_requirements: *70314005857720
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: highline
27
- requirement: &70288827576060 !ruby/object:Gem::Requirement
27
+ requirement: &70314005857300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70288827576060
35
+ version_requirements: *70314005857300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: i18n
38
- requirement: &70288827575620 !ruby/object:Gem::Requirement
38
+ requirement: &70314005856880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70288827575620
46
+ version_requirements: *70314005856880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: nokogiri
49
- requirement: &70288827575200 !ruby/object:Gem::Requirement
49
+ requirement: &70314005856440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70288827575200
57
+ version_requirements: *70314005856440
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: sdoc
60
- requirement: &70288827574780 !ruby/object:Gem::Requirement
60
+ requirement: &70314005856000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70288827574780
68
+ version_requirements: *70314005856000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: term-ansicolor
71
- requirement: &70288827574360 !ruby/object:Gem::Requirement
71
+ requirement: &70314005855580 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70288827574360
79
+ version_requirements: *70314005855580
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: trollop
82
- requirement: &70288827573940 !ruby/object:Gem::Requirement
82
+ requirement: &70314005855160 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70288827573940
90
+ version_requirements: *70314005855160
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: autotest
93
- requirement: &70288827573520 !ruby/object:Gem::Requirement
93
+ requirement: &70314005854740 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70288827573520
101
+ version_requirements: *70314005854740
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: autotest-fsevent
104
- requirement: &70288827573100 !ruby/object:Gem::Requirement
104
+ requirement: &70314005854320 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70288827573100
112
+ version_requirements: *70314005854320
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: autotest-growl
115
- requirement: &70288827572680 !ruby/object:Gem::Requirement
115
+ requirement: &70314005853900 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70288827572680
123
+ version_requirements: *70314005853900
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: bundler
126
- requirement: &70288827572260 !ruby/object:Gem::Requirement
126
+ requirement: &70314005853480 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70288827572260
134
+ version_requirements: *70314005853480
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: rspec
137
- requirement: &70288827571840 !ruby/object:Gem::Requirement
137
+ requirement: &70314005853060 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70288827571840
145
+ version_requirements: *70314005853060
146
146
  description: A Ruby command-line utility for translating files using a YAML wordlist
147
147
  email:
148
148
  - bryan.mckelvey@gmail.com
@@ -161,6 +161,8 @@ files:
161
161
  - Rakefile
162
162
  - bin/konjac
163
163
  - konjac.gemspec
164
+ - lib/applescripts/konjac_powerpoint_export
165
+ - lib/applescripts/konjac_powerpoint_import
164
166
  - lib/applescripts/konjac_word_export
165
167
  - lib/applescripts/konjac_word_import
166
168
  - lib/konjac.rb
@@ -169,13 +171,13 @@ files:
169
171
  - lib/konjac/dictionary.rb
170
172
  - lib/konjac/exception.rb
171
173
  - lib/konjac/language.rb
174
+ - lib/konjac/office.rb
172
175
  - lib/konjac/suggestor.rb
173
176
  - lib/konjac/tag.rb
174
177
  - lib/konjac/tag_manager.rb
175
178
  - lib/konjac/translator.rb
176
179
  - lib/konjac/utils.rb
177
180
  - lib/konjac/version.rb
178
- - lib/konjac/word.rb
179
181
  - lib/locales/en.yml
180
182
  - lib/locales/ja.yml
181
183
  - spec/cli_spec.rb