rulex 0.1.7 → 0.1.8
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/README.md +3 -3
- data/lib/rulex/rex/reader.rb +68 -7
- data/lib/rulex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b7e37b8df7d840e4e80107918b400adf154118
|
4
|
+
data.tar.gz: 6c174975e1eae9fc164383f81a918ee363da107d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e47edef1e0851c47b8bb2622ae257824f5dc27bb004199aa5d7fbf2fcbf0253356f09e4deea3eeadd29ebd8bc32d7d252d18c072428736ecba65a7815821553
|
7
|
+
data.tar.gz: 456de3ad1e30f61e8482f7cf08f7199df06f3dc6dc5eed962718dca3f37f4fc096cd703bb1cfb05ab86bb3a0b0dd6185f82c383a9b7a7e7b7a010b916fc62c9d
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Rulex
|
2
2
|
|
3
|
+
[](https://gitter.im/Nicowcow/rulex?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
|
+
|
3
5
|

|
4
6
|
[](https://codeclimate.com/github/Nicowcow/rulex)
|
5
7
|
[](https://codeclimate.com/github/Nicowcow/rulex/coverage)
|
@@ -70,7 +72,7 @@ end
|
|
70
72
|
document do
|
71
73
|
section "A Short Lecture on How to Count"
|
72
74
|
|
73
|
-
# You can use markdown
|
75
|
+
# You can use markdown (though you need `pandoc` to be installed)
|
74
76
|
md "Pay attention, the following is *very* important."
|
75
77
|
|
76
78
|
# You can of course call the functions you defined (AND NOT BE LIMITED TO 9 ******* ARGUMENTS)
|
@@ -179,9 +181,7 @@ That's the point. Seriously, the code might need some refactoring, and can alway
|
|
179
181
|
|
180
182
|
* `Rulex::Tex::Grammar::Document` is a big misnommer! It should be changed to something that reflects better what its role is.
|
181
183
|
* `Rulex::Rex::Reader#raw` might not be the best name either. Maybe change it to text.
|
182
|
-
* Add markdown support to `Rulex::Rex::Reader` through Pandoc
|
183
184
|
* The parser needs some beefin-up (not sure what it does with spaces, especially with command options)
|
184
|
-
* Maybe add some syntax for LaTeX commands to output text directly rather than store the command in the tree
|
185
185
|
* Coffee is on me if you write a Vim plugin
|
186
186
|
* Another coffee if you also write a Rake task.
|
187
187
|
* There should be some special delimiters like Ruby's `#{...}` (maybe `#< ... >`) which would translate all method calls to `pure_` method calls. That would make inlining method calls in strings much easier.
|
data/lib/rulex/rex/reader.rb
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
require 'pandoc-ruby'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
#grammar_path = File.join(File.dirname(File.expand_path(__FILE__)),
|
5
|
+
#'rulex.treetop')
|
6
|
+
#Treetop.load grammar_path
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
# Used when reading YAML
|
12
|
+
class Object
|
13
|
+
def deep_symbolize_keys
|
14
|
+
return self.inject({}){|memo,(k,v)| memo[k.to_sym] = v.deep_symbolize_keys; memo} if self.is_a? Hash
|
15
|
+
return self.inject([]){|memo,v | memo << v.deep_symbolize_keys; memo} if self.is_a? Array
|
16
|
+
return self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
2
20
|
|
3
21
|
module Rulex
|
4
22
|
module Rex
|
5
23
|
class Reader
|
6
|
-
|
7
24
|
def initialize
|
8
25
|
@content = []
|
9
26
|
@content_stack = [@content]
|
10
27
|
@latex_reader = Rulex::Tex::Reader.new
|
28
|
+
@delimiters = {
|
29
|
+
raw: { open: "<##", close: "##>"},
|
30
|
+
tex: { open: "<(#", close: "#)>"}
|
31
|
+
}
|
11
32
|
end
|
12
33
|
|
13
34
|
# Feeds instructions, either as a [String] or Rulex instructions (parsed and then interpreted
|
@@ -28,9 +49,20 @@ module Rulex
|
|
28
49
|
instance_eval rex_to_ruby str
|
29
50
|
end
|
30
51
|
|
31
|
-
# There are a few characters ('\\', '\[' and '\]') that even %q[] escapes
|
32
52
|
def rex_to_ruby str
|
33
|
-
|
53
|
+
@delimiters.inject(str) do |str, d|
|
54
|
+
key = d.first
|
55
|
+
val = d[1]
|
56
|
+
|
57
|
+
open_delimiter = Regexp.escape val[:open]
|
58
|
+
close_delimiter = Regexp.escape val[:close]
|
59
|
+
|
60
|
+
regexp = /#{open_delimiter}(((?!#{close_delimiter})[\s\S])+)#{close_delimiter}/
|
61
|
+
|
62
|
+
# There are a few characters ('\\', '\[' and '\]') that even %q[] "un"-escapes,
|
63
|
+
# hence the second gsub
|
64
|
+
str.gsub(regexp) { |m| "#{key} %q[" + $1.gsub("\\","\\\\\\\\") + "]"}
|
65
|
+
end
|
34
66
|
end
|
35
67
|
|
36
68
|
def add_node_to_content node
|
@@ -55,8 +87,37 @@ module Rulex
|
|
55
87
|
append_nodes_to_content @latex_reader.read(str).to_a
|
56
88
|
end
|
57
89
|
|
58
|
-
|
59
|
-
|
90
|
+
|
91
|
+
# TODO
|
92
|
+
def import str
|
93
|
+
import_file str
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
# Reads a file, given a filepath
|
98
|
+
# @filepath a [String]
|
99
|
+
# @return self (the Rulex::Rex::Reader)
|
100
|
+
def import_file filepath
|
101
|
+
content = File.read(filepath)
|
102
|
+
import_content content
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
# Reads some content
|
107
|
+
# @content a [String]
|
108
|
+
# @return self (the Rulex::Rex::Reader)
|
109
|
+
def import_content content
|
110
|
+
if content =~ /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m
|
111
|
+
content = $'
|
112
|
+
data = YAML.load($1).deep_symbolize_keys
|
113
|
+
end
|
114
|
+
content ||= ""
|
115
|
+
data ||= {}
|
116
|
+
if(delimiters = data[:delimiters])
|
117
|
+
@delimiters.merge! delimiters
|
118
|
+
end
|
119
|
+
|
120
|
+
read content
|
60
121
|
end
|
61
122
|
|
62
123
|
def export
|
@@ -66,14 +127,14 @@ module Rulex
|
|
66
127
|
def build_tex_command(name, params)
|
67
128
|
|
68
129
|
fail ArgumentError, "Command name must be a String or a Symbol, got #{name} of type #{name.class}" unless
|
69
|
-
|
130
|
+
String === name or Symbol === name
|
70
131
|
|
71
132
|
case params.length
|
72
133
|
when 0
|
73
134
|
{type: :command, name: name}
|
74
135
|
when 1
|
75
136
|
fail ArgumentError "Command arguments must all be String s or Symbol s, got #{params}" unless
|
76
|
-
|
137
|
+
params.all?{|s| String === s or Symbol === s}
|
77
138
|
{type: :command, name: name, arguments: params}
|
78
139
|
when 2
|
79
140
|
first = params[0]
|
data/lib/rulex/version.rb
CHANGED
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.8
|
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-
|
11
|
+
date: 2015-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: treetop
|