p2h.rb
で、まだめんどくさいからせめて、とこんなのも書く。
#write SS. # #Format #------------------------------------------------------------ #=begin #SS Info Header(omittable with =begin - =end lines) as YAML #=end # #SS body as SSML # #------------------------------------------------------------ require 'erb' require 'stringio' require 'yaml' module P2H class ValueHolder def initialize @sets = {} @read_stream = ARGF end attr_accessor :read_stream def load_values(yaml_src) loaded = YAML.load(yaml_src) if loaded loaded.kind_of?(Hash) or raise ArgumentError end @sets = loaded || {} end def context instance_eval{ binding() } end def title_content @sets[:title] || 'Untitled' end def css_uri_list @sets[:css] || [] end def body_content @read_stream.read end end end text = StringIO.new head = StringIO.new now = text ARGF.each do |line| case line when /\A=begin\Z/ now = head when /\A=end\Z/ now = text else now.print line end end text.rewind holder = P2H::ValueHolder.new holder.read_stream = text holder.load_values(head.string) ERB.new(DATA.read).run(holder.context) __END__ <?xml version="1.0" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title><%= title_content() %></title> <%= css_uri_list().map{|css| %Q|<link href="#{css}" type="text/css" rel="stylesheet" />\n| }.join %></head> <body> <%= body_content() %> </body> </html>
ss2h.bat
で、こんなんで使う。
@echo off ssml %1 %2 %3 %4 %5 %6 %7 %8 %9 | ruby p2h.rb @echo on