jekyll-pseudo 0.1.4 → 0.1.6

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.
@@ -12,7 +12,7 @@ module Jekyll
12
12
  end
13
13
 
14
14
  # format a variable
15
- def var(txt)
15
+ def var(txt, sub)
16
16
  raise 'not implemented'
17
17
  end
18
18
 
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Pseudo
3
3
  class Grammar
4
- # format a block of text, giving html as output
4
+ # parse a block of text, using the given brush to format output (works in a single pass)
5
5
  def format(txt, brush)
6
6
  results = []
7
7
 
@@ -10,14 +10,28 @@ module Jekyll
10
10
  [/\b([A-Z]\w+)/, :sym],
11
11
  [/(\w+)(?=[({\[])/, :fn],
12
12
  [/(\".*?\")/, :string],
13
- [/(<-|->|\+\+|<=|>=|--)/, :op], # try these operations first
13
+ [/(<-|->|\+\+|<=|>=|--)/, :op], # try these operators first
14
14
  [/([-()\[\]{}=<>+*])/, :op], # and these second
15
+ [/\b([a-z][a-zA-Z0-9]*)(_[a-zA-Z0-9]+)?/, :var],
15
16
  [/^(\s+)/, :indent]
16
17
  ]
17
-
18
- txt.strip!
19
18
 
20
- # lazy man's parser (we don't do that backtracking business)
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)
21
35
  cursor = 0
22
36
  while true
23
37
  matches = mappings.map do |pair|
@@ -36,10 +50,10 @@ module Jekyll
36
50
  if upto[0] != nil
37
51
  results << brush.plain(txt.slice(cursor, upto[0].begin(0)-cursor))
38
52
 
39
- match = upto[0][1]
40
53
  # which match?
41
- results << brush.method(upto[1]).call(match)
42
- cursor = upto[0].end(1)
54
+ captures = upto[0].captures
55
+ results << brush.method(upto[1]).call(*captures)
56
+ cursor = upto[0].end(0)
43
57
  else
44
58
  # no matches remaining
45
59
  results << brush.plain(txt.slice(cursor, txt.size))
@@ -47,8 +61,6 @@ module Jekyll
47
61
  end
48
62
  end
49
63
 
50
- # puts "FINAL: #{results.inspect}"
51
- # puts " = #{results.join('').inspect}"
52
64
  return results.join('')
53
65
  end
54
66
  end
@@ -11,8 +11,12 @@ module Jekyll
11
11
  "<span class='function'>#{txt}</span>"
12
12
  end
13
13
 
14
- def var(txt)
15
- "<span class='variable'>#{var}</span>"
14
+ def var(txt, sub)
15
+ if sub
16
+ "#{txt}<sub>#{sub.slice(1,sub.size)}</sub>"
17
+ else
18
+ "#{txt}"
19
+ end
16
20
  end
17
21
 
18
22
  def comment(txt)
@@ -37,6 +41,8 @@ module Jekyll
37
41
  when '<-' then '&larr;'
38
42
  when '->' then '&rarr;'
39
43
  when '*' then '&times;'
44
+ when '[' then '&#65339;'
45
+ when ']' then '&#65341;'
40
46
  else txt
41
47
  end
42
48
  # FIXME: html conversion for some operators
@@ -11,8 +11,12 @@ module Jekyll
11
11
  "fn(#{txt})"
12
12
  end
13
13
 
14
- def var(txt)
15
- "var(#{var})"
14
+ def var(txt, sub)
15
+ if sub
16
+ "#{txt}sub(#{sub.slice(1,sub.size)})"
17
+ else
18
+ txt
19
+ end
16
20
  end
17
21
 
18
22
  def comment(txt)
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Pseudo
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
data/spec/grammar_spec.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require_relative '../lib/jekyll-pseudo.rb'
2
2
  require_relative '../lib/jekyll-pseudo/mock_brush.rb'
3
- # require 'spec_helper'
4
3
 
5
4
  include Jekyll::Pseudo
6
5
 
@@ -34,10 +33,21 @@ describe Grammar do
34
33
  format('oh "what" a world!').should eql 'oh str("what") a world!'
35
34
  end
36
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
+
37
41
  it 'formats functions' do
38
42
  format('fn(b,c)').should eql('fn(fn)op(()b,cop())')
39
43
  format('fn[b,c]').should eql('fn(fn)op([)b,cop(])')
40
44
  format('fn{b,c}').should eql('fn(fn)op({)b,cop(})')
41
45
  end
46
+
47
+ it 'strips leading whitespace' do
48
+ format("\thi\n\tthere").should eql("hi\nthere")
49
+ format("\thi\n\t\tthere").should eql("hi\ni(\t)there")
50
+ format("\t\thi\n\tthere").should eql("i(\t)hi\nthere")
51
+ end
42
52
  end
43
53
  end
data/spec/html_spec.rb CHANGED
@@ -23,6 +23,10 @@ describe HtmlBrush do
23
23
  format("# hi!").should eql "<span class='comment'>/* hi! */</span>"
24
24
  end
25
25
 
26
+ it "variable span" do
27
+ format("a_b").should eql "a<sub>b</sub>"
28
+ end
29
+
26
30
  it "operator converstions" do
27
31
  format("<").should eql "<span class='op'>&#12296;</span>"
28
32
  format("*").should eql "<span class='op'>&times;</span>"
metadata CHANGED
@@ -1,36 +1,44 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: jekyll-pseudo
3
- version: !ruby/object:Gem::Version
4
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 6
9
+ version: 0.1.6
5
10
  platform: ruby
6
- authors:
11
+ authors:
7
12
  - Wiktor Macura
8
13
  autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
- date: 2013-06-24 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
16
+
17
+ date: 2013-07-01 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
14
21
  name: jekyll
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
22
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
27
32
  description: jekyll-pseudo helps typeset pseudocode with minimal formatting
28
- email:
33
+ email:
29
34
  - wmacura@gmail.com
30
35
  executables: []
36
+
31
37
  extensions: []
38
+
32
39
  extra_rdoc_files: []
33
- files:
40
+
41
+ files:
34
42
  - .gitignore
35
43
  - .ruby-version
36
44
  - Gemfile
@@ -46,29 +54,36 @@ files:
46
54
  - lib/jekyll-pseudo/version.rb
47
55
  - spec/grammar_spec.rb
48
56
  - spec/html_spec.rb
57
+ has_rdoc: true
49
58
  homepage: http://github.com/wkm/jekyll-pseudo
50
59
  licenses: []
51
- metadata: {}
60
+
52
61
  post_install_message:
53
62
  rdoc_options: []
54
- require_paths:
63
+
64
+ require_paths:
55
65
  - lib
56
- required_ruby_version: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - '>='
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- required_rubygems_version: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - '>='
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ segments:
78
+ - 0
79
+ version: "0"
66
80
  requirements: []
81
+
67
82
  rubyforge_project:
68
- rubygems_version: 2.0.3
83
+ rubygems_version: 1.3.6
69
84
  signing_key:
70
- specification_version: 4
85
+ specification_version: 3
71
86
  summary: A trivial jekyll plugin for formatting pseudocode
72
- test_files:
87
+ test_files:
73
88
  - spec/grammar_spec.rb
74
89
  - spec/html_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 6675c1135d5bedd8f3fc925ba10e589246d04d63
4
- data.tar.gz: 81f4f5f0b5e2dd9c79cc373140cb08a3fffe52d8
5
- SHA512:
6
- metadata.gz: 3042a6d5ec4c71a0ac59162aad2d80eb3430ca85c2183876e1763d939db509de8e563a2c65c377f2d1b1f2f737b92e947660aeb02442a82968aa1d83a65612d7
7
- data.tar.gz: 3db7b240dbc2f0832f0770c51f345912a1d4c0be5e2aeac454162e063c199bc8a2b0754600734442836167c02076f7a6efe742f18569a99176bb6ab337edd28c