module Booky::Textile class Source include Booky::Textile::Precompiler # Does the current line need to be precompiled? def matches line return false unless line.match /^source/ line.gsub("source", "").strip end # Replace the path with the contents of the file def compile_to options begin options = parse(options) @output = "bc{name: #{options[:name]};}.. " @output += File.open("#{File.dirname(Booky.source)}/#{options[:file]}", 'rb') { |f| f.read } @output += "\n\np. \n" @output rescue raise Booky::LoadError.new "#{File.dirname(Booky.source)}/#{options[:name]}" end end # Parses the options for a name and the file def parse options if name_match = options.match(/{(.*?)}/) options = options.gsub(name_match[0], "") name = name_match[1] end file = options[1..-1].strip name = File.basename("#{File.dirname(Booky.source)}/#{file}") unless name { :name => name, :file => file } end end end