Don't use a constant for api data

This commit is contained in:
Jonathan Rudenberg 2012-09-17 12:06:20 -04:00
parent 0af6c1af84
commit e5fcd98247

View file

@ -4,7 +4,9 @@ class ApiExampleFilter < Nanoc::Filter
identifier :api_example identifier :api_example
type :text type :text
DATA = YAML.load(File.read('content/docs/api_examples.yaml')) def initialize(*args)
@data = YAML.load(File.read('content/docs/api_examples.yaml'))
end
def run(content, params={}) def run(content, params={})
content.gsub(/\{(\w+) example\}/) { api_example($1) }.gsub(/\{(\w+) var\}/) { api_var($1) } content.gsub(/\{(\w+) example\}/) { api_example($1) }.gsub(/\{(\w+) var\}/) { api_var($1) }
@ -13,10 +15,10 @@ class ApiExampleFilter < Nanoc::Filter
private private
def api_example(id) def api_example(id)
DATA[:examples][id.to_sym] @data[:examples][id.to_sym]
end end
def api_var(id) def api_var(id)
DATA[:variables][id.to_sym] @data[:variables][id.to_sym]
end end
end end