Class: Jekyll::PseudoCodeB::HtmlBrush
- Defined in:
- lib/jekyll-pseudocode-b/html_brush.rb
Instance Method Summary collapse
- #comment(txt) ⇒ Object
- #fn(txt) ⇒ Object
- #indent(txt) ⇒ Object
- #is_numeric?(s) ⇒ Boolean
- #math(txt) ⇒ Object
- #number(txt) ⇒ Object
- #objfn(obj, fnc) ⇒ Object
- #op(txt) ⇒ Object
- #plain(txt) ⇒ Object
- #special(txt, sub) ⇒ Object
- #string(txt) ⇒ Object
- #sym(txt) ⇒ Object
- #var(txt, sub) ⇒ Object
Instance Method Details
#comment(txt) ⇒ Object
54 55 56 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 54 def comment(txt) "<span class='comment'>/* #{txt.strip} */</span>" end |
#fn(txt) ⇒ Object
22 23 24 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 22 def fn(txt) "<span class='function'>#{txt}</span>" end |
#indent(txt) ⇒ Object
62 63 64 65 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 62 def indent(txt) txt.gsub! "\t", ' ' "<span class='indent'>#{txt}</span>" end |
#is_numeric?(s) ⇒ Boolean
7 8 9 10 11 12 13 14 15 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 7 def is_numeric?(s) begin Float(s) rescue false # not numeric else true # numeric end end |
#math(txt) ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 96 def math(txt) symbol = case txt when 'pi' then 'π' when 'tau' then '𝛕' when 'infinity' then '∞' else txt end # FIXME: html conversion for some operators "<span class='math-symbol'>#{symbol}</span>" end |
#number(txt) ⇒ Object
30 31 32 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 30 def number(txt) "<span class='numeric'>#{txt}</span>" end |
#objfn(obj, fnc) ⇒ Object
26 27 28 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 26 def objfn(obj, fnc) "<span class='variable'>#{obj}</span><span class='operator'>.</span><span class='function'>#{fnc}</span>" end |
#op(txt) ⇒ Object
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 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 67 def op(txt) symbol = case txt when '<' then '<' when '>' then '>' when '<=' then '≤' when '>=' then '≥' when '<-' then '←' when '->' then '→' when '<--' then '⟵' when '-->' then '⟶' when '<->' then '↔' when '<-->' then '⟷' when '*' then '×' when '[' then '[' when ']' then ']' when '!=' then '≠' when '<>' then '≠' when '=' then '=' when ':=' then '≔' when '+' then '+' when '-' then '-' when '/' then '/' when '==' then '=' else txt end # FIXME: html conversion for some operators "<span class='operator'>#{symbol}</span>" end |
#plain(txt) ⇒ Object
107 108 109 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 107 def plain(txt) "#{txt}" end |
#special(txt, sub) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 34 def special(txt, sub) if sub "<span class='special'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>" else "<span class='special'>#{txt}</span>" end end |
#string(txt) ⇒ Object
58 59 60 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 58 def string(txt) "<span class='string'>#{txt}</span>" end |
#sym(txt) ⇒ Object
17 18 19 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 17 def sym(txt) "<span class='symbol'>#{txt}</span>" end |
#var(txt, sub) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jekyll-pseudocode-b/html_brush.rb', line 42 def var(txt, sub) if sub "<span class='variable'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>" else if (is_numeric?(txt)) "<span class='numeric'>#{txt}</span>" else "<span class='variable'>#{txt}</span>" end end end |