mirror of
https://github.com/aziis98/ro-vis.git
synced 2026-10-24 23:01:54 +00:00
enhancements to the latex cards
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
require "json"
|
||||
require "js"
|
||||
|
||||
def print_step(label, state)
|
||||
puts "Ruby: #{label} #{state}"
|
||||
JS.global[:rubyOutputs].push({
|
||||
label: label,
|
||||
state: state
|
||||
})
|
||||
end
|
||||
|
||||
def run(config)
|
||||
i = config["i"] || 1
|
||||
j = config["j"] || 1
|
||||
n = config["n"] || 10
|
||||
|
||||
print_step "Initial", { i: i, j: j, n: n }
|
||||
|
||||
n.times do
|
||||
m = i + j
|
||||
i = j
|
||||
j = m
|
||||
|
||||
print_step "Step", { i: i, j: j }
|
||||
end
|
||||
|
||||
return i
|
||||
end
|
||||
|
||||
run({ "n" => 10 })
|
||||
@@ -0,0 +1,35 @@
|
||||
class CardDSL
|
||||
def initialize
|
||||
@blocks = []
|
||||
end
|
||||
|
||||
def text(content)
|
||||
@blocks << { type: "text", content: content }
|
||||
end
|
||||
|
||||
def code(content)
|
||||
@blocks << { type: "code", content: content }
|
||||
end
|
||||
|
||||
def math(content)
|
||||
@blocks << { type: "math", content: content }
|
||||
end
|
||||
|
||||
def blocks
|
||||
@blocks
|
||||
end
|
||||
end
|
||||
|
||||
def print_card(&block)
|
||||
card = CardDSL.new
|
||||
card.instance_eval(&block)
|
||||
|
||||
card.blocks.each { |block| p block }
|
||||
# JS.global[:rubyOutputs].push(card)
|
||||
end
|
||||
|
||||
print_card do
|
||||
text "Hello, world!"
|
||||
code "puts 'Hello, world!'"
|
||||
math "\\begin{bmatrix} 1 & 2 \\\\ 3 & 4 \\end{bmatrix}"
|
||||
end
|
||||
Reference in New Issue
Block a user