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 +4 -4
- data/examples/count.rex +1 -1
- data/examples/count.tex +1 -0
- data/lib/rulex/rex/reader.rb +23 -7
- data/lib/rulex/tex/writer.rb +25 -22
- data/lib/rulex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a4320567471b4e3e59824ba257532d95c470aa8
|
4
|
+
data.tar.gz: 425acc9636e13862d28f563a8251f62d55c08f0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd20d78fd564ec24c2bc9c0252a09d847369da9de5cc55bd41a7ae1cc47ba47d2a5822c41032497e7993513dd9f84ec2a341a571a9f5f3f4e091da37b9157ef7
|
7
|
+
data.tar.gz: 5f1a2eec6be5e5bcbe17e656fd72c6682a4051853e4725229e007708e7f0f22dcb3d56a16ba61796087dc6bff495287b8accd0c04a2a6bd60ee14c83a004a77f
|
data/examples/count.rex
CHANGED
data/examples/count.tex
CHANGED
data/lib/rulex/rex/reader.rb
CHANGED
@@ -30,16 +30,29 @@ module Rulex
|
|
30
30
|
@content
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
data/lib/rulex/tex/writer.rb
CHANGED
@@ -6,32 +6,35 @@ module Rulex
|
|
6
6
|
@content = ''
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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