Skip to content

Instantly share code, notes, and snippets.

@aisuii
Created July 6, 2011 03:09
Show Gist options
  • Save aisuii/1066478 to your computer and use it in GitHub Desktop.
Save aisuii/1066478 to your computer and use it in GitHub Desktop.
require 'ripper'
require 'cgi'
class Ruby2HTML < Ripper::Filter
def on_default(event, tok, f)
f << CGI.escapeHTML(tok)
end
private
def respond_to?(name, priv = false)
!!event_pattern_matching(name) or super
end
def method_missing(name, *args)
if event = event_pattern_matching(name)
tok, f = args
f << %Q[<span class="#{event}">#{CGI.escapeHTML(tok)}</span>]
else
super
end
end
def event_pattern_matching(on_name)
on_name.to_s =~ /^on_(.+)$/ and Ripper::SCANNER_EVENTS.include? $1.to_sym and $1
end
end
if $0 == __FILE__
Ruby2HTML.new(ARGF).parse($stdout)
end
@aisuii
Copy link
Author

aisuii commented Jul 6, 2011

http://i.loveruby.net/w/RipperTutorial.TokenStreamInterface.html + すべての要素になんかしらのクラスを振る

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment