mathematical 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b65f349cfec4f55547f35a15b5a527632ad1d35
4
- data.tar.gz: 7aeb3ccd7a9525dea1563e220872e88acf9fadae
3
+ metadata.gz: b928c24ef87a4975a2b5851a97e5fa591647efe0
4
+ data.tar.gz: 704f73219af63fd695babd14c5ac5b71b1b2787e
5
5
  SHA512:
6
- metadata.gz: 7ad672a775f19bdd40c567830589c9e913365b8f84b3c820da3492269a52abb2f82d97a4d86892570cd8106a9136cdaf28871e16c308d551ab967c0d94e43efc
7
- data.tar.gz: 44f24e6ea31ad609be0a4cbe1bf13e8fdb08522125e4547c346afb4bfee467769b68f9f1dc86fab75191d67de6ce5475a2ca5de3e1cf338bd5e0945ff5f149ad
6
+ metadata.gz: 8bce8aee4fb278fb8fc4d41dfd91fc5f437027dc383077cdfdc8ee1a6ba1e146a2ab0306f06c260695681d570e3023124d563626a35b4f38108b44e63b8ac777
7
+ data.tar.gz: 1b6ce19f7871ba48488765fd56f7b98b997828c16ad272381600778cec0739a7656f44fae5fd8d863ca59eb207d2007b141b770e32ba784eec75fb123c977daa
@@ -39,6 +39,13 @@
39
39
  static VALUE rb_mMathematical;
40
40
  static VALUE rb_cMathematicalProcess;
41
41
 
42
+ // Raised when the contents could not be parsed
43
+ static VALUE rb_eParseError;
44
+ // Raised when the SVG document could not be created
45
+ static VALUE rb_eDocumentCreationError;
46
+ // Raised when the SVG document could not be read
47
+ static VALUE rb_eDocumentReadError;
48
+
42
49
  char* readFile(const char* filename) {
43
50
  FILE* file = fopen(filename, "r");
44
51
  if (file == NULL) return NULL;
@@ -87,7 +94,7 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
87
94
  // convert the TeX math to MathML
88
95
  char * mathml = lsm_itex_to_mathml(latex_code, latex_size);
89
96
 
90
- if (mathml == NULL) rb_raise(rb_eRuntimeError, "Failed to parse itex");
97
+ if (mathml == NULL) rb_raise(rb_eParseError, "Failed to parse itex");
91
98
 
92
99
  int mathml_size = strlen(mathml);
93
100
 
@@ -96,7 +103,7 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
96
103
 
97
104
  lsm_itex_free_mathml_buffer (mathml);
98
105
 
99
- if (document == NULL) rb_raise(rb_eRuntimeError, "Failed to create document");
106
+ if (document == NULL) rb_raise(rb_eDocumentCreationError, "Failed to create document");
100
107
 
101
108
  LsmDomView *view;
102
109
 
@@ -132,14 +139,19 @@ static VALUE MATHEMATICAL_process(VALUE self, VALUE rb_LatexCode, VALUE rb_TempF
132
139
 
133
140
  char* svg_contents = readFile(tempfile);
134
141
 
135
- if (svg_contents == NULL) rb_raise(rb_eRuntimeError, "Failed to read SVG contents");
142
+ if (svg_contents == NULL) rb_raise(rb_eDocumentReadError, "Failed to read SVG contents");
136
143
 
137
144
  return rb_str_new2(readFile(tempfile));
138
145
  }
139
146
 
140
147
  void Init_mathematical() {
141
148
  rb_mMathematical = rb_define_module("Mathematical");
149
+
142
150
  rb_cMathematicalProcess = rb_define_class_under(rb_mMathematical, "Process", rb_cObject);
151
+ rb_eParseError = rb_define_class_under(rb_mMathematical, "ParseError", rb_eStandardError);
152
+ rb_eDocumentCreationError = rb_define_class_under(rb_mMathematical, "DocumentCreationError", rb_eStandardError);
153
+ rb_eDocumentReadError = rb_define_class_under(rb_mMathematical, "DocumentReadError", rb_eStandardError);
154
+
143
155
  rb_define_method(rb_cMathematicalProcess, "initialize", MATHEMATICAL_init, 1);
144
156
  rb_define_method(rb_cMathematicalProcess, "process", MATHEMATICAL_process, 2);
145
157
  }
@@ -11,14 +11,8 @@ module Mathematical
11
11
  }
12
12
 
13
13
  def initialize(opts = {})
14
- raise(TypeError, "opts must be a hash!") unless opts.is_a? Hash
15
-
16
14
  @config = DEFAULT_OPTS.merge(opts)
17
- begin
18
- @processer = Mathematical::Process.new(@config)
19
- rescue TypeError => e # some error in the C code
20
- raise
21
- end
15
+ @processer = Mathematical::Process.new(@config)
22
16
  end
23
17
 
24
18
  def render(maths)
@@ -32,7 +26,7 @@ module Mathematical
32
26
  svg_content = File.open(tempfile.path, 'r') { |image_file| image_file.read }
33
27
  svg_content = svg_content[xml_header.length..-1] # remove starting <?xml...> tag
34
28
  @config[:base64] ? svg_to_base64(svg_content) : svg_content
35
- rescue RuntimeError => e # an error in the C code, probably a bad TeX parse
29
+ rescue ParseError, DocumentCreationError, DocumentReadError => e # an error in the C code, probably a bad TeX parse
36
30
  $stderr.puts "#{e.message}: #{maths}"
37
31
  maths
38
32
  end
@@ -1,3 +1,3 @@
1
1
  module Mathematical
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mathematical
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-09 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake-compiler