Better caching for autocompile.
This commit is contained in:
parent
02570b445b
commit
f9a66671f8
12
doc-src/lib/data_sources/nanoc_monkey_patches.rb
Normal file
12
doc-src/lib/data_sources/nanoc_monkey_patches.rb
Normal file
@ -0,0 +1,12 @@
|
||||
class Nanoc3::Site
|
||||
def cached(key)
|
||||
if cache.has_key?(key)
|
||||
cache[key]
|
||||
else
|
||||
cache[key]= yield
|
||||
end
|
||||
end
|
||||
def cache
|
||||
@cache ||= {}
|
||||
end
|
||||
end
|
@ -4,13 +4,12 @@ def stylesheets_dir(framework)
|
||||
Compass::Frameworks[framework].stylesheets_directory
|
||||
end
|
||||
|
||||
def stylesheet_key(item)
|
||||
[item[:framework], item[:stylesheet]].join("/")
|
||||
def tree_key(item)
|
||||
"tree/"+[item[:framework], item[:stylesheet]].join("/")
|
||||
end
|
||||
|
||||
def tree(item)
|
||||
@stylesheets ||= {}
|
||||
@stylesheets[stylesheet_key(item)] ||= begin
|
||||
@site.cached(tree_key(item)) do
|
||||
file = File.join(stylesheets_dir(item[:framework]), item[:stylesheet])
|
||||
contents = File.read(file)
|
||||
Sass::Engine.new(contents).send :to_tree
|
||||
@ -30,6 +29,7 @@ end
|
||||
|
||||
def reference_item(options)
|
||||
stylesheet = options[:stylesheet]
|
||||
@site.cached("reference/item/#{stylesheet}") do
|
||||
path = stylesheet_path(stylesheet)
|
||||
if path
|
||||
@items.detect do |i|
|
||||
@ -38,6 +38,7 @@ def reference_item(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def reference_path(options)
|
||||
if item = reference_item(options)
|
||||
@ -57,6 +58,7 @@ def import_paths
|
||||
end
|
||||
|
||||
def stylesheet_path(ss)
|
||||
@site.cached("stylesheet/path/#{ss}") do
|
||||
possible_filenames_for_stylesheet(ss).each do |filename|
|
||||
import_paths.each do |import_path|
|
||||
full_path = File.join(import_path.first, filename)
|
||||
@ -66,6 +68,7 @@ def stylesheet_path(ss)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def possible_filenames_for_stylesheet(ss)
|
||||
ext = File.extname(ss)
|
||||
@ -132,16 +135,19 @@ def mixin_signature(mixin)
|
||||
end
|
||||
|
||||
def example_items
|
||||
@example_items ||= @items.select{|i| i[:example]}
|
||||
@site.cached("examples") do
|
||||
@items.select{|i| i[:example]}
|
||||
end
|
||||
end
|
||||
|
||||
def examples_for_item(item)
|
||||
@examples ||= {}
|
||||
@examples[item] ||= example_items.select do |i|
|
||||
@site.cached("examples/#{item.identifier}") do
|
||||
example_items.select do |i|
|
||||
i[:framework] == item[:framework] &&
|
||||
i[:stylesheet] == item[:stylesheet]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def examples(item, mixin = nil)
|
||||
examples = examples_for_item(item)
|
||||
|
Loading…
Reference in New Issue
Block a user