obf 0.2.7 → 0.2.8

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: fef34ab3a181c76b6c107a31dce9afcc447cf739
4
- data.tar.gz: 662acf486037c269ec73c1a412bab3602fb45028
3
+ metadata.gz: cd14606792d2167ee379b1350f895a10544f8ade
4
+ data.tar.gz: cf2c60064c88bcb3416522194d269a4fff9ec25b
5
5
  SHA512:
6
- metadata.gz: 7cb389f8925f8ce59b0d968bcf1518870a68aa24f7ad38c28a5e53b1c0857eb2940410a9e07d0da02bcf02f082d623280ce203191031409cb1cbb4d2a0853d24
7
- data.tar.gz: 1e6423f85d4668b8fa3eb49d7855ae0d7824cb7d6d519b130b52eafd16f9c15bb4e34a4c4d9b08d60ac8313de6c1c5c3d94686ca5b22c80931d35978d85359ff
6
+ metadata.gz: ff23f4727217c9de507be569fc47b77c5764d87cc4efd563419e1ac30dfab6be833c070d93816b30aa298e710a7d4a1ba95fb04307c13c3fbda08071c6868c10
7
+ data.tar.gz: 86ddfe73ba066d966263e463152c9f20d4f42d2fb8e97ccb0e13072c2b7a22f898ca948ad8207b8051834ae4e75760c6c660aa0d0872f699c4a99b5f9b44f3ef
data/lib/obf.rb CHANGED
@@ -15,4 +15,5 @@ module OBF
15
15
 
16
16
  require 'obf/picto4me'
17
17
  require 'obf/avaz'
18
+ require 'obf/unknown_file'
18
19
  end
@@ -1,8 +1,17 @@
1
1
  module OBF::External
2
2
  def self.to_obf(hash, dest_path, path_hash=nil)
3
+ if hash['boards']
4
+ old_hash = hash
5
+ hash = old_hash['boards'][0]
6
+ hash['images'] = content['images'] || []
7
+ hash['sounds'] = content['sounds'] || []
8
+ path_hash = nil
9
+ end
10
+
3
11
  res = OBF::Utils.obf_shell
4
12
  res['id'] = hash['id']
5
13
  res['locale'] = hash['locale'] || 'en'
14
+ res['format'] = 'open-board-0.1'
6
15
  res['name'] = hash['name']
7
16
  res['default_layout'] = hash['default_layout'] || 'landscape'
8
17
  res['url'] = hash['url']
@@ -183,6 +192,15 @@ module OBF::External
183
192
  end
184
193
 
185
194
  def self.to_obz(content, dest_path, opts)
195
+ if content['id']
196
+ old_content = content
197
+ content = {
198
+ 'boards' => [old_content],
199
+ 'images' => old_content['images'] || [],
200
+ 'sounds' => old_content['sounds'] || []
201
+ }
202
+ end
203
+
186
204
  paths = {}
187
205
  boards = content['boards']
188
206
  content['images'] ||= boards.map{|b| b['images'] }.flatten.uniq
@@ -203,6 +221,7 @@ module OBF::External
203
221
  end
204
222
  end
205
223
  manifest = {
224
+ 'format' => 'open-board-0.1',
206
225
  'root' => paths['boards'][root_board['id']]['path'],
207
226
  'paths' => {}
208
227
  }
@@ -147,7 +147,8 @@ module OBF::PDF
147
147
  # footer
148
148
  pdf.fill_color "aaaaaa"
149
149
  if OBF::PDF.footer_text
150
- pdf.text_box OBF::PDF.footer_text, :at => [doc_width - 300, text_height], :width => 200, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
150
+ text = OBF::PDF.footer_text
151
+ pdf.formatted_text_box [{:text => text, :link => OBF::PDF.footer_url}], :at => [doc_width - 300, text_height], :width => 200, :height => text_height, :align => :right, :valign => :center, :overflow => :shrink_to_fit
151
152
  end
152
153
  pdf.fill_color "000000"
153
154
  if options['pages']
@@ -0,0 +1,36 @@
1
+ module OBF::UnknownFile
2
+ def self.to_external(path)
3
+ type = OBF::Utils.identify_file(path)
4
+ if type == :obf
5
+ OBF::OBF.to_external(path, {})
6
+ elsif type == :obz
7
+ OBF::OBZ.to_external(path, {})
8
+ elsif type == :avaz
9
+ OBF::Avaz.to_external(path)
10
+ elsif type == :picto4me
11
+ OBF::Picto4me.to_external(path)
12
+ else
13
+ raise "unrecognized file type"
14
+ end
15
+ end
16
+
17
+ def self.to_obf(path, dest_path)
18
+ ext = to_external(path)
19
+ OBF::External.to_obf(ext, dest_path, {})
20
+ end
21
+
22
+ def self.to_obz(path, dest_path)
23
+ ext = to_external(path)
24
+ OBF::External.to_obz(ext, dest_path, {})
25
+ end
26
+
27
+ def self.to_pdf(path, dest_path)
28
+ ext = to_external(path)
29
+ OBF::External.to_pdf(ext, dest_path, {})
30
+ end
31
+
32
+ def self.to_png(path, dest_path)
33
+ ext = to_external(path)
34
+ OBF::External.to_png(ext, dest_path, {})
35
+ end
36
+ end
@@ -22,6 +22,47 @@ module OBF::Utils
22
22
  }
23
23
  end
24
24
 
25
+ def self.identify_file(file)
26
+ name = File.basename(file.path) rescue nil
27
+ if name.match(/\.obf$/)
28
+ return :obf
29
+ elsif name.match(/\.obz$/)
30
+ return :obz
31
+ elsif name.match(/\.avz$/)
32
+ return :avaz
33
+ else
34
+ json = JSON.parse(file.read) rescue nil
35
+ if json
36
+ if json['format'] && json['format'].match(/^open-board-/)
37
+ return :obf
38
+ end
39
+ else
40
+ begin
41
+ type = nil
42
+ load_zip(f.path) do |zipper|
43
+ if zipper.exists?('manifest.json')
44
+ json = JSON.parse(zipper.read('manifest.json')) rescue nil
45
+ if json['root'] && json['format'] && json['format'].match(/^open-board-/)
46
+ type = :obz
47
+ end
48
+ end
49
+ if !type && zipper.glob('*.js')
50
+ json = JSON.parse(zipper.read('*.js')) rescue nil
51
+ if json['locale'] && json['sheets']
52
+ type = :picto4me
53
+ end
54
+ end
55
+ end
56
+ return type if type
57
+ # rescue => e
58
+ # puts e.class.to_s
59
+ # puts e.message.to_s
60
+ end
61
+ end
62
+ end
63
+ return :unknown
64
+ end
65
+
25
66
  def self.image_raw(url)
26
67
  image = get_url(url)
27
68
  return nil unless image
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.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Whitmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-19 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -125,6 +125,7 @@ files:
125
125
  - lib/obf/pdf.rb
126
126
  - lib/obf/picto4me.rb
127
127
  - lib/obf/png.rb
128
+ - lib/obf/unknown_file.rb
128
129
  - lib/obf/utils.rb
129
130
  - lib/tinycolor_convert.js
130
131
  homepage: https://github.com/CoughDrop/obf