#! /usr/bin/env ruby begin require 'plist' rescue LoadError require 'rubygems' require 'plist' end require 'uv/utility' base_dir = File.join( File.dirname(__FILE__), '..', 'render' ) def settings unless @settings @settings = @theme["settings"].find { |s| ! s["name"] }["settings"] end @settings end puts "Processing #{ARGV[0]}" @theme = Plist::parse_xml( ARGV[0] ) render = {"name" => @theme["name"]} css = {} standard_name = File.basename( ARGV[0] ).downcase.gsub(/\s+/, '_').gsub('.tmtheme', '').gsub(/\W/, '').gsub(/_+/, '_') code_name = "pre.#{standard_name}" render["tags"] = [] count_names = {} @theme["settings"].each do |t| if t["scope"] class_name = t["name"].downcase.gsub(/\W/, ' ').gsub('.tmtheme', '').split(' ').collect{|s| s.capitalize}.join if class_name == "" class_name = "x" * t["name"].size end if count_names[class_name] tname = class_name class_name = "#{class_name}#{count_names[class_name]}" count_names[tname] += count_names[tname] + 1 else count_names[class_name] = 1 end tag = {} tag["selector"] = t["scope"] tag["begin"] = "" tag["end"] = "" render["tags"] << tag if s = t["settings"] style = {} style["color"] = Uv.normalize_color(settings, s["foreground"], true) style["background-color"] = Uv.normalize_color(settings, s["background"]) case s["fontStyle"] when /bold/ then style["font-weight"] = "bold" when /italic/ then style["font-style"] = "italic" when /underline/ then style["text-decoration"] = "underline" end css[".#{class_name}"] = style end elsif ! t["name"] if s = t["settings"] style = {} style["color"] = Uv.normalize_color(settings, s["foreground"], true) style["background-color"] = Uv.alpha_blend(s["background"], s["background"]) css[code_name] = style @style = style style = {} style["background-color"] = Uv.alpha_blend(s["selection"], s["selection"]) style["color"] = Uv.foreground( style["background-color"] ) css[".line-numbers"] = style tag = {} tag["begin"] = "" tag["end"] = "" render["line-numbers"] = tag end end end render["filter"] = "CGI.escapeHTML( @escaped )" tag = {} tag["begin"] = "" tag["end"] = "" render["line"] = tag tag = {} tag["begin"] = "
"
tag["end"]   = "
" render["listing"] = tag tag = {} tag["begin"] = < #{standard_name} END tag["end"] = < Valid XHTML 1.0 Strict Valid CSS!

END render["document"] = tag File.open( File.join( base_dir, "xhtml", "#{standard_name}.render" ), "w" ) {|f| YAML.dump( render, f ) } File.open( File.join( base_dir, "xhtml", "files", "css", "#{standard_name}.css" ), "w" ) do |f| css.each do |key, values| if key == code_name f.puts "#{code_name} {" #puts @style else f.puts "#{code_name} #{key} {" end values.each do |style, value| f.puts " #{style}: #{value};" if value end f.puts "}" end end