rulex 0.1.3 → 0.1.4

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: 615cc7d413292fbe99bd79cb0cdaee48d9e6ca91
4
- data.tar.gz: 32dfee7e649b5f48c60d1f5e0e2d59e37c01b382
3
+ metadata.gz: bed57ce48166e9fd4098a7bdb005aa1547f8a387
4
+ data.tar.gz: 2b7bdd9322fc92f6842bda43a39787dace26fffa
5
5
  SHA512:
6
- metadata.gz: d506ff5ad0e7037afa8498884f06b4c591de5074b5de206480b21ca90b2e1db5011e36d517993eeb3f89334861e0918e6e0bc184c818b0d9eeda35a34107ccee
7
- data.tar.gz: d4f609a790eb152cc056ec6fb26a0bdbb27711e719616dd6d003f5b629689510188f152348d0fbede1513714fcd259ffcda0c4644395ca7c5b02aca46c9c7fc8
6
+ metadata.gz: 426395fdabefb0a5003eea0a072599ca2df66d663113b754527fc92079ed5da31443a62380932d0bdb106837ccb927d6daf8a6d68e456f17552e50c8b9793a42
7
+ data.tar.gz: 785ab466a702b3e5a2787f91b457e464a2fc65ca718dc9af3d968610cf29ead1681319855d52ba4ee835b9eec80f8d148cf95607268ecfa7e7227c7813f09ee7
@@ -46,8 +46,16 @@ module Rulex
46
46
  end
47
47
 
48
48
  def build_tex_command(name, params)
49
+
50
+ fail ArgumentError, "Command name must be a String or a Symbol, got #{name} of type #{name.class}" unless
51
+ String === name or Symbol === name
52
+
49
53
  case params.length
54
+ when 0
55
+ {type: :command, name: name}
50
56
  when 1
57
+ fail ArgumentError "Command arguments must all be String s or Symbol s, got #{params}" unless
58
+ params.all?{|s| String === s or Symbol === s}
51
59
  {type: :command, name: name, arguments: params}
52
60
  when 2
53
61
  first = params[0]
@@ -57,21 +65,22 @@ module Rulex
57
65
  elsif String === params[0] && String === params[1]
58
66
  {type: :command, name: name, arguments: [first, second]}
59
67
  else
60
- error "something is not quite right with the parameters"
68
+ raise ArgumentError, "something is not quite right with the parameters"
61
69
  end
62
70
  else
63
- error "wrong number of params"
71
+ raise ArgumentError, "wrong number of params"
64
72
  end
65
73
  end
66
74
 
67
- def tex_command(name, params)
68
- add_node_to_content build_tex_command name, params
69
- end
70
75
 
71
76
  def depth
72
77
  @content_stack.length - 1
73
78
  end
74
79
 
80
+ def tex_command(name, *params)
81
+ add_node_to_content build_tex_command name, *params
82
+ end
83
+
75
84
  def tex_environment(name, *args, &block)
76
85
  new_node = {type: :environment, name: name, arguments: args}
77
86
  @content_stack.push []
@@ -7,30 +7,40 @@ module Rulex
7
7
  end
8
8
 
9
9
  def self.to_str item
10
+ raise TypeError, "item must be a Hash, got #{item}" unless Hash === item
11
+ raise ArgumentError, ":type must be defined" unless item[:type]
10
12
  case item[:type]
11
13
  when :command
14
+ raise TypeError, "command name must be a Symbol or a String" unless
15
+ Symbol === item[:name] or String === item[:name]
16
+
12
17
  str = "\\#{item[:name]}"
13
18
  if opts = item[:options]
14
19
  str += '[' + opts.join(',') + ']'
15
20
  end
16
- item[:arguments].each do |arg|
17
- str += "{#{arg}}"
21
+ if args = item[:arguments] and not args.empty?
22
+ str += '{' + args.join('}{') + '}'
18
23
  end
19
24
  str += "\n"
20
25
  when :text
21
26
  res = item[:text]
22
27
  when :environment
23
- str = "\\begin{#{item[:name]}}\n"
28
+ str = "\\begin{#{item[:name]}}"
29
+ if args = item[:arguments] and not args.empty?
30
+ str += '{' + args.join('}{') + '}'
31
+ end
32
+ str += "\n"
24
33
  if children = item[:children]
25
34
  str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c}
26
35
  end
27
36
  res = str += "\\end{#{item[:name]}}\n"
28
37
  else
29
38
  if item[:children]
30
- str = ""
31
- res = str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} if item[:children] else
39
+ raise TypeError, "Children must form an array" unless Array === item[:children]
40
+ str = item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} if item[:children]
41
+ else
32
42
  ""
33
- end
43
+ end
34
44
 
35
45
  end
36
46
  end
data/lib/rulex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rulex
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Mattia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-26 00:00:00.000000000 Z
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop