rulex 0.1.1 → 0.1.2

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: d4415c9c1a3b0a1b94e0a8227b9baa9e3dfd8ca6
4
- data.tar.gz: 934a03920ea1d907f2544a5545a6456d1aedb5d8
3
+ metadata.gz: 5a4320567471b4e3e59824ba257532d95c470aa8
4
+ data.tar.gz: 425acc9636e13862d28f563a8251f62d55c08f0d
5
5
  SHA512:
6
- metadata.gz: 841a5ce7e54eb466677677639f643b0eb8dfc17ae0903fa7fa3d6fa8f441f58c8c99e8d98ad2e746d2e42df26ba1200b2c44da5ac7e002bae9823f32589d578a
7
- data.tar.gz: 5ba3f8afe690b1b242f4954c6318291f3957ab261ec3f056f8c78322cf898e0d1cd22b58bf838a7133c37efbff827c06420e1b8c4525fdbe1dfce9092fa02c66
6
+ metadata.gz: fd20d78fd564ec24c2bc9c0252a09d847369da9de5cc55bd41a7ae1cc47ba47d2a5822c41032497e7993513dd9f84ec2a341a571a9f5f3f4e091da37b9157ef7
7
+ data.tar.gz: 5f1a2eec6be5e5bcbe17e656fd72c6682a4051853e4725229e007708e7f0f22dcb3d56a16ba61796087dc6bff495287b8accd0c04a2a6bd60ee14c83a004a77f
data/examples/count.rex CHANGED
@@ -34,7 +34,7 @@ document do
34
34
  count_from (1..5)
35
35
  count_from (10..20)
36
36
 
37
- raw "Good job, now off to section "; ref :acks;
37
+ raw "Good job, now off to section #{pure_ref :acks}\n" # #{pure_ref :acks}\n"
38
38
 
39
39
  section "Acknowledgements"
40
40
  label :acks
data/examples/count.tex CHANGED
@@ -24,6 +24,7 @@ Let's try to count.\begin{itemize}
24
24
  \item{20}
25
25
  \end{itemize}
26
26
  Good job, now off to section \ref{acks}
27
+
27
28
  \section{Acknowledgements}
28
29
  \label{acks}
29
30
  Finally I would like to thank
@@ -30,16 +30,29 @@ module Rulex
30
30
  @content
31
31
  end
32
32
 
33
- def tex_command(name, params)
34
- if params.length == 1
35
- add_to_content(type: :command, name: name, arguments: params)
36
- elsif params.length == 2
37
- opts = params[0]
38
- args = params[1]
39
- add_to_content(type: :command, name: name, arguments: args, options: opts)
33
+ def build_tex_command(name, params)
34
+ case params.length
35
+ when 1
36
+ {type: :command, name: name, arguments: params}
37
+ when 2
38
+ first = params[0]
39
+ second = params[1]
40
+ if Array === params[0] && Array === params[1]
41
+ {type: :command, name: name, arguments: second, options: first}
42
+ elsif String === params[0] && String === params[1]
43
+ {type: :command, name: name, arguments: [first, second]}
44
+ else
45
+ error "something is not quite right with the parameters"
46
+ end
47
+ else
48
+ error "wrong number of params"
40
49
  end
41
50
  end
42
51
 
52
+ def tex_command(name, params)
53
+ add_to_content build_tex_command name, params
54
+ end
55
+
43
56
  def depth
44
57
  @content_stack.length - 1
45
58
  end
@@ -55,6 +68,9 @@ module Rulex
55
68
  def method_missing(m_id, *args, &block)
56
69
  if block
57
70
  tex_environment(m_id, args, block)
71
+ elsif /pure_([a-zA-Z]+)/.match(m_id)
72
+ Rulex::Tex::Writer.to_str(build_tex_command($1,args))
73
+ #"\\#{$1}{1}{2}"
58
74
  else
59
75
  tex_command(m_id, args)
60
76
  end
@@ -6,32 +6,35 @@ module Rulex
6
6
  @content = ''
7
7
  end
8
8
 
9
- def import arr
10
- return unless arr
11
- arr.each do |item|
12
-
13
- case item[:type]
14
- when :command
15
- @content += "\\#{item[:name]}"
16
- if opts = item[:options]
17
- @content += '[' + opts.join(',') + ']'
18
- end
19
- item[:arguments].each do |arg|
20
- @content += "{#{arg}}"
21
- end
22
- @content += "\n"
23
- when :text
24
- @content += item[:text]
25
- when :environment
26
- @content += "\\begin{#{item[:name]}}\n"
27
- import item[:children]
28
- @content += "\\end{#{item[:name]}}\n"
29
- else
30
- import item[:children] if item[:children]
9
+ def self.to_str item
10
+ case item[:type]
11
+ when :command
12
+ str = "\\#{item[:name]}"
13
+ if opts = item[:options]
14
+ str += '[' + opts.join(',') + ']'
15
+ end
16
+ item[:arguments].each do |arg|
17
+ str += "{#{arg}}"
18
+ end
19
+ str += "\n"
20
+ when :text
21
+ res = item[:text]
22
+ when :environment
23
+ str = "\\begin{#{item[:name]}}\n"
24
+ if children = item[:children]
25
+ str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c}
31
26
  end
27
+ res = str += "\\end{#{item[:name]}}\n"
28
+ else
29
+ str = ""
30
+ res = str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} if item[:children]
32
31
  end
33
32
  end
34
33
 
34
+ def import arr
35
+ arr.each {|i| @content += Rulex::Tex::Writer.to_str i} if arr
36
+ end
37
+
35
38
  def to_s
36
39
  @content
37
40
  end
data/lib/rulex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rulex
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rulex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolas Mattia