forked from plurimath/plurimath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
125 lines (104 loc) · 3.01 KB
/
Rakefile
File metadata and controls
125 lines (104 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
require "erb"
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "opal/rspec/rake_task"
require_relative "lib/plurimath"
RSpec::Core::RakeTask.new(:spec)
# Opal testing support
begin
Opal::RSpec::RakeTask.new(:"spec-opal")
rescue LoadError
# Likely the dependencies haven't been upstreamed yet. Ensure you
# run those tests via the `plurimath-js` repo's `env/plurimath`
# script.
end
DOC_FILES = {
"supported_parens_list.adoc" => :paren,
"supported_symbols_list.adoc" => :symbols,
"intent_supported_classes.adoc" => :intent,
}.freeze
DOC_FILES.each do |file_name, type|
file file_name => [] do
write_doc_file(file_name, type: type)
end
end
def write_doc_file(doc_file, type:)
File.open(doc_file, "a") do |file|
case type
when :intent
write_intent_doc_file(file)
else
paren_symbols_doc(file, type)
end
end
end
def paren_symbols_doc(file, type)
file.write(file_header)
Plurimath::Utility.send(:"#{type}_files").each do |klass|
next if klass::INPUT.empty?
file_name = File.basename(klass.const_source_location(:INPUT).first, ".rb")
file.write(documentation_content(file_name, klass))
end
file.write("|===")
end
def documentation_content(file_name, klass)
<<~DOCUMENTATION
| #{Plurimath::Utility.capitalize(file_name)}
| `#{Plurimath::Utility.hexcode_in_input(klass) || klass.input(:asciimath).first}`
#{input_for_formats(klass)}
DOCUMENTATION
end
def file_header
<<~HEADER
|===
| Math symbol name | Unicode character | AsciiMath | LaTeX | MathML | OMML | UnicodeMath
HEADER
end
def input_for_formats(klass)
%i[asciimath latex mathml omml unicodemath].map do |format|
<<~ROW
| #{format_input(format, klass)}
ROW
end.join("")
end
def format_input(format, klass)
klass.input(format).flatten.map do |s|
if [:latex, :unicodemath].include?(format)
"`\\#{s}`"
else
"`#{s}`"
end
end.join(", ").gsub(/\|/, "\\|")
end
def write_intent_doc_file(file)
file.write("= List of classes supporting `intent` encoding with relevant values\n")
intent_classes.each do |klass|
intents = klass.new.intent_names.values.map do |intent|
"`#{intent}`"
end
file.write(
<<~INTENT
* `#{klass.name.gsub("Plurimath::Math::", "")}`
** #{intents.join("\n** ")}
INTENT
)
end
file.write("\nIntent for unary classes like, sin, cos, tan, etc. will be `Function`.\n")
end
def intent_classes
intent_classes = [
Plurimath::Math::Function::TernaryFunction.descendants,
Plurimath::Math::Function::BinaryFunction.descendants,
Plurimath::Math::Function::UnaryFunction.descendants,
Plurimath::Math::Function::Table.descendants,
Plurimath::Math::Symbols::Symbol.descendants,
Plurimath::Math::Function::UnaryFunction,
Plurimath::Math::Function::Table,
Plurimath::Math::Function::Nary,
Plurimath::Math::Formula,
].flatten
intent_classes.select do |klass|
klass.instance_methods(false).include?(:intent_names)
end
end
task :default => :spec