lib/trackler/track.rb in trackler-2.0.3.9 vs lib/trackler/track.rb in trackler-2.0.4.0

- old
+ new

@@ -6,10 +6,11 @@ module Trackler # Track is a collection of exercises in a given language. class Track TOPICS = %w(about installation tests learning resources) + DEFAULT_IMAGE_PATH = "/docs/img" Image = Struct.new(:path) do def exists? File.exist?(path) end @@ -78,12 +79,12 @@ else /test/i end end - def docs - OpenStruct.new( Hash[TOPICS.zip(TOPICS.map { |topic| document_contents(topic) })] ) + def docs(image_path = DEFAULT_IMAGE_PATH) + OpenStruct.new(docs_by_topic(image_path)) end def img(file_path) Image.new(File.join(dir, file_path)) end @@ -155,9 +156,19 @@ when /\.org$/ Orgmode::Parser.new(File.read(filename)).to_markdown else '' end + end + + def docs_by_topic(image_path) + Hash[ + TOPICS.zip( + TOPICS.map { |topic| + document_contents(topic).gsub(DEFAULT_IMAGE_PATH, image_path.gsub(Regexp.new("/$"), "")) + } + ) + ] end def document_filename(topic) path = File.join(dir, "docs", topic.upcase) Dir.glob("%s.*" % path).sort.first