jekyll-pseudocode 0.1.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a51b68d46cbd01b77363100383fef7df319bd65c
4
+ data.tar.gz: 0d9a29b14040cb8bc6777b4f0b5abe04839c7b7d
5
+ SHA512:
6
+ metadata.gz: 04e6f11f961ba2f3552d6ad83bd606c114e3eca1cb38a6f3538ab9ffd91884da6302cbcf0dbf4528dfc8b03aa1007b0faa6df7f04786c3843f8cb68966cccd30
7
+ data.tar.gz: 490b282dea171022a112c850253e8aed6d5a3d3eda36a7060f6e30a433597a5330fcc28d6c924cf0fd9e05be4d42fb862042af75c46abcc43b797e417b195335
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
6
+ *.iml
@@ -0,0 +1 @@
1
+ ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in jekyll-pseudocode.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Victor Eduardo Bazterra
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # jekyll-pseudocode
2
+ A pseudocode/algorithm formatter for sites powered by jekyll. This is a fork from wkm/jekyll-pseudo.
3
+
4
+ Sometimes you don't want to use a particular programming language to
5
+ demonstrate a concept because of the syntactic overhead. jekyll-pseudocode lets
6
+ you use a gently styled free-formated representation.
7
+
8
+ ## Language
9
+ * indentation is preserved
10
+ * a word beginning with a capital letter is a keyword
11
+ * a word followed by parentheses is a function name
12
+ * all other words are variables
13
+ * words within double quotes are generally strings
14
+
15
+ * these symbols are auto-formatted: `<-- <= >= --> =`
16
+
17
+
18
+ Sample output:
19
+
20
+ {% pseudo %}
21
+ Function swap(old, new)
22
+ remaining <- quorumSize
23
+ success <- False
24
+ For Each host
25
+ result[host] <- send(host, propose(old, new))
26
+ If result[host] = "ok"
27
+ remaining--
28
+ If remaining > 1+quorumSize/2
29
+ success <- True
30
+ For Each result
31
+ If success
32
+ send(host, confirm(old, new))
33
+ Else
34
+ send(host, cancel(old, new))
35
+ {% endpseudo %}
36
+
37
+ ## Output
38
+ Output is annotated with `<span>` classes and can be styled using CSS. Typically keywords are made bold and variables are italicized.
39
+
40
+ Using the style provided in `lib/jekyll-pseudocode.css` previous markdown should be rendered as:
41
+
42
+ ![Image](https://raw.github.com/baites/jekyll-pseudocode/master/doc/screenshot.png)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
Binary file
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jekyll-pseudocode/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "jekyll-pseudocode"
7
+ s.version = Jekyll::PseudoCode::VERSION
8
+ s.authors = ["Victor Bazterra"," Wiktor Macura"]
9
+ s.email = ["bazterra@gmail.com", "wmacura@gmail.com"]
10
+ s.homepage = "http://github.com/baites/jekyll-pseudocode"
11
+ s.summary = %q{A trivial jekyll plugin for pseudocode fork from jekyll-pseudo}
12
+ s.description = %q{jekyll-pseudocode helps typeset pseudocode with minimal formatting}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ s.add_runtime_dependency "jekyll"
21
+ end
@@ -0,0 +1,23 @@
1
+ ---
2
+ ---
3
+
4
+ @import "{{ site.theme }}";
5
+
6
+ .pseudocode {
7
+ text-indent: 50px;
8
+ font-family: "Courier New", Courier, monospace;
9
+ white-space: pre-wrap;
10
+ }
11
+
12
+ .symbol {
13
+ font-weight: bold;
14
+ text-transform: lowercase;
15
+ }
16
+
17
+ .function {
18
+ text-transform: uppercase;
19
+ }
20
+
21
+ .variable {
22
+ font-style: italic;
23
+ }
@@ -0,0 +1,23 @@
1
+ require 'liquid'
2
+ require 'jekyll-pseudocode/version'
3
+ require 'jekyll-pseudocode/grammar'
4
+ require 'jekyll-pseudocode/html_brush'
5
+
6
+ module Jekyll
7
+ class PseudoCodeBlock < Liquid::Block
8
+ def initialize(tag_name, text, tokens)
9
+ super
10
+ @brush = PseudoCode::HtmlBrush.new
11
+ @grammar = PseudoCode::Grammar.new
12
+ end
13
+
14
+ def render(context)
15
+ @text = super
16
+ @formatted = @grammar.format(@text, @brush)
17
+ "<div class='pseudocode'>#{@formatted}</div>"
18
+ end
19
+ end
20
+ end
21
+
22
+
23
+ Liquid::Template.register_tag('pseudocode', Jekyll::PseudoCodeBlock)
@@ -0,0 +1,40 @@
1
+ module Jekyll
2
+ module PseudoCode
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 variable
15
+ def var(txt, sub)
16
+ raise 'not implemented'
17
+ end
18
+
19
+ # format a comment
20
+ def comment(txt)
21
+ raise 'not implemented'
22
+ end
23
+
24
+ # format an operator
25
+ def op(txt)
26
+ raise 'not implemented'
27
+ end
28
+
29
+ # format a string
30
+ def string(txt)
31
+ raise 'not implemented'
32
+ end
33
+
34
+ # render plain text
35
+ def plain(txt)
36
+ raise 'not implemented'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ module Jekyll
2
+ module PseudoCode
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
+ [/\b([A-Z]\w+)/, :sym],
11
+ [/(\w+)(?=[(])/, :fn],
12
+ [/(\".*?\")/, :string],
13
+ [/(<-|->|\+\+|<=|>=|--)/, :op], # try these operators first
14
+ [/([-()\[\]{}=<>+*])/, :op], # and these second
15
+ [/\b([a-z][a-zA-Z0-9]*)(_[a-zA-Z0-9]+)?/, :var],
16
+ [/^(\s+)/, :indent]
17
+ ]
18
+
19
+ # replace tabs with three spaces
20
+ txt.gsub! /^\t/, ' '
21
+
22
+ # count leading whitespace
23
+ ws = txt.scan(/^ */).map do |leading|
24
+ leading.size
25
+ end
26
+ leading = (ws.min or 0)
27
+
28
+ # remove leading whitespace of the given length
29
+ if leading > 0
30
+ r = /^ {#{leading}}/
31
+ txt.gsub! r, ''
32
+ end
33
+
34
+ # lazy man's parser (we don't do any of that silly backtracking)
35
+ cursor = 0
36
+ while true
37
+ matches = mappings.map do |pair|
38
+ [pair[0].match(txt, cursor), pair[1]]
39
+ end
40
+
41
+ upto = matches.min_by do |pair|
42
+ matchdata = pair[0]
43
+ if matchdata == nil
44
+ txt.size
45
+ else
46
+ matchdata.begin(0)
47
+ end
48
+ end
49
+
50
+ if upto[0] != nil
51
+ results << brush.plain(txt.slice(cursor, upto[0].begin(0)-cursor))
52
+
53
+ # which match?
54
+ captures = upto[0].captures
55
+ results << brush.method(upto[1]).call(*captures)
56
+ cursor = upto[0].end(0)
57
+ else
58
+ # no matches remaining
59
+ results << brush.plain(txt.slice(cursor, txt.size))
60
+ break
61
+ end
62
+ end
63
+
64
+ return results.join('')
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,57 @@
1
+ require 'jekyll-pseudocode/brush'
2
+
3
+ module Jekyll
4
+ module PseudoCode
5
+ class HtmlBrush < Jekyll::PseudoCode::Brush
6
+ def sym(txt)
7
+ "<span class='symbol'>#{txt}</span>"
8
+ end
9
+
10
+ def fn(txt)
11
+ "<span class='function'>#{txt}</span>"
12
+ end
13
+
14
+ def var(txt, sub)
15
+ if sub
16
+ "<span class='variable'>#{txt}<sub>#{sub.slice(1,sub.size)}</sub></span>"
17
+ else
18
+ "<span class='variable'>#{txt}</span>"
19
+ end
20
+ end
21
+
22
+ def comment(txt)
23
+ "<span class='comment'>/* #{txt.strip} */</span>"
24
+ end
25
+
26
+ def string(txt)
27
+ "<span class='string'>#{txt}</span>"
28
+ end
29
+
30
+ def indent(txt)
31
+ txt.gsub! "\t", ' '
32
+ "<span class='indent'>#{txt}</span>"
33
+ end
34
+
35
+ def op(txt)
36
+ symbol = case txt
37
+ when '<' then '&#12296;'
38
+ when '>' then '&#12297;'
39
+ when '<=' then '&le;'
40
+ when '>=' then '&ge;'
41
+ when '<-' then '&larr;'
42
+ when '->' then '&rarr;'
43
+ when '*' then '&times;'
44
+ when '[' then '&#65339;'
45
+ when ']' then '&#65341;'
46
+ else txt
47
+ end
48
+ # FIXME: html conversion for some operators
49
+ "<span class='op'>#{symbol}</span>"
50
+ end
51
+
52
+ def plain(txt)
53
+ "#{txt}"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,43 @@
1
+ require 'jekyll-pseudocode/brush'
2
+
3
+ module Jekyll
4
+ module PseudoCode
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 var(txt, sub)
15
+ if sub
16
+ "#{txt}sub(#{sub.slice(1,sub.size)})"
17
+ else
18
+ txt
19
+ end
20
+ end
21
+
22
+ def comment(txt)
23
+ "c(#{txt})"
24
+ end
25
+
26
+ def op(txt)
27
+ "op(#{txt})"
28
+ end
29
+
30
+ def string(txt)
31
+ "str(#{txt})"
32
+ end
33
+
34
+ def indent(txt)
35
+ "i(#{txt})"
36
+ end
37
+
38
+ def plain(txt)
39
+ txt
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Jekyll
2
+ module PseudoCode
3
+ VERSION = "0.1.3"
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ require_relative '../lib/jekyll-pseudocode.rb'
2
+ require_relative '../lib/jekyll-pseudocode/mock_brush.rb'
3
+
4
+ include Jekyll::PseudoCode
5
+
6
+ describe Grammar do
7
+ def format(txt)
8
+ g = Grammar.new
9
+ g.format(txt, MockBrush.new)
10
+ end
11
+
12
+ describe "#format" do
13
+ it "ignores plain text" do
14
+ format("plain text").should eql "plain text"
15
+ end
16
+
17
+ it "formats symbols" do
18
+ format("For").should eql "sym(For)"
19
+ format("For this").should eql "sym(For) this"
20
+ format("If Then").should eql "sym(If) sym(Then)"
21
+ format("If Then that").should eql ("sym(If) sym(Then) that")
22
+ end
23
+
24
+ it "formats comments" do
25
+ format("oh #hi\n there").should eql "oh c(hi)\ni( )there"
26
+ end
27
+
28
+ it "formats operators" do
29
+ format("For a < b").should eql("sym(For) a op(<) b")
30
+ end
31
+
32
+ it 'formats strings' do
33
+ format('oh "what" a world!').should eql 'oh str("what") a world!'
34
+ end
35
+
36
+ it 'formats variables' do
37
+ format('x_0').should eql ('xsub(0)')
38
+ format('x_i').should eql ('xsub(i)')
39
+ end
40
+
41
+ it 'formats functions' do
42
+ format('fn(b,c)').should eql('fn(fn)op(()b,cop())')
43
+ end
44
+
45
+ it 'strips leading whitespace' do
46
+ format("\thi\n\tthere").should eql("hi\nthere")
47
+ format("\thi\n\t\tthere").should eql("hi\ni(\t)there")
48
+ format("\t\thi\n\tthere").should eql("i(\t)hi\nthere")
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../lib/jekyll-pseudocode.rb'
2
+ require_relative '../lib/jekyll-pseudocode/mock_brush.rb'
3
+ # require 'spec_helper'
4
+
5
+ include Jekyll::PseudoCode
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='op'>(</span><span class='op'>)</span>"
20
+ end
21
+
22
+ it "comment span" do
23
+ format("# hi!").should eql "<span class='comment'>/* hi! */</span>"
24
+ end
25
+
26
+ it "variable span" do
27
+ format("a_b").should eql "<span class='variable'>a<sub>b</sub></span>"
28
+ end
29
+
30
+ it "operator converstions" do
31
+ format("<").should eql "<span class='op'>&#12296;</span>"
32
+ format("*").should eql "<span class='op'>&times;</span>"
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-pseudocode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Victor Bazterra
8
+ - " Wiktor Macura"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-09-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jekyll
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description: jekyll-pseudocode helps typeset pseudocode with minimal formatting
29
+ email:
30
+ - bazterra@gmail.com
31
+ - wmacura@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - ".ruby-version"
38
+ - Gemfile
39
+ - LICENSE
40
+ - README.md
41
+ - Rakefile
42
+ - doc/screenshot.png
43
+ - jekyll-pseudocode.gemspec
44
+ - lib/jekyll-pseudocode.css
45
+ - lib/jekyll-pseudocode.rb
46
+ - lib/jekyll-pseudocode/brush.rb
47
+ - lib/jekyll-pseudocode/grammar.rb
48
+ - lib/jekyll-pseudocode/html_brush.rb
49
+ - lib/jekyll-pseudocode/mock_brush.rb
50
+ - lib/jekyll-pseudocode/version.rb
51
+ - spec/grammar_spec.rb
52
+ - spec/html_spec.rb
53
+ homepage: http://github.com/baites/jekyll-pseudocode
54
+ licenses: []
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.6.11
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A trivial jekyll plugin for pseudocode fork from jekyll-pseudo
76
+ test_files:
77
+ - spec/grammar_spec.rb
78
+ - spec/html_spec.rb