jekyll-pseudocode-b 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/README.md +108 -0
- data/Rakefile +12 -0
- data/doc/output-sample.png +0 -0
- data/doc/samplecode.png +0 -0
- data/jekyll-pseudocode-b.gemspec +27 -0
- data/lib/jekyll-pseudocode-b/brush.rb +54 -0
- data/lib/jekyll-pseudocode-b/grammar.rb +72 -0
- data/lib/jekyll-pseudocode-b/html_brush.rb +103 -0
- data/lib/jekyll-pseudocode-b/mock_brush.rb +59 -0
- data/lib/jekyll-pseudocode-b/version.rb +5 -0
- data/lib/jekyll-pseudocode-b.rb +40 -0
- data/spec/grammar_spec.rb +66 -0
- data/spec/html_spec.rb +43 -0
- data/spec/spec_helper.rb +9 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a206281381f3106b1d82cc74b939b8ab10ec3ee
|
4
|
+
data.tar.gz: 7d81b69ca7f21bfbd8fcea8147f99244ab429a21
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dadf8baefeda70808d11d0a76d5a2ffab0d462611dd53ded0957bdc3af1ac18d168b1b376ad565eaf198c98f0c93c1e8f9e909e39dbe2d60fbc398b73f3f9697
|
7
|
+
data.tar.gz: 891fbd1fc6c702d5746fb5b79211873f8e53e59d1e250310a8741639b5ad52ca180796b1c11cde3b2f52d8cca3b50764466bf71872e39d5960106c63c05ea932
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-head
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# jekyll-pseudocode-b
|
2
|
+
_A pseudocode/algorithm formatter for sites powered by Jekyll._
|
3
|
+
|
4
|
+
This is a updated fork from **[wkm/jekyll-pseudo](https://github.com/wkm/jekyll-pseudo)**.
|
5
|
+
|
6
|
+
Sometimes you don't want to use a particular programming language to
|
7
|
+
demonstrate a concept because of the syntactic overhead. **jekyll-pseudocode-b** lets
|
8
|
+
you use a gently styled free-formated representation.
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## Usage:
|
13
|
+
|
14
|
+
0. Install the `gem`
|
15
|
+
|
16
|
+
```
|
17
|
+
gem install jekyll-pseudocode-b
|
18
|
+
```
|
19
|
+
|
20
|
+
1. Add the following line to your site's `Gemfile`
|
21
|
+
|
22
|
+
```GemFile
|
23
|
+
gem 'jekyll-pseudocode-b'
|
24
|
+
```
|
25
|
+
|
26
|
+
2. And add the following line to your site plugin's `_config.yml`
|
27
|
+
|
28
|
+
```yml
|
29
|
+
plugins:
|
30
|
+
- jekyll-pseudocode-b
|
31
|
+
```
|
32
|
+
|
33
|
+
Note: if `jekyll --version` is less than `3.5` use:
|
34
|
+
|
35
|
+
```yml
|
36
|
+
gems:
|
37
|
+
- jekyll-pseudocode-b
|
38
|
+
```
|
39
|
+
|
40
|
+
## Language
|
41
|
+
|
42
|
+
* Indentation is preserved
|
43
|
+
* A word beginning with a capital letter is a keyword
|
44
|
+
* A word followed by parentheses is a function name
|
45
|
+
* All other words are variables
|
46
|
+
* Words within double quotes are generally strings
|
47
|
+
* Variables that calls a function can reproduce the following output: `myVar.FUNCTION(a);`
|
48
|
+
|
49
|
+
## Auto-Formatted Syntax
|
50
|
+
|
51
|
+
The following table shows auto-formated symbols:
|
52
|
+
|
53
|
+
| Syntax | Symbol |
|
54
|
+
| :------: | :--------: |
|
55
|
+
| <- | ← |
|
56
|
+
| -> | → |
|
57
|
+
| <-- | ⟵ |
|
58
|
+
| --> | ⟶ |
|
59
|
+
| => | ≥ |
|
60
|
+
| <= | ≤ |
|
61
|
+
| == | = |
|
62
|
+
| := | ≔ |
|
63
|
+
| = | = |
|
64
|
+
| < | < |
|
65
|
+
| > | > |
|
66
|
+
| [ | [ |
|
67
|
+
| ] | ] |
|
68
|
+
| <-> | ↔ |
|
69
|
+
| <--> | ⟷ |
|
70
|
+
| $pi | π |
|
71
|
+
| $tau | 𝛕 |
|
72
|
+
|
73
|
+
## Output
|
74
|
+
|
75
|
+
Output is annotated with `<span>` classes and can be styled using CSS. Typically keywords are made bold and variables are italicized. Using the following code lines:
|
76
|
+
|
77
|
+
{% pseudocode %}
|
78
|
+
Function swap(old, new)
|
79
|
+
remaining <- quorumSize
|
80
|
+
success <- False
|
81
|
+
For Each host
|
82
|
+
result[host] <- send(host, propose(old, new))
|
83
|
+
If result[host] = "ok"
|
84
|
+
remaining--
|
85
|
+
|
86
|
+
If remaining > 1+quorumSize/2
|
87
|
+
success <- True
|
88
|
+
|
89
|
+
For Each result
|
90
|
+
If success
|
91
|
+
send(host, confirm(old, new))
|
92
|
+
Else
|
93
|
+
send(host, cancel(old, new))
|
94
|
+
{% endpseudocode %}
|
95
|
+
|
96
|
+
With a bit of formatting, the above code becomes:
|
97
|
+
|
98
|
+

|
99
|
+
|
100
|
+
## More Styles
|
101
|
+
|
102
|
+
You can also create your own style for pseudo-codes like images below. Check on the `css` folder for CSS files examples.
|
103
|
+
|
104
|
+
_Comming soon_
|
105
|
+
|
106
|
+
## Author
|
107
|
+
|
108
|
+
[Wiktor Macura](https://github.com/wkm) is the author of this plugin. This is fork for updated version with some new features. Also it's based on the fork of [Victor Bazterra](https://github.com/baites).
|
data/Rakefile
ADDED
Binary file
|
data/doc/samplecode.png
ADDED
Binary file
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "jekyll-pseudocode-b/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-pseudocode-b"
|
7
|
+
spec.version = Jekyll::PseudoCodeB::VERSION
|
8
|
+
spec.authors = ["Tobias Ulrich", "Victor Bazterra", "Wiktor Macura"]
|
9
|
+
spec.email = ["tobiasbulrich@gmail.com","bazterra@gmail.com", "wmacura@gmail.com"]
|
10
|
+
spec.homepage = "http://github.com/wkm/jekyll-pseudo"
|
11
|
+
spec.summary = %q{A trivial jekyll plugin for formatting pseudocode}
|
12
|
+
spec.description = %q{jekyll-pseudocode helps typeset pseudocode with minimal formatting}
|
13
|
+
spec.licenses = ["MIT"]
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split("\n")
|
16
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
spec.add_runtime_dependency "jekyll", "~> 3.0"
|
22
|
+
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
26
|
+
spec.add_development_dependency "rake", "~> 12"
|
27
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PseudoCodeB
|
3
|
+
class Brush
|
4
|
+
# format a symbol
|
5
|
+
def sym(txt)
|
6
|
+
raise 'not implemented'
|
7
|
+
end
|
8
|
+
|
9
|
+
# format a function
|
10
|
+
def fn(txt)
|
11
|
+
raise 'not implemented'
|
12
|
+
end
|
13
|
+
|
14
|
+
# format a object call function
|
15
|
+
def objfn(txt)
|
16
|
+
raise 'not implemented'
|
17
|
+
end
|
18
|
+
|
19
|
+
# format a variable
|
20
|
+
def variable(txt, sub)
|
21
|
+
raise 'not implemented'
|
22
|
+
end
|
23
|
+
|
24
|
+
# format a comment
|
25
|
+
def comment(txt)
|
26
|
+
raise 'not implemented'
|
27
|
+
end
|
28
|
+
|
29
|
+
# format an operator
|
30
|
+
def op(txt)
|
31
|
+
raise 'not implemented'
|
32
|
+
end
|
33
|
+
|
34
|
+
# format a string
|
35
|
+
def string(txt)
|
36
|
+
raise 'not implemented'
|
37
|
+
end
|
38
|
+
|
39
|
+
# render plain text
|
40
|
+
def plain(txt)
|
41
|
+
raise 'not implemented'
|
42
|
+
end
|
43
|
+
|
44
|
+
# render math symbols
|
45
|
+
def math(txt)
|
46
|
+
raise 'not implemented'
|
47
|
+
end
|
48
|
+
|
49
|
+
def number(txt)
|
50
|
+
raise 'not implemented'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module PseudoCodeB
|
3
|
+
class Grammar
|
4
|
+
# parse a block of text, using the given brush to format output (works in a single pass)
|
5
|
+
def format(txt, brush)
|
6
|
+
results = []
|
7
|
+
|
8
|
+
mappings = [
|
9
|
+
[/\#(.*$)/, :comment],
|
10
|
+
[/\/\/(.*$)/, :comment],
|
11
|
+
[/(\w+)(?=[({\[])/, :fn],
|
12
|
+
[/\b([a-zA-Z0-9]*\w+)\.(\w+)(?=[({\[])/, :objfn], # obj calls funcion
|
13
|
+
[/\b([A-Z]\w+)/, :sym],
|
14
|
+
[/(\".*?\")/, :string],
|
15
|
+
[/(<-|->|\+\+|<=|>=|--|!=|:=|==|<>|<->|<-->|<--|-->)/, :op], # try these operators first
|
16
|
+
[/([-()\[\]{}=<>+*\/])/, :op], # and these second
|
17
|
+
[/(\$pi|\$tau)/, :math],
|
18
|
+
[/\b([0-9]*\.?[0-9]+)/, :number],
|
19
|
+
[/\b([a-z][a-zA-Z0-9]*)(_[a-zA-Z0-9]+)?/, :var],
|
20
|
+
[/^(\s+)/, :indent]
|
21
|
+
]
|
22
|
+
|
23
|
+
# replace tabs with three spaces
|
24
|
+
txt.gsub! /^\t/, ' '
|
25
|
+
|
26
|
+
# count leading whitespace
|
27
|
+
ws = txt.scan(/^ */).map do |leading|
|
28
|
+
leading.size
|
29
|
+
end
|
30
|
+
leading = (ws.min or 0)
|
31
|
+
|
32
|
+
# remove leading whitespace of the given length
|
33
|
+
if leading > 0
|
34
|
+
r = /^ {#{leading}}/
|
35
|
+
txt.gsub! r, ''
|
36
|
+
end
|
37
|
+
|
38
|
+
# lazy man's parser (we don't do any of that silly backtracking)
|
39
|
+
cursor = 0
|
40
|
+
while true
|
41
|
+
matches = mappings.map do |pair|
|
42
|
+
[pair[0].match(txt, cursor), pair[1]]
|
43
|
+
end
|
44
|
+
|
45
|
+
upto = matches.min_by do |pair|
|
46
|
+
matchdata = pair[0]
|
47
|
+
if matchdata == nil
|
48
|
+
txt.size
|
49
|
+
else
|
50
|
+
matchdata.begin(0)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if upto[0] != nil
|
55
|
+
results << brush.plain(txt.slice(cursor, upto[0].begin(0)-cursor))
|
56
|
+
|
57
|
+
# which match?
|
58
|
+
captures = upto[0].captures
|
59
|
+
results << brush.method(upto[1]).call(*captures)
|
60
|
+
cursor = upto[0].end(0)
|
61
|
+
else
|
62
|
+
# no matches remaining
|
63
|
+
results << brush.plain(txt.slice(cursor, txt.size))
|
64
|
+
break
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
return results.join('')
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'jekyll-pseudocode-b/brush'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module PseudoCodeB
|
5
|
+
class HtmlBrush < Jekyll::PseudoCodeB::Brush
|
6
|
+
|
7
|
+
def is_numeric?(s)
|
8
|
+
begin
|
9
|
+
Float(s)
|
10
|
+
rescue
|
11
|
+
false # not numeric
|
12
|
+
else
|
13
|
+
true # numeric
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def sym(txt)
|
18
|
+
"<span class='symbol'>#{txt}</span>"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def fn(txt)
|
23
|
+
"<span class='function'>#{txt}</span>"
|
24
|
+
end
|
25
|
+
|
26
|
+
def objfn(obj, fnc)
|
27
|
+
"<span class='variable'>#{obj}</span><span class='operator'>.</span><span class='function'>#{fnc}</span>"
|
28
|
+
end
|
29
|
+
|
30
|
+
def number(txt)
|
31
|
+
"<span class='numeric'>#{txt}</span>"
|
32
|
+
end
|
33
|
+
|
34
|
+
def var(txt, sub)
|
35
|
+
if sub
|
36
|
+
"<span class='variable'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>"
|
37
|
+
else
|
38
|
+
if (is_numeric?(txt))
|
39
|
+
"<span class='numeric'>#{txt}</span>"
|
40
|
+
else
|
41
|
+
"<span class='variable'>#{txt}</span>"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def comment(txt)
|
47
|
+
"<span class='comment'>/* #{txt.strip} */</span>"
|
48
|
+
end
|
49
|
+
|
50
|
+
def string(txt)
|
51
|
+
"<span class='string'>#{txt}</span>"
|
52
|
+
end
|
53
|
+
|
54
|
+
def indent(txt)
|
55
|
+
txt.gsub! "\t", ' '
|
56
|
+
"<span class='indent'>#{txt}</span>"
|
57
|
+
end
|
58
|
+
|
59
|
+
def op(txt)
|
60
|
+
symbol = case txt
|
61
|
+
when '<' then '<'
|
62
|
+
when '>' then '>'
|
63
|
+
when '<=' then '≤'
|
64
|
+
when '>=' then '≥'
|
65
|
+
when '<-' then '←'
|
66
|
+
when '->' then '→'
|
67
|
+
when '<--' then '⟵'
|
68
|
+
when '-->' then '⟶'
|
69
|
+
when '<->' then '↔'
|
70
|
+
when '<-->' then '⟷'
|
71
|
+
when '*' then '×'
|
72
|
+
when '[' then '['
|
73
|
+
when ']' then ']'
|
74
|
+
when '!=' then '≠'
|
75
|
+
when '<>' then '≠'
|
76
|
+
when '=' then '='
|
77
|
+
when ':=' then '≔'
|
78
|
+
when '+' then '+'
|
79
|
+
when '-' then '-'
|
80
|
+
when '/' then '/'
|
81
|
+
when '==' then '='
|
82
|
+
else txt
|
83
|
+
end
|
84
|
+
# FIXME: html conversion for some operators
|
85
|
+
"<span class='operator'>#{symbol}</span>"
|
86
|
+
end
|
87
|
+
|
88
|
+
def math(txt)
|
89
|
+
symbol = case txt
|
90
|
+
when '$pi' then 'π'
|
91
|
+
when '$tau' then '𝛕'
|
92
|
+
else txt
|
93
|
+
end
|
94
|
+
# FIXME: html conversion for some operators
|
95
|
+
"<span class='math-symbol'>#{symbol}</span>"
|
96
|
+
end
|
97
|
+
|
98
|
+
def plain(txt)
|
99
|
+
"#{txt}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'jekyll-pseudocode-b/brush'
|
2
|
+
|
3
|
+
module Jekyll
|
4
|
+
module PseudoCodeB
|
5
|
+
class MockBrush < Brush
|
6
|
+
def sym(txt)
|
7
|
+
"sym(#{txt})"
|
8
|
+
end
|
9
|
+
|
10
|
+
def fn(txt)
|
11
|
+
"fn(#{txt})"
|
12
|
+
end
|
13
|
+
|
14
|
+
def objfn(obj, fnc)
|
15
|
+
"v(#{obj})op(.)fn(#{fnc})"
|
16
|
+
end
|
17
|
+
|
18
|
+
def variable(txt)
|
19
|
+
"v(#{txt})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def number(txt)
|
23
|
+
"num(#{txt})"
|
24
|
+
end
|
25
|
+
|
26
|
+
def var(txt, sub)
|
27
|
+
if sub
|
28
|
+
"#{txt}sub(#{sub.slice(1,sub.size)})"
|
29
|
+
else
|
30
|
+
txt
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def comment(txt)
|
35
|
+
"c(#{txt})"
|
36
|
+
end
|
37
|
+
|
38
|
+
def op(txt)
|
39
|
+
"op(#{txt})"
|
40
|
+
end
|
41
|
+
|
42
|
+
def string(txt)
|
43
|
+
"str(#{txt})"
|
44
|
+
end
|
45
|
+
|
46
|
+
def indent(txt)
|
47
|
+
"i(#{txt})"
|
48
|
+
end
|
49
|
+
|
50
|
+
def math(txt)
|
51
|
+
"math(#{txt})"
|
52
|
+
end
|
53
|
+
|
54
|
+
def plain(txt)
|
55
|
+
txt
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'liquid'
|
2
|
+
require 'jekyll-pseudocode-b/version'
|
3
|
+
require 'jekyll-pseudocode-b/grammar'
|
4
|
+
require 'jekyll-pseudocode-b/html_brush'
|
5
|
+
|
6
|
+
|
7
|
+
class String
|
8
|
+
|
9
|
+
def remove_lines(i)
|
10
|
+
split("\n")[i..-1].join("\n")
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
module Jekyll
|
16
|
+
class PseudoCodeBlockB < Liquid::Block
|
17
|
+
def initialize(tag_name, text, tokens)
|
18
|
+
super
|
19
|
+
@brush = PseudoCodeB::HtmlBrush.new
|
20
|
+
@grammar = PseudoCodeB::Grammar.new
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
def render(context)
|
26
|
+
@text = super
|
27
|
+
|
28
|
+
# for some reason is adding a line to initial code
|
29
|
+
# let's removes
|
30
|
+
@text = @text.remove_lines(1)
|
31
|
+
|
32
|
+
@formatted = @grammar.format(@text, @brush)
|
33
|
+
|
34
|
+
"<div class='pseudocode'>#{@formatted}</div>"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
Liquid::Template.register_tag('pseudocode', Jekyll::PseudoCodeBlockB)
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../lib/jekyll-pseudocode-b.rb'
|
2
|
+
require_relative '../lib/jekyll-pseudocode-b/mock_brush.rb'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Jekyll::PseudoCodeB
|
6
|
+
|
7
|
+
describe Grammar do
|
8
|
+
def format(txt)
|
9
|
+
g = Grammar.new
|
10
|
+
g.format(txt, MockBrush.new)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#format" do
|
14
|
+
it "ignores plain text" do
|
15
|
+
format("plain text").should eql "plain text"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "formats symbols" do
|
19
|
+
format("For").should eql "sym(For)"
|
20
|
+
format("For this").should eql "sym(For) this"
|
21
|
+
format("If Then").should eql "sym(If) sym(Then)"
|
22
|
+
format("If Then that").should eql ("sym(If) sym(Then) that")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "formats number" do
|
26
|
+
format("1234").should eql "num(1234)"
|
27
|
+
format("1234.1234").should eql "num(1234.1234)"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "formats comments" do
|
31
|
+
format("oh #hi\n there").should eql "oh c(hi)\ni( )there"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "formats operators" do
|
35
|
+
format("For a < b").should eql("sym(For) a op(<) b")
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'formats strings' do
|
39
|
+
format('oh "what" a world!').should eql 'oh str("what") a world!'
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'formats variables' do
|
43
|
+
format('x_0').should eql ('xsub(0)')
|
44
|
+
format('x_i').should eql ('xsub(i)')
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'formats functions' do
|
48
|
+
format('fn(b,c)').should eql('fn(fn)op(()b,cop())')
|
49
|
+
format('fn[b,c]').should eql('fn(fn)op([)b,cop(])')
|
50
|
+
format('fn{b,c}').should eql('fn(fn)op({)b,cop(})')
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'formats objects functions' do
|
54
|
+
format('obj.fn(b,c)').should eql('v(obj)op(.)fn(fn)op(()b,cop())')
|
55
|
+
format('obj.fn[b,c]').should eql('v(obj)op(.)fn(fn)op([)b,cop(])')
|
56
|
+
format('obj.fn{b,c}').should eql('v(obj)op(.)fn(fn)op({)b,cop(})')
|
57
|
+
format('ObjCapital.fn{b,c}').should eql('v(ObjCapital)op(.)fn(fn)op({)b,cop(})')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'strips leading whitespace' do
|
61
|
+
format("\thi\n\tthere").should eql("hi\nthere")
|
62
|
+
format("\thi\n\t\tthere").should eql("hi\ni(\t)there")
|
63
|
+
format("\t\thi\n\tthere").should eql("i(\t)hi\nthere")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/spec/html_spec.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require_relative '../lib/jekyll-pseudocode-b.rb'
|
2
|
+
require_relative '../lib/jekyll-pseudocode-b/mock_brush.rb'
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
include Jekyll::PseudoCodeB
|
6
|
+
|
7
|
+
describe HtmlBrush do
|
8
|
+
def format(txt)
|
9
|
+
g = Grammar.new
|
10
|
+
g.format(txt, HtmlBrush.new)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#format" do
|
14
|
+
it "symbol span" do
|
15
|
+
format("For").should eql "<span class='symbol'>For</span>"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "fn span" do
|
19
|
+
format("fn()").should eql "<span class='function'>fn</span><span class='operator'>(</span><span class='operator'>)</span>"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "obj fn span" do
|
23
|
+
format("obj.fn()").should eql "<span class='variable'>obj</span><span class='operator'>.</span><span class='function'>fn</span><span class='operator'>(</span><span class='operator'>)</span>"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "numeric span" do
|
27
|
+
format("1234").should eql "<span class='numeric'>1234</span>"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "comment span" do
|
31
|
+
format("# hi!").should eql "<span class='comment'>/* hi! */</span>"
|
32
|
+
end
|
33
|
+
|
34
|
+
it "variable span" do
|
35
|
+
format("a_b").should eql "<span class='variable'>a<sub>b</sub></span>"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "operator converstions" do
|
39
|
+
format("<").should eql "<span class='operator'><</span>"
|
40
|
+
format("*").should eql "<span class='operator'>×</span>"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-pseudocode-b
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Ulrich
|
8
|
+
- Victor Bazterra
|
9
|
+
- Wiktor Macura
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2018-02-24 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: jekyll
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '3.0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.16'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.16'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rspec
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '3.5'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '3.5'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rake
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '12'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '12'
|
71
|
+
description: jekyll-pseudocode helps typeset pseudocode with minimal formatting
|
72
|
+
email:
|
73
|
+
- tobiasbulrich@gmail.com
|
74
|
+
- bazterra@gmail.com
|
75
|
+
- wmacura@gmail.com
|
76
|
+
executables: []
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- ".ruby-version"
|
82
|
+
- Gemfile
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- doc/output-sample.png
|
86
|
+
- doc/samplecode.png
|
87
|
+
- jekyll-pseudocode-b.gemspec
|
88
|
+
- lib/jekyll-pseudocode-b.rb
|
89
|
+
- lib/jekyll-pseudocode-b/brush.rb
|
90
|
+
- lib/jekyll-pseudocode-b/grammar.rb
|
91
|
+
- lib/jekyll-pseudocode-b/html_brush.rb
|
92
|
+
- lib/jekyll-pseudocode-b/mock_brush.rb
|
93
|
+
- lib/jekyll-pseudocode-b/version.rb
|
94
|
+
- spec/grammar_spec.rb
|
95
|
+
- spec/html_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
homepage: http://github.com/wkm/jekyll-pseudo
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata: {}
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.14
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: A trivial jekyll plugin for formatting pseudocode
|
121
|
+
test_files: []
|