Skip to content

Commit 8185470

Browse files
authored
Merge pull request #5 from DerekStride/caching
Cache converted content to prevent slow livereload
2 parents 3fdbc29 + 2677c4c commit 8185470

File tree

5 files changed

+12
-94
lines changed

5 files changed

+12
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/pkg/
77
/spec/reports/
88
/tmp/
9+
Gemfile.lock

Gemfile.lock

Lines changed: 0 additions & 92 deletions
This file was deleted.

lib/jekyll-graphviz/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
module Jekyll
44
module Graphviz
5-
VERSION = "0.1.3"
5+
VERSION = "0.1.4"
66
end
77
end

lib/jekyll/converters/graphviz.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ class Graphviz < Converter
66
safe true
77
priority :low
88

9+
attr_accessor :cache
10+
911
def setup
1012
require 'ruby-graphviz'
1113
@format = (@config.dig("graphviz", "format") || :svg).to_sym
14+
@cache = {}
1215
@setup = true
1316
end
1417

@@ -23,7 +26,7 @@ def output_ext(ext)
2326

2427
def convert(content)
2528
setup unless @setup
26-
GraphViz.parse_string(content).output(@format => String)
29+
@cache[content] ||= GraphViz.parse_string(content).output(@format => String)
2730
end
2831
end
2932
end

test/jekyll/graphviz_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ def test_output_to_another_output_type
3131
assert_equal(Encoding::ASCII_8BIT, output.encoding)
3232
end
3333

34+
def test_files_are_cached
35+
content = "digraph x { a -> b }"
36+
converter.convert(content)
37+
assert(converter.cache.key?(content))
38+
end
39+
3440
def converter(opts = {})
3541
config = Jekyll::Configuration::DEFAULTS.merge(opts)
3642
@converter ||= Jekyll::Converters::Graphviz.new(config)

0 commit comments

Comments
 (0)