-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic ragelpen working. Next up a run simulator.
- Loading branch information
Showing
8 changed files
with
187 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ | |
|
||
# editable text | ||
component 'editable_text' | ||
|
||
# code highlight | ||
component 'code_highlight' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'oga' | ||
|
||
class SvgWrapper | ||
def initialize(string) | ||
@root = Oga.parse_xml(string).at_xpath('/svg') | ||
@root.attributes.reject!{|a| ["xmlns", "xlink"].include?(a.name) } | ||
end | ||
|
||
def as_embed | ||
@root.to_xml | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class LoggingTasks < Volt::Task | ||
def log(message) | ||
puts message | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
require 'open3' | ||
require 'main/lib/svg_wrapper' | ||
|
||
class RagelTasks < Volt::Task | ||
def run_ragel(pen_id, ragel_input) | ||
|
||
# lookup the pen | ||
store._pens.find(id: pen_id).first.then do |pen| | ||
|
||
# clear any errors | ||
pen._error = "" | ||
|
||
# set the ragel_content | ||
pen._ragel_content = ragel_input | ||
|
||
# setup tempdir | ||
Dir.mktmpdir do |dir| | ||
|
||
# create the ragel file | ||
ragel_file = create_ragel(dir, pen._ragel_content) | ||
|
||
# run ragel -R to create the rb file and save the output | ||
ruby_file, err, status = create_ruby(dir, ragel_file) | ||
return build_error(pen, err) unless status.success? | ||
pen._ruby_content = File.read(ruby_file) | ||
|
||
# # run ragel -V to create the dot file | ||
dot_file, err = create_dot(dir, ragel_file) | ||
return build_error(pen, err) unless status.success? | ||
pen._dot_content = File.read(dot_file) | ||
|
||
# convert to png (or svg) | ||
svg_file, err = create_svg(dir, dot_file) | ||
return build_error(pen, err) unless status.success? | ||
pen._svg_content = SvgWrapper.new(File.read(svg_file)).as_embed | ||
|
||
# return png/svg or link to the same | ||
"ok" | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
def create_ragel(dir, content) | ||
File.join(dir, "input.rl").tap do |fn_output| | ||
File.open(fn_output, 'w') do |file| | ||
file.write(content) | ||
end | ||
end | ||
end | ||
|
||
def create_ruby(dir, fn_input) | ||
File.join(dir, "output.rb").tap do |fn_output| | ||
out, err, status = Open3.capture3("ragel -R #{fn_input} -o #{fn_output}") | ||
return [fn_output, err, status] | ||
end | ||
end | ||
|
||
def create_dot(dir, fn_input) | ||
File.join(dir, "output.dot").tap do |fn_output| | ||
out, err, status = Open3.capture3("ragel -V #{fn_input} -o #{fn_output}") | ||
return [fn_output, err, status] | ||
end | ||
end | ||
|
||
def create_svg(dir, fn_input) | ||
File.join(dir, "output.svg").tap do |fn_output| | ||
out, err, status = Open3.capture3("dot -Tsvg #{fn_input} -o #{fn_output}") | ||
return [fn_output, err, status] | ||
end | ||
end | ||
|
||
def build_error(pen, err) | ||
pen._error = err | ||
pen._ruby_content = '' | ||
pen._dot_content = '' | ||
pen._svg_content = '' | ||
Promise.error(err) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters