rulex 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README.md +4 -0
- data/lib/rulex/rex/reader.rb +15 -1
- data/lib/rulex/tex/latex.treetop +3 -8
- data/lib/rulex/tex/node_extensions.rb +23 -2
- data/lib/rulex/tex/reader.rb +9 -2
- data/lib/rulex/version.rb +1 -1
- data/rulex.gemspec +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48ab31fba5ef554feb4384f82952d3c4a5d862f2
|
4
|
+
data.tar.gz: 4a3c7fdb779b6699113bbe24a4a2a508a3f5707a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8539de0be9ecdfad57d95f911e8c892de3eaead4e46e0f78db35785147b963898b38c6a88b6d6751ab90240ae5f724463baf5b3fbab88ee76984cc8e2c0c7bc
|
7
|
+
data.tar.gz: 7ffb697045a62a4cba6ee8ea0e9057c8110dfef505ffdd26280a0af1c527533c267fab8e606f8a20966aca07fdaeaf48e2c5ebd5a912f8f84f9352ceadd43aa7
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Rulex
|
2
2
|
|
3
|
+

|
4
|
+
[](https://codeclimate.com/github/Nicowcow/rulex)
|
5
|
+
[](https://codeclimate.com/github/Nicowcow/rulex/coverage)
|
6
|
+
[](http://inch-ci.org/github/Nicowcow/rulex)
|
3
7
|
Rulex is a rubygem allowing you to use Ruby while writing LaTex files. It reads rulex `.rex` files, and converts them into LaTex `.tex` files. A `.rex` file is a Ruby file; you can use (almost) everything the way you would in a Ruby script.
|
4
8
|
|
5
9
|
## Installation
|
data/lib/rulex/rex/reader.rb
CHANGED
@@ -8,12 +8,18 @@ module Rulex
|
|
8
8
|
@latex_reader = Rulex::Tex::Reader.new
|
9
9
|
end
|
10
10
|
|
11
|
+
# Feeds instructions, either as a [String] or Rulex instructions (parsed and then interpreted
|
12
|
+
# with instance_eval) or as a block (it must be either or). All the functions of
|
13
|
+
# Rulex::Rex::Reader are available.
|
14
|
+
# @param either a [String] or a [Block]
|
15
|
+
# @return self (the Rulex::Rex::Reader)
|
11
16
|
def read *args, &block
|
12
17
|
if args.length == 1
|
13
18
|
read_rex args.first
|
14
19
|
elsif block
|
15
20
|
instance_eval &block
|
16
21
|
end
|
22
|
+
self
|
17
23
|
end
|
18
24
|
|
19
25
|
def read_rex str
|
@@ -29,12 +35,20 @@ module Rulex
|
|
29
35
|
@content_stack.last << node
|
30
36
|
end
|
31
37
|
|
38
|
+
def append_nodes_to_content arr
|
39
|
+
@content_stack.last.concat arr
|
40
|
+
end
|
41
|
+
|
32
42
|
def raw str
|
33
43
|
add_node_to_content(type: :text, text: str)
|
34
44
|
end
|
35
45
|
|
46
|
+
def md str
|
47
|
+
raise RuntimeError, "not implemented"
|
48
|
+
end
|
49
|
+
|
36
50
|
def tex str
|
37
|
-
|
51
|
+
append_nodes_to_content @latex_reader.read(str).to_a
|
38
52
|
end
|
39
53
|
|
40
54
|
def import filepath
|
data/lib/rulex/tex/latex.treetop
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
grammar Latex
|
2
|
-
rule
|
3
|
-
(environment/command/text)* <Rulex::Tex::Grammar::
|
2
|
+
rule latex_content
|
3
|
+
(environment/command/text)* <Rulex::Tex::Grammar::LatexContent>
|
4
4
|
end
|
5
5
|
|
6
6
|
rule environment
|
@@ -8,12 +8,7 @@ grammar Latex
|
|
8
8
|
end
|
9
9
|
|
10
10
|
rule environment_text
|
11
|
-
|
12
|
-
#( document) !"\\end{" &{ |s| puts s[0].text_value; true}
|
13
|
-
document
|
14
|
-
|
15
|
-
#[^\\]* &{ |s| puts s[0].text_value; true}
|
16
|
-
#[^\\]*
|
11
|
+
latex_content
|
17
12
|
end
|
18
13
|
|
19
14
|
|
@@ -3,12 +3,32 @@ module Rulex
|
|
3
3
|
module Grammar
|
4
4
|
|
5
5
|
class Treetop::Runtime::SyntaxNode
|
6
|
+
|
7
|
+
|
8
|
+
# Goes through all its SyntaxNode children to build a Hash and Array based tree
|
9
|
+
# of the parsed document. A node_content is a Hash, containing a :type, and maybe
|
10
|
+
# containing :children. If node_content contains :children, they must form an Array.
|
11
|
+
# That is:
|
12
|
+
# * node_content MUST be a Hash that
|
13
|
+
# * MUST contain an entry :type of type Symbol or String
|
14
|
+
# * MAY contain an entry :children, which then MUST be of type Array
|
15
|
+
# * MAY contain any other kind of entries
|
16
|
+
#
|
17
|
+
# The before it is returned, the node_content is merged with the result from #content.
|
18
|
+
# @return the Hash object of the node's content
|
6
19
|
def node_content
|
7
20
|
h = {type: :node} #, log: elements.to_s}
|
8
21
|
h.merge!(:children => elements.map{|e| e.node_content}) if elements && !elements.empty?
|
9
22
|
h.merge!(log: text_value)
|
10
23
|
h.merge! content
|
11
24
|
end
|
25
|
+
|
26
|
+
# Build an Array of its children and returns it. Each children is a Hash (description in #node_content).
|
27
|
+
# @return [Array] the Array of children
|
28
|
+
def to_a
|
29
|
+
elements.map{|e| e.node_content} if elements
|
30
|
+
end
|
31
|
+
|
12
32
|
def content
|
13
33
|
{}
|
14
34
|
end
|
@@ -17,9 +37,10 @@ module Rulex
|
|
17
37
|
class CustomNode < Treetop::Runtime::SyntaxNode
|
18
38
|
end
|
19
39
|
|
20
|
-
class
|
40
|
+
class LatexContent < CustomNode
|
21
41
|
def content
|
22
|
-
{
|
42
|
+
#elements.map{|e| e.node_content} if elements && !elements.empty?
|
43
|
+
{type: :node}
|
23
44
|
end
|
24
45
|
end
|
25
46
|
|
data/lib/rulex/tex/reader.rb
CHANGED
@@ -15,14 +15,21 @@ module Rulex
|
|
15
15
|
@content = []
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
# Exports the Reader's content
|
19
|
+
# @return [Array] the Reader's content
|
19
20
|
def to_a
|
20
21
|
@content
|
21
22
|
end
|
22
23
|
alias_method :export, :to_a
|
23
24
|
|
25
|
+
# Takes a string of LaTeX contents, parses it to a Rulex tree, and sets that tree as
|
26
|
+
# the Reader's content
|
27
|
+
# @param str [String] the LaTeX contents as a String
|
28
|
+
# @return [Array] The new content
|
24
29
|
def read str
|
25
|
-
|
30
|
+
new_content = @parser.parse(str).to_a
|
31
|
+
raise TypeError, "content should be an Array" unless new_content and Array === new_content
|
32
|
+
@content = new_content
|
26
33
|
end
|
27
34
|
end
|
28
35
|
end
|
data/lib/rulex/version.rb
CHANGED
data/rulex.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_runtime_dependency "treetop"
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "rake"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
25
|
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.
|
4
|
+
version: 0.1.6
|
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-
|
11
|
+
date: 2015-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|