octopress-pygments 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWY3YTkyYWNlMjgzMDE0YzFkZjBjY2U0ZGUyMjAwMGUxMDVhYWQ4Zg==
4
+ YTUwM2Q0N2ExNDAwNzE4OGQzYzUzNjQ5ZmRhMWY5MWQ2YzkzZWY4Ng==
5
5
  data.tar.gz: !binary |-
6
- NzIyOGNkMjUxYzQzN2EyNDgzYjhjZDExNTdlODM1OTVhMDg4ZmY0Nw==
6
+ NjcwZjkwMzQ5ZjU1NDAzZjVkN2QxY2ZlZThlNzFlNmVkZmY3YjAwNg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YWE0Yzc2YjQ2ZTVkYzYyMzE0NjE2OWI5NjYwNWZhYmU1MDQ2YTFhOGM2ZjVk
10
- OTZiNmNjODAyZTdkNjNmOTQ1M2JmOTJlMDcwZjM1YmQ4MWNmM2Q1NjZhYjIz
11
- MGFmZmJlZTU1NzRkZWQyNTQ1NGQwMGM1YjAxOTgyNWI4MjJjMDA=
9
+ ODU4NGZiZmVmZTk3ZTA0ZmFlYmFjNTI1NDFiYzY0MzcxY2VhZTU0ZTdiZTVl
10
+ NDU1ODU3YWI2NzBjOWExOGRmYzcxOGEzMTYzOTM4YjljYmVkNDA1NmJkOGU4
11
+ ZGNmMWExMWI1MWNmMDg2OTg3ZjA3NmQ5YjVkMjE5ZDZkN2RhOGQ=
12
12
  data.tar.gz: !binary |-
13
- NGY4OWQxOTUzOTI1ZWQ5MDBjNzcyYTdmYTY1M2M0ODgzMzVhNDUxODNiMGQ0
14
- MjFkNjRiZDA5OThmN2VhNDY2MjcxMzIyNTRkMjZjNmI4MTk2ZjFkOTI4NzYy
15
- OWQwZjA2ZjMwYzY1Y2Q4NjdmMjUwM2JmZWQ2MzQwNWFhNmZmMjc=
13
+ MGY4ODEwMmVhN2EzOWNhNDAyMTZhMDdiZWEwODAwYmM1MTk3NmZiMmYxMjcx
14
+ YTYxNDgzZGYzOTg0NDg1NzI3ODYyMGI1ZTQzZTAzODBkMTM2OTYyMjQ2OWIw
15
+ ZDAxZjU2ZGM5YzIwMDM3NDZmOTc2MjA5YWU2ZTE4N2QzYzMxZDI=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.2
4
+ - Now you can call Pygments.read_cache directly.
5
+ - Added an option to specify a label on cache files.
6
+ - Simplified caching methods.
7
+
3
8
  ## 1.2.1
4
9
  - Fix: No longer overwriting options with `nil` in parse_markup
5
10
 
@@ -17,6 +17,10 @@ module Octopress
17
17
  Renderer.new(code, options).highlight
18
18
  end
19
19
 
20
+ def self.read_cache(code, options={})
21
+ Cache.read_cache(code, options)
22
+ end
23
+
20
24
  def self.parse_markup(input, defaults={})
21
25
  OptionsParser.new(input).parse_markup(defaults)
22
26
  end
@@ -4,25 +4,24 @@ module Octopress
4
4
  PYGMENTS_CACHE_DIR = '.pygments-cache'
5
5
 
6
6
  class << self
7
- def fetch_from_cache(code, options)
8
- path = options[:cache_path] || get_cache_path(PYGMENTS_CACHE_DIR, options[:lang], options.to_s + code)
9
- cache = read_cache(path)
7
+ def read_cache(code, options)
8
+ cache_label = options[:cache_label] || options[:lang] || ''
9
+ path = get_cache_path(PYGMENTS_CACHE_DIR, cache_label, options.to_s + code)
10
+ File.exist?(path) ? File.read(path) : nil unless path.nil?
10
11
  end
11
12
 
12
13
  def write_to_cache(contents, options)
13
14
  FileUtils.mkdir_p(PYGMENTS_CACHE_DIR) unless File.directory?(PYGMENTS_CACHE_DIR)
14
- path = options[:cache_path] || get_cache_path(PYGMENTS_CACHE_DIR, options[:lang], options.to_s + contents)
15
+ cache_label = options[:cache_label] || options[:lang] || ''
16
+ path = get_cache_path(PYGMENTS_CACHE_DIR, cache_label, options.to_s + contents)
15
17
  File.open(path, 'w') do |f|
16
18
  f.print(contents)
17
19
  end
18
20
  end
19
21
 
20
- def read_cache(path)
21
- File.exist?(path) ? File.read(path) : nil unless path.nil?
22
- end
23
-
24
- def get_cache_path(dir, name, str)
25
- File.join(dir, "#{name}-#{Digest::MD5.hexdigest(str)}.html")
22
+ def get_cache_path(dir, label, str)
23
+ label += '-' unless label === ''
24
+ File.join(dir, "#{label}#{Digest::MD5.hexdigest(str)}.html")
26
25
  end
27
26
  end
28
27
  end
@@ -13,8 +13,9 @@ module Octopress
13
13
 
14
14
  def highlight
15
15
  @options[:title] ||= ' ' if @options[:url]
16
- cache = Cache.fetch_from_cache(code, @options)
17
- unless cache
16
+ if cache = Cache.read_cache(code, @options)
17
+ cache
18
+ else
18
19
  if @lang == 'plain'
19
20
  rendered_code = code.to_s.gsub('<','&lt;')
20
21
  else
@@ -24,8 +25,8 @@ module Octopress
24
25
  title = captionize(@options[:title], @options[:url], @options[:link_text]) if @options[:title]
25
26
  rendered_code = "<figure class='code'>#{title}#{rendered_code}</figure>"
26
27
  Cache.write_to_cache(rendered_code, @options) unless @options[:no_cache]
28
+ rendered_code
27
29
  end
28
- cache || rendered_code
29
30
  end
30
31
 
31
32
  def determine_lang(lang)
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Pygments
3
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-pygments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-11 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pygments.rb