module TPS::TaskPaperShim
Converts a TaskPaper
document to the internal format (as represented by YAML).
hash = TaskPaperShim.load('file.taskpaper') hash = TaskPaperShim.parse("Version 1:\n\t- Login")
Constants
- SETTINGS
Public Instance Methods
is_setting?(node)
click to toggle source
Checks if a given node is a settings node
# File lib/tps/taskpaper_shim.rb, line 56 def is_setting?(node) if node.note? SETTINGS.any? { |tag| node.text =~ /^#{tag}:/ } end end
load(file)
click to toggle source
# File lib/tps/taskpaper_shim.rb, line 62 def load(file) data = File.read(file) parse data end
parse(source)
click to toggle source
# File lib/tps/taskpaper_shim.rb, line 12 def parse(source) node = TPS::TaskPaper.parse(source) hash = work(node) hash end
work(node)
click to toggle source
# File lib/tps/taskpaper_shim.rb, line 19 def work(node) return nil if node.tags.empty? && node.children.empty? hash = {} # Load tags tags = node.tags.map { |s| s.gsub(/^@/, '').gsub(/_/, ' ').gsub(/\(.*?\)$/, '') } if tags.any? if node.children.any? hash['_'] = tags else return tags end end # Load children node.children.each do |child| text = child.text # For "Trello URL: xxx" settings if is_setting?(child) child.text =~ /^(.*?): (.*)$/ hash[$1] = $2 # For "s1: Sprint 1" notes elsif node.text == "Sprints" text.match(/^(.*?): (.*)$/) && hash[$1] = $2 # For everything else elsif !child.note? hash[text] = work(child) end end hash end