rulex 0.1.0 → 0.1.1

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: b837fec66c1b803f2637a4a8158437c68cb463cd
4
- data.tar.gz: 85fa266b72812926f6a4f1e4b1f73c674e44636c
3
+ metadata.gz: d4415c9c1a3b0a1b94e0a8227b9baa9e3dfd8ca6
4
+ data.tar.gz: 934a03920ea1d907f2544a5545a6456d1aedb5d8
5
5
  SHA512:
6
- metadata.gz: dc75afa077337de174796be17e7f34fb07b633cda9a7ee9aa19f0021956db8e5134e837cb23399b634a4b45b327a435eb1c08de2cebb90298a57b20fbc4f6e2a
7
- data.tar.gz: 65bec4fdc03d4869418162d50380595ac45705d346bff3868b46b1a9cdb2032c29050ad0f047ed2161ab25e1506b44df349b1dd1a5a152b35211b72f722bb90c
6
+ metadata.gz: 841a5ce7e54eb466677677639f643b0eb8dfc17ae0903fa7fa3d6fa8f441f58c8c99e8d98ad2e746d2e42df26ba1200b2c44da5ac7e002bae9823f32589d578a
7
+ data.tar.gz: 5ba3f8afe690b1b242f4954c6318291f3957ab261ec3f056f8c78322cf898e0d1cd22b58bf838a7133c37efbff827c06420e1b8c4525fdbe1dfce9092fa02c66
data/README.md CHANGED
@@ -20,33 +20,58 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- **Everything is still very experimental, and might break at any point!**
24
-
25
23
  *For detailed documentation, please refer to the code, mainly `/spec/rulex_spec.rb`. There are a few examples as well in `/examples/`.*
26
24
 
25
+ **Everything is still very experimental, and might break at any point!** Consider using a specific version, and sticking to it if it works.
26
+
27
+
27
28
 
28
29
  ### Example
29
30
 
30
31
  ```ruby
31
- # example.rex
32
- documentclass :article
32
+ # First thing to note, your rex file must follow the TeX document structure.
33
+ # You will start with a `\documentclass` call, then wrap your document in a
34
+ # `document` environment by calling `\begin{document}` and `\end{document}`.
35
+ # The only difference here is that most of this process is wrapped in Ruby.
36
+
37
+
38
+ # Just call `documentclass` to set the document class. This for instance will
39
+ # be translated to `\documentclass{article}`.
40
+ documentclass :article
33
41
 
42
+ # You can define your own Ruby functions.
34
43
  def count_from range
35
44
  first = range.first
36
45
  last = range.last
37
46
 
47
+ # Any function call, like `functionname("arg1", "arg2",...)`, will be
48
+ # translated to `\functionname{arg1}{arg2}{...}`. That way, you can start
49
+ # a subsection as follows:
38
50
  subsection "how to count from #{first} to #{last}"
51
+
52
+ # Raw is a special `rex` function. It writes its argument as text in the rex
53
+ # tree (and subsequently in the TeX file) without parsing it. Note that the
54
+ # fact that it is not writing a `\raw` function is exceptional, because `raw`
55
+ # is a `rex` reserved function name. To use `raw` like you would use
56
+ # `subsection` call `tex_command :raw`.
39
57
  raw "Let's try to count."
40
58
 
59
+ # If you pass a command a bloc, it will start a TeX environment. The
60
+ # following `itemize do ... end` is equivalent to `\begin{itemize} ... \end{itemize}`.
41
61
  itemize do
42
62
  range.each do |n|
43
63
  item n.to_s
44
64
  end
45
65
  end
46
66
  end
67
+
47
68
  document do
48
69
  section "A Short Lecture on How to Count"
49
70
 
71
+
72
+ # You can of course call the functions you defined (AND NOT BE LIMITED TO
73
+ # 9 ******* ARGUMENTS)
74
+
50
75
  count_from (1..5)
51
76
  count_from (10..20)
52
77
 
@@ -58,6 +83,7 @@ document do
58
83
  raw "Finally I would like to thank \n"
59
84
 
60
85
  enumerate do
86
+ # You can of course use just any kind of Ruby goodness you like.
61
87
  %w[Donald\ Knuth Yukihiro\ Matsumoto].each do |name|
62
88
  item "Mr. #{name}"
63
89
  end
@@ -127,3 +153,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
127
153
  * Add markdown support to `Rulex::Rex::Reader` through Pandoc
128
154
  * The parser needs some beefin-up (not sure what it does with spaces, especially with command options)
129
155
  * Maybe add some syntax for LaTeX commands to output text directly rather than store the command in the tree
156
+ * Coffee is on me if you write a Vim plugin
@@ -0,0 +1,50 @@
1
+ # First thing to note, your rex file must follow the TeX document structure. You will start
2
+ # with a `\documentclass` call, then wrap your document in a `document` environment by calling `\begin{document}` and `\end{document}`. The only difference here is that most of this process is wrapped in Ruby.
3
+
4
+
5
+ # Just call `documentclass` to set the document class. This for instance will be translated to `\documentclass{article}`.
6
+ documentclass :article
7
+
8
+ # You can define your own Ruby functions.
9
+ def count_from range
10
+ first = range.first
11
+ last = range.last
12
+
13
+ # Any function call, like `functionname("arg1", "arg2",...)`, will be translated to `\functionname{arg1}{arg2}{...}`.
14
+ # That way, you can start a subsection as follows:
15
+ subsection "how to count from #{first} to #{last}"
16
+
17
+ # Raw is a special `rex` function. It writes its argument as text in the rex tree (and subsequently in the TeX file) without parsing it. Note that the fact that it is not writing a `\raw` function is exceptional, because `raw` is a `rex` reserved function name. To use `raw` like you would use `subsection` call `tex_command :raw`.
18
+ raw "Let's try to count."
19
+
20
+ # If you pass a command a bloc, it will start a TeX environment. The following `itemize do ... end` is equivalent to `\begin{itemize} ... \end{itemize}`.
21
+ itemize do
22
+ range.each do |n|
23
+ item n.to_s
24
+ end
25
+ end
26
+ end
27
+
28
+ document do
29
+ section "A Short Lecture on How to Count"
30
+
31
+
32
+ # You can of course call the functions you defined (AND NOT BE LIMITED TO 9 ******* ARGUMENTS)
33
+
34
+ count_from (1..5)
35
+ count_from (10..20)
36
+
37
+ raw "Good job, now off to section "; ref :acks;
38
+
39
+ section "Acknowledgements"
40
+ label :acks
41
+
42
+ raw "Finally I would like to thank \n"
43
+
44
+ enumerate do
45
+ # You can of course use just any kind of Ruby goodness you like.
46
+ %w[Donald\ Knuth Yukihiro\ Matsumoto].each do |name|
47
+ item "Mr. #{name}"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ \documentclass{article}
2
+ \begin{document}
3
+ \section{A Short Lecture on How to Count}
4
+ \subsection{how to count from 1 to 5}
5
+ Let's try to count.\begin{itemize}
6
+ \item{1}
7
+ \item{2}
8
+ \item{3}
9
+ \item{4}
10
+ \item{5}
11
+ \end{itemize}
12
+ \subsection{how to count from 10 to 20}
13
+ Let's try to count.\begin{itemize}
14
+ \item{10}
15
+ \item{11}
16
+ \item{12}
17
+ \item{13}
18
+ \item{14}
19
+ \item{15}
20
+ \item{16}
21
+ \item{17}
22
+ \item{18}
23
+ \item{19}
24
+ \item{20}
25
+ \end{itemize}
26
+ Good job, now off to section \ref{acks}
27
+ \section{Acknowledgements}
28
+ \label{acks}
29
+ Finally I would like to thank
30
+ \begin{enumerate}
31
+ \item{Mr. Donald Knuth}
32
+ \item{Mr. Yukihiro Matsumoto}
33
+ \end{enumerate}
34
+ \end{document}
@@ -1,6 +1,7 @@
1
1
  module Rulex
2
2
  module Rex
3
3
  class Reader
4
+
4
5
  def initialize
5
6
  @content = []
6
7
  @content_stack = [@content]
@@ -15,8 +16,6 @@ module Rulex
15
16
 
16
17
  def raw str
17
18
  add_to_content(type: :text, text: str)
18
- #new_node = {type: :text, text: str }
19
- #@content << new_node
20
19
  end
21
20
 
22
21
  def tex str
@@ -31,8 +30,18 @@ module Rulex
31
30
  @content
32
31
  end
33
32
 
34
- def tex_command(name, args)
35
- add_to_content(type: :command, name: name, arguments: args)
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)
40
+ end
41
+ end
42
+
43
+ def depth
44
+ @content_stack.length - 1
36
45
  end
37
46
 
38
47
  def tex_environment(name, args, block)
@@ -40,12 +49,6 @@ module Rulex
40
49
  @content_stack.push []
41
50
  read &block
42
51
  new_node.merge!(children: @content_stack.pop)
43
-
44
- #new_node = {type: :environment, name: name, arguments: args}
45
- #deeper_parser = Rulex::Rex::Reader.new
46
- #deeper_parser.read &block
47
- #new_node.merge!(children: deeper_parser.export)
48
-
49
52
  add_to_content new_node
50
53
  end
51
54
 
@@ -13,6 +13,9 @@ module Rulex
13
13
  case item[:type]
14
14
  when :command
15
15
  @content += "\\#{item[:name]}"
16
+ if opts = item[:options]
17
+ @content += '[' + opts.join(',') + ']'
18
+ end
16
19
  item[:arguments].each do |arg|
17
20
  @content += "{#{arg}}"
18
21
  end
data/lib/rulex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rulex
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/rulex.gemspec CHANGED
@@ -17,10 +17,6 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- #if spec.respond_to?(:metadata)
21
- #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
22
- #end
23
-
24
20
  spec.add_runtime_dependency "treetop"
25
21
 
26
22
  spec.add_development_dependency "bundler", "~> 1.9"
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.0
4
+ version: 0.1.1
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-23 00:00:00.000000000 Z
11
+ date: 2015-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: treetop
@@ -83,6 +83,8 @@ files:
83
83
  - bin/console
84
84
  - bin/setup
85
85
  - examples/bracket_bloc.tex
86
+ - examples/count.rex
87
+ - examples/count.tex
86
88
  - examples/hello_world.rex
87
89
  - examples/hello_world.tex
88
90
  - examples/simple.tex