obf 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/obf/external.rb +9 -6
- data/lib/obf/pdf.rb +1 -1
- data/lib/obf/utils.rb +20 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd25c02539cdc01e06d0621a266aff2ffcaccb9
|
4
|
+
data.tar.gz: fd5b2cdbe77059ff5059a04832a29b6b2ac8a56f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f4f0079d4cabbebbf5c83c0c2f9d1cc37fc85080c23ff3793dcc7cf2d007fa46764604fd4d864571036028e654611881b7d8905f16cd16d3ff09162bb75f1f2
|
7
|
+
data.tar.gz: 72bb40d9f7930309e79c3e2628f2dd2e446b1b8a93c9f75dd065696c5a7e9ecd1dd82005466085f7720872c940ccfe76d75b06f5d3b7bc39a15401359f1c94ce
|
data/lib/obf/external.rb
CHANGED
@@ -192,11 +192,12 @@ module OBF::External
|
|
192
192
|
end
|
193
193
|
|
194
194
|
def self.from_obf(obf_json_or_path, opts)
|
195
|
+
opts ||= {}
|
195
196
|
obj = obf_json_or_path
|
196
197
|
if obj.is_a?(String)
|
197
|
-
obj = OBF::Utils.parse_obf(File.read(obf_json_or_path))
|
198
|
+
obj = OBF::Utils.parse_obf(File.read(obf_json_or_path), opts)
|
198
199
|
else
|
199
|
-
obj = OBF::Utils.parse_obf(obf_json_or_path)
|
200
|
+
obj = OBF::Utils.parse_obf(obf_json_or_path, opts)
|
200
201
|
end
|
201
202
|
|
202
203
|
['images', 'sounds'].each do |type|
|
@@ -272,8 +273,9 @@ module OBF::External
|
|
272
273
|
OBF::Utils.load_zip(obz_path) do |zipper|
|
273
274
|
obf_opts = {'zipper' => zipper, 'images' => {}, 'sounds' => {}, 'boards' => {}}
|
274
275
|
manifest = JSON.parse(zipper.read('manifest.json'))
|
276
|
+
obf_opts['manifest'] = manifest
|
275
277
|
root = manifest['root']
|
276
|
-
board = OBF::Utils.parse_obf(zipper.read(root))
|
278
|
+
board = OBF::Utils.parse_obf(zipper.read(root), obf_opts)
|
277
279
|
board['path'] = root
|
278
280
|
unvisited_boards = [board]
|
279
281
|
visited_boards = []
|
@@ -286,9 +288,9 @@ module OBF::External
|
|
286
288
|
if button['load_board']
|
287
289
|
all_boards = visited_boards + unvisited_boards
|
288
290
|
if all_boards.none?{|b| b['id'] == button['load_board']['id'] || b['path'] == button['load_board']['path'] }
|
289
|
-
path = button['load_board']['path'] || manifest[button['load_board']['id']]
|
291
|
+
path = button['load_board']['path'] || (manifest['paths'] && manifest['paths']['boards'] && manifest['paths']['boards'][button['load_board']['id']])
|
290
292
|
if path
|
291
|
-
b = OBF::Utils.parse_obf(zipper.read(path))
|
293
|
+
b = OBF::Utils.parse_obf(zipper.read(path), obf_opts)
|
292
294
|
b['path'] = path
|
293
295
|
button['load_board']['id'] = b['id']
|
294
296
|
unvisited_boards << b
|
@@ -310,11 +312,12 @@ module OBF::External
|
|
310
312
|
raise "sound ids must be present and unique" unless sounds.map{|i| i['id'] }.uniq.length == sounds.length
|
311
313
|
# TODO: try to fix the problem where multiple images or sounds have the same id --
|
312
314
|
# this involves reaching in and updating image and sound references on generated boards..
|
313
|
-
|
315
|
+
res = {
|
314
316
|
'boards' => boards,
|
315
317
|
'images' => images,
|
316
318
|
'sounds' => sounds
|
317
319
|
}
|
320
|
+
res
|
318
321
|
end
|
319
322
|
|
320
323
|
def self.to_pdf(board, dest_path, opts)
|
data/lib/obf/pdf.rb
CHANGED
@@ -193,7 +193,7 @@ module OBF::PDF
|
|
193
193
|
children << button['load_board']
|
194
194
|
all_boards = visited_boards + unvisited_boards
|
195
195
|
if all_boards.none?{|b| b['id'] == button['load_board']['id'] || b['path'] == button['load_board']['path'] }
|
196
|
-
path = button['load_board']['path'] || manifest[button['load_board']['id']]
|
196
|
+
path = button['load_board']['path'] || (manifest['paths'] && manifest['paths']['boards'] && manifest['paths']['boards'][button['load_board']['id']])
|
197
197
|
if path
|
198
198
|
b = OBF::Utils.parse_obf(zipper.read(path))
|
199
199
|
b['path'] = path
|
data/lib/obf/utils.rb
CHANGED
@@ -215,11 +215,30 @@ module OBF::Utils
|
|
215
215
|
color
|
216
216
|
end
|
217
217
|
|
218
|
-
def self.parse_obf(obj)
|
218
|
+
def self.parse_obf(obj, opts=nil)
|
219
|
+
opts ||= {}
|
219
220
|
json = obj
|
220
221
|
if obj.is_a?(String)
|
221
222
|
json = JSON.parse(obj)
|
222
223
|
end
|
224
|
+
if opts['manifest']
|
225
|
+
(json['buttons'] || []).each do |button|
|
226
|
+
if button['image_id']
|
227
|
+
# find image in list, if it has an id but no path, use the path from the manifest
|
228
|
+
image = (json['images'] || []).detect{|i| i['id'] == button['image_id'] }
|
229
|
+
if image && !image['path'] && !image['data'] && opts['manifest'] && opts['manifest']['images'] && opts['manifest']['images'][button['image_id']]
|
230
|
+
image['path'] = opts['manifest']['images'][button['image_id']]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
if button['sound_id']
|
234
|
+
# find sound in list, if it has an id but no path, use the path from the manifest
|
235
|
+
sound = (json['sounds'] || []).detect{|s| s['id'] == button['sound_id'] }
|
236
|
+
if sound && !sound['path'] && !sound['data'] && opts['manifest'] && opts['manifest']['sounds'] && opts['manifest']['sounds'][button['sound_id']]
|
237
|
+
sound['path'] = opts['manifest']['sounds'][button['sound_id']]
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
223
242
|
['images', 'sounds', 'buttons'].each do |key|
|
224
243
|
json["#{key}_hash"] = json[key]
|
225
244
|
if json[key].is_a?(Array)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Whitmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|