Something went wrong. Try again.
A TextMate Bundle for Forester
Something went wrong. Try again.
2.9 kB · 108 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict> <key>beforeRunningCommand</key> <string>saveActiveFile</string> <key>command</key> <string>#!/usr/bin/env rubyrequire 'pathname'require 'cgi'
def find_forest_root(path) return nil if path.nil? current = Pathname.new(path).parent while current.to_s != "/" return current if (current + "forest.toml").exist? current = current.parent end nilend
file = ENV['TM_FILEPATH']root = find_forest_root(file)
unless root puts "<p>No forest.toml found in ancestor directories.</p>" exit 1end
Dir.chdir(root) do output = `forester build 2>&1`
puts "<style> body { font-family: monospace; padding: 1em; } .error { color: #cc0000; font-weight: bold; } .warning { color: #cc7700; font-weight: bold; } .file a { color: #0066cc; } pre { margin: 0; } .block { margin-bottom: 1em; } </style>"
current_level = nil current_file = nil current_line = nil block_lines = []
flush = lambda do unless block_lines.empty? css_class = current_level == 'error' ? 'error' : 'warning' puts "<div class='block'>" block_lines.each_with_index do |l, i| if i == 0 puts "<span class='#{css_class}'>#{CGI.escapeHTML(l)}</span>" elsif current_file && current_line && i == 1 url = "txmt://open?url=file://#{CGI.escapeHTML(current_file)}&line=#{current_line}" puts "<span class='file'><a href='#{url}'>#{CGI.escapeHTML(l)}</a></span>" else puts "<pre>#{CGI.escapeHTML(l)}</pre>" end end puts "</div>" block_lines = [] current_level = nil current_file = nil current_line = nil end end
output.each_line do |line| line = line.rstrip if line =~ /→\s*(error|warning)/ flush.call current_level = $1 block_lines << line elsif line =~ /■\s*(.+)/ current_file = $1.strip block_lines << line elsif line =~ /^\s*(\d+)\s*\|/ current_line = $1 block_lines << line elsif line.strip.empty? && !block_lines.empty? flush.call else block_lines << line end end flush.callend</string> <key>input</key> <string>document</string> <key>inputFormat</key> <string>text</string> <key>keyEquivalent</key> <string>@b</string> <key>name</key> <string>Build</string> <key>outputCaret</key> <string>afterOutput</string> <key>outputFormat</key> <string>html</string> <key>outputLocation</key> <string>newWindow</string> <key>uuid</key> <string>19FA73A2-C2FA-4A59-9AE2-E1A347D7B8D6</string> <key>version</key> <integer>2</integer></dict></plist>