Module: Pseudocode
- Defined in:
- lib/pseudocode.rb,
lib/pseudocode/version.rb
Overview
Provides a Ruby wrapper for pseudocode server-side rendering.
Constant Summary collapse
- VERSION =
Version of this gem
'0.1.1'
- PSEUDOCODE_VERSION =
Version of the included Pseudocode.js
'2.2.0'
Class Attribute Summary collapse
-
.caption_count ⇒ Object
Emulated caption counter to allow manipulation from ruby.
-
.execjs_runtime ⇒ Object
The ExecJS runtime factory, default: ‘-> { ExecJS.runtime }`.
Class Method Summary collapse
-
.gem_path ⇒ Object
Return gem base path.
-
.pseudocode_context ⇒ Object
Return JS context, preloaded with KaTeX and Pseudocode.js.
-
.pseudocode_css_path ⇒ Object
Return path to included Pseudocode.js style file.
-
.pseudocode_js_path ⇒ Object
Return path to included Pseudocode.js script file.
-
.render(algorithm, line_number: false, **options) ⇒ String, Int
Renders the given pseudocode algorithm to HTML via pseudocode.renderToString.
Class Attribute Details
.caption_count ⇒ Object
Emulated caption counter to allow manipulation from ruby
45 46 47 |
# File 'lib/pseudocode.rb', line 45 def @caption_count end |
.execjs_runtime ⇒ Object
The ExecJS runtime factory, default: ‘-> { ExecJS.runtime }`. Set this before calling any other methods to use a different runtime.
This proc is guaranteed to be called at most once.
42 43 44 |
# File 'lib/pseudocode.rb', line 42 def execjs_runtime @execjs_runtime end |
Class Method Details
.gem_path ⇒ Object
Return gem base path
68 69 70 71 |
# File 'lib/pseudocode.rb', line 68 def gem_path @gem_path ||= File.(File.join(File.dirname(__FILE__), '..')) end |
.pseudocode_context ⇒ Object
Return JS context, preloaded with KaTeX and Pseudocode.js
48 49 50 51 52 53 |
# File 'lib/pseudocode.rb', line 48 def pseudocode_context @load_context_mutex.synchronize do source = (File.read Katex.katex_js_path) + (File.read pseudocode_js_path) @context ||= @execjs_runtime.call.compile source end end |
.pseudocode_css_path ⇒ Object
Return path to included Pseudocode.js style file
62 63 64 65 |
# File 'lib/pseudocode.rb', line 62 def pseudocode_css_path File. File.join('vendor', 'pseudocode', 'pseudocode.min.css'), gem_path end |
.pseudocode_js_path ⇒ Object
Return path to included Pseudocode.js script file
56 57 58 59 |
# File 'lib/pseudocode.rb', line 56 def pseudocode_js_path File. File.join('vendor', 'pseudocode', 'pseudocode.min.js'), gem_path end |
.render(algorithm, line_number: false, **options) ⇒ String, Int
This method is thread-safe as long as your ExecJS runtime is thread-safe. MiniRacer is the recommended runtime.
Renders the given pseudocode algorithm to HTML via pseudocode.renderToString.
29 30 31 32 33 34 35 36 |
# File 'lib/pseudocode.rb', line 29 def render(algorithm, line_number: false, **) return pseudocode_context.call('pseudocode.renderToString', algorithm, lineNumber: line_number, captionCount: @caption_count, **), @caption_count += 1 rescue ExecJS::ProgramError => e raise e end |