jekyll-ultraviolet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,4 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.name = "jekyll-ultraviolet"
14
14
  gem.require_paths = ["lib"]
15
15
  gem.version = Jekyll::Ultraviolet::VERSION
16
+
17
+ gem.add_dependency "liquid"
18
+ gem.add_dependency "spox-ultraviolet"
19
+ gem.add_development_dependency "rspec", "~> 2.6.0"
16
20
  end
@@ -1,30 +1,40 @@
1
- require 'uv'
1
+ require "uv"
2
+ require "liquid"
3
+ # Psych can't parse some of the syntax/theme files
4
+ YAML::ENGINE.yamler = "syck"
2
5
 
3
6
  module Jekyll
4
7
  module Ultraviolet
5
- class << self; attr_accessor :theme; end
6
-
7
- def self.initialize
8
- @theme = "twilight"
9
- end
10
-
8
+ class << self; attr_accessor :theme end
9
+
11
10
  class Block < Liquid::Block
12
11
  include Liquid::StandardFilters
13
-
12
+
14
13
  def initialize(tag, lang, tokens)
15
14
  super
16
- @lang = (lang.strip unless lang.empty?) || "ruby"
15
+ @theme = "twilight"
16
+ @lang = lang.strip rescue "ruby"
17
17
  end
18
-
18
+
19
19
  def render(context)
20
20
  output = []
21
21
  output << context["pygments_prefix"]
22
- output << Uv.parse(super.join, "xhtml", @lang, false, Ultraviolet.theme)
22
+ output << Uv.parse(remove_leading_spaces(super.join), "xhtml", @lang, false, theme)
23
23
  output << context["pygments_suffix"]
24
24
  output.join
25
25
  rescue LoadError
26
26
  raise "Ultraviolet not installed."
27
27
  end
28
+
29
+ def remove_leading_spaces(text)
30
+ padding = text.match(/\n?(\s+)/)[1]
31
+ return text if padding == "\n"
32
+ text.each_line.map { |l| l.gsub(/^#{padding}/, "") }.join
33
+ end
34
+
35
+ def theme
36
+ Jekyll::Ultraviolet.theme || @theme
37
+ end
28
38
  end
29
39
  end
30
40
  end
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module Ultraviolet
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,2 @@
1
+ require File.dirname(__FILE__) + "/../lib/jekyll/ultraviolet"
2
+ require File.dirname(__FILE__) + "/support/highlighting"
@@ -0,0 +1,43 @@
1
+ module HighlighedTextHelpers
2
+ def text
3
+ <<-TEXT
4
+ This is a code example:
5
+ {% uv ruby %}
6
+ def awesome
7
+ puts "AWESOME"
8
+ end
9
+ {% enduv %}
10
+ And other stuff.
11
+ TEXT
12
+ end
13
+
14
+ def expected
15
+ <<-TEXT
16
+ This is a code example:
17
+ <pre class="twilight">
18
+ <span class="Keyword">def</span> <span class="Entity">awesome</span>
19
+ puts <span class="String"><span class="String">&quot;</span>AWESOME<span class="String">&quot;</span></span>
20
+ <span class="Keyword">end</span>
21
+ </pre>
22
+ And other stuff.
23
+ TEXT
24
+ end
25
+
26
+ def text_python
27
+ <<-TEXT
28
+ This is Python:
29
+ {% uv python %}
30
+ len(0)
31
+ {% enduv %}
32
+ TEXT
33
+ end
34
+
35
+ def expected_python
36
+ <<-TEXT
37
+ This is Python:
38
+ <pre class="twilight">
39
+ <span class="SupportFunction">len</span>(<span class="Constant">0</span>)
40
+ </pre>
41
+ TEXT
42
+ end
43
+ end
@@ -0,0 +1,30 @@
1
+ require "spec_helper"
2
+
3
+ describe Jekyll::Ultraviolet do
4
+ include HighlighedTextHelpers
5
+
6
+ before do
7
+ Jekyll::Ultraviolet.theme = nil
8
+ end
9
+
10
+ def rendered(source)
11
+ Liquid::Template.parse(source).render
12
+ end
13
+
14
+ it "parses uv blocks into syntax highlighted code" do
15
+ rendered(text).should == expected
16
+ end
17
+
18
+ it "allow indenting within {% uv %} but proportionately remove it in output" do
19
+ rendered(text).split("\n")[2].should =~ /^[^\s]+/
20
+ end
21
+
22
+ it "allows the theme to be set" do
23
+ Jekyll::Ultraviolet.theme = "amy"
24
+ rendered(text).should =~ /<pre class="amy">/
25
+ end
26
+
27
+ it "supports specifying a language" do
28
+ rendered(text_python).should == expected_python
29
+ end
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-ultraviolet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,41 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-20 00:00:00.000000000Z
13
- dependencies: []
12
+ date: 2011-10-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: liquid
16
+ requirement: &70367021988580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70367021988580
25
+ - !ruby/object:Gem::Dependency
26
+ name: spox-ultraviolet
27
+ requirement: &70367021979020 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70367021979020
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70367021978240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70367021978240
14
47
  description: Ultraviolet syntax highlighting in Jekyll
15
48
  email:
16
49
  - me@mattenoble.com
@@ -24,6 +57,9 @@ files:
24
57
  - jekyll-ultraviolet.gemspec
25
58
  - lib/jekyll/ultraviolet.rb
26
59
  - lib/jekyll/ultraviolet/version.rb
60
+ - spec/spec_helper.rb
61
+ - spec/support/highlighting.rb
62
+ - spec/ultraviolet_spec.rb
27
63
  homepage:
28
64
  licenses: []
29
65
  post_install_message:
@@ -44,8 +80,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
80
  version: '0'
45
81
  requirements: []
46
82
  rubyforge_project:
47
- rubygems_version: 1.8.6
83
+ rubygems_version: 1.8.10
48
84
  signing_key:
49
85
  specification_version: 3
50
86
  summary: Ultraviolet syntax highlighting in Jekyll
51
- test_files: []
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/support/highlighting.rb
90
+ - spec/ultraviolet_spec.rb