ruby3mf 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/bin/cli.rb +5 -0
- data/lib/ruby3mf/content_types.rb +2 -4
- data/lib/ruby3mf/document.rb +24 -26
- data/lib/ruby3mf/hash.rb +1 -1
- data/lib/ruby3mf/model3mf.rb +1 -1
- data/lib/ruby3mf/texture3mf.rb +5 -4
- data/lib/ruby3mf/version.rb +1 -1
- data/lib/ruby3mf.rb +9 -9
- data/ruby3mf.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8735913c55551b73173f7f8d17b8ec85031c4cb4
|
4
|
+
data.tar.gz: f0d565d1debb5049533f1bcd04c6942798a7e458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd4d6bfa3f8308522b458318fb42eb648d1936f4748bacc983f4207328a15d762f21afc500b1873eef55993cac98e9dca44afdcd2061eb3e3ecf77053e6bfd82
|
7
|
+
data.tar.gz: 08a66aac1559d688a642801fb8add46beedc3743304f48472169f21739f81f3cc81057ea6e77999f8db0767485c574cbe959db1a9556e699e9a2d8fe94b5bc9d
|
data/.gitignore
CHANGED
data/bin/cli.rb
ADDED
@@ -14,8 +14,8 @@ class ContentTypes
|
|
14
14
|
l.warning '[Content_Types].xml must contain root name Types' unless doc.children.first.name == "Types"
|
15
15
|
|
16
16
|
required_content_types = ['application/vnd.openxmlformats-package.relationships+xml', 'application/vnd.ms-package.3dmanufacturing-3dmodel+xml']
|
17
|
-
optional_content_types = ['application/vnd.ms-printing.printticket+xml']
|
18
|
-
all_types = required_content_types + optional_content_types
|
17
|
+
#optional_content_types = ['application/vnd.ms-printing.printticket+xml']
|
18
|
+
#all_types = required_content_types + optional_content_types
|
19
19
|
|
20
20
|
types_node = doc.children.first
|
21
21
|
types_node.children.each do |node|
|
@@ -35,8 +35,6 @@ class ContentTypes
|
|
35
35
|
end
|
36
36
|
rescue Nokogiri::XML::SyntaxError => e
|
37
37
|
l.error "[Content_Types].xml file is not valid XML. #{e}", page: 15
|
38
|
-
rescue Zip::Error
|
39
|
-
l.error 'Problem extracting [Content_Types].xml from zip file'
|
40
38
|
end
|
41
39
|
end
|
42
40
|
|
data/lib/ruby3mf/document.rb
CHANGED
@@ -4,6 +4,7 @@ class Document
|
|
4
4
|
attr_accessor :thumbnails
|
5
5
|
attr_accessor :textures
|
6
6
|
attr_accessor :objects
|
7
|
+
attr_accessor :zip_filename
|
7
8
|
|
8
9
|
# Relationship Type => Class validating relationship type
|
9
10
|
RELATIONSHIP_TYPES = {
|
@@ -21,18 +22,15 @@ class Document
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.read(input_file)
|
24
|
-
|
25
|
-
m
|
26
|
-
|
25
|
+
|
26
|
+
m = new(input_file)
|
27
|
+
|
28
|
+
begin
|
29
|
+
Log3mf.context "zip" do |l|
|
27
30
|
begin
|
28
31
|
Zip.warn_invalid_date = false
|
29
32
|
Zip::File.open(input_file) do |zip_file|
|
30
33
|
|
31
|
-
# puts "Zip contents:"
|
32
|
-
# zip_file.each do |entry|
|
33
|
-
# puts entry
|
34
|
-
# end
|
35
|
-
|
36
34
|
l.info "Zip file is valid"
|
37
35
|
|
38
36
|
l.context "content types" do |l|
|
@@ -88,7 +86,6 @@ class Document
|
|
88
86
|
return m
|
89
87
|
rescue Zip::Error
|
90
88
|
l.fatal_error 'File provided is not a valid ZIP archive', page: 9
|
91
|
-
return nil
|
92
89
|
end
|
93
90
|
end
|
94
91
|
rescue Log3mf::FatalError
|
@@ -98,32 +95,33 @@ class Document
|
|
98
95
|
end
|
99
96
|
|
100
97
|
def write(output_file = nil)
|
101
|
-
output_file =
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
else
|
110
|
-
out.put_next_entry(e.name)
|
111
|
-
if objects[e.name]
|
112
|
-
out.write objects[e.name]
|
98
|
+
output_file = zip_filename if output_file.nil?
|
99
|
+
|
100
|
+
Zip::File.open(zip_filename) do |input_zip_file|
|
101
|
+
|
102
|
+
buffer = Zip::OutputStream.write_buffer do |out|
|
103
|
+
input_zip_file.entries.each do |e|
|
104
|
+
if e.directory?
|
105
|
+
out.copy_raw_entry(e)
|
113
106
|
else
|
114
|
-
out.
|
107
|
+
out.put_next_entry(e.name)
|
108
|
+
if objects[e.name]
|
109
|
+
out.write objects[e.name]
|
110
|
+
else
|
111
|
+
out.write e.get_input_stream.read
|
112
|
+
end
|
115
113
|
end
|
116
114
|
end
|
117
115
|
end
|
118
|
-
end
|
119
116
|
|
120
|
-
|
117
|
+
File.open(output_file, "wb") {|f| f.write(buffer.string) }
|
118
|
+
|
119
|
+
end
|
121
120
|
|
122
|
-
File.open(output_file, "wb") {|f| f.write(buffer.string) }
|
123
121
|
end
|
124
122
|
|
125
123
|
def contents_for(path)
|
126
|
-
Zip::File.open(
|
124
|
+
Zip::File.open(zip_filename) do |zip_file|
|
127
125
|
zip_file.glob(path).first.get_input_stream.read
|
128
126
|
end
|
129
127
|
end
|
data/lib/ruby3mf/hash.rb
CHANGED
data/lib/ruby3mf/model3mf.rb
CHANGED
@@ -12,6 +12,7 @@ class Model3mf
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
|
15
16
|
def self.parse(document, zip_entry, relationships)
|
16
17
|
model_hash = {}
|
17
18
|
Log3mf.context "parsing model" do |l|
|
@@ -25,7 +26,6 @@ class Model3mf
|
|
25
26
|
model_hash = Hash.from_xml(doc)
|
26
27
|
rescue Nokogiri::XML::SyntaxError => e
|
27
28
|
l.fatal_error "Model file invalid XML. Exception #{e}"
|
28
|
-
doc.errors.each { |error| l.error error }
|
29
29
|
end
|
30
30
|
|
31
31
|
l.context "verifying 3D payload required resources" do |l|
|
data/lib/ruby3mf/texture3mf.rb
CHANGED
@@ -6,11 +6,12 @@ class Texture3mf
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.parse(document, relationship_file, relationships)
|
9
|
-
t = Texture3mf.new(document)
|
10
|
-
t.name = relationship_file.name
|
11
9
|
|
12
|
-
|
13
|
-
|
10
|
+
t = new(document)
|
11
|
+
t.name = relationship_file.name
|
12
|
+
stream = relationship_file.get_input_stream
|
13
|
+
img_type = MimeMagic.by_magic(stream)
|
14
|
+
@bytes = stream.read
|
14
15
|
Log3mf.context "Texture3mf" do |l|
|
15
16
|
l.debug "texture is of type: #{img_type}"
|
16
17
|
l.error "Expected a png or jpeg texture but the texture was of type #{img_type}", spec: :material, page: 16 unless ['image/png', 'image/jpeg'].include? img_type.type
|
data/lib/ruby3mf/version.rb
CHANGED
data/lib/ruby3mf.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
require_relative "ruby3mf/version"
|
2
|
+
require_relative "ruby3mf/log3mf"
|
3
|
+
require_relative "ruby3mf/document"
|
4
|
+
require_relative "ruby3mf/content_types"
|
5
|
+
require_relative "ruby3mf/hash"
|
6
|
+
require_relative "ruby3mf/model3mf"
|
7
|
+
require_relative "ruby3mf/relationships"
|
8
|
+
require_relative "ruby3mf/thumbnail3mf"
|
9
|
+
require_relative "ruby3mf/texture3mf"
|
10
10
|
|
11
11
|
require 'zip'
|
12
12
|
require 'nokogiri'
|
data/ruby3mf.gemspec
CHANGED
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency "bundler", "~> 1.11"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "simplecov"
|
33
34
|
|
34
35
|
spec.add_runtime_dependency 'rubyzip'
|
35
36
|
spec.add_runtime_dependency 'nokogiri', '~>1.6.8'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby3mf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Whitmarsh, Jeff Porter, and William Hertling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rubyzip
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -113,6 +127,7 @@ files:
|
|
113
127
|
- LICENSE.txt
|
114
128
|
- README.md
|
115
129
|
- Rakefile
|
130
|
+
- bin/cli.rb
|
116
131
|
- bin/console
|
117
132
|
- bin/setup
|
118
133
|
- lib/ruby3mf.rb
|