Class: Octopress::CodeHighlighter::Cache
- Inherits:
-
Object
- Object
- Octopress::CodeHighlighter::Cache
- Defined in:
- lib/octopress-code-highlighter/cache.rb
Constant Summary collapse
- CODE_CACHE_DIR =
'.code-style-cache'
Class Method Summary collapse
- .get_cache_path(dir, label, str) ⇒ Object
- .read_cache(code, options) ⇒ Object
- .write_to_cache(contents, options) ⇒ Object
Class Method Details
.get_cache_path(dir, label, str) ⇒ Object
22 23 24 25 |
# File 'lib/octopress-code-highlighter/cache.rb', line 22 def get_cache_path(dir, label, str) label += '-' unless label === '' File.join(dir, "#{label}#{Digest::MD5.hexdigest(str)}.html") end |
.read_cache(code, options) ⇒ Object
7 8 9 10 11 |
# File 'lib/octopress-code-highlighter/cache.rb', line 7 def read_cache(code, ) cache_label = [:cache_label] || [:lang] || '' path = get_cache_path(CODE_CACHE_DIR, cache_label, .to_s + code) File.exist?(path) ? File.read(path) : nil unless path.nil? end |
.write_to_cache(contents, options) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/octopress-code-highlighter/cache.rb', line 13 def write_to_cache(contents, ) FileUtils.mkdir_p(CODE_CACHE_DIR) unless File.directory?(CODE_CACHE_DIR) cache_label = [:cache_label] || [:lang] || '' path = get_cache_path(CODE_CACHE_DIR, cache_label, .to_s + contents) File.open(path, 'w') do |f| f.print(contents) end end |