Module: MetaGen
- Defined in:
- lib/xspf.rb
Overview
:include: USAGE :main: USAGE
Class Method Summary collapse
-
.add_method(klass, meth_name, body, meth_rdoc) ⇒ Object
define the method.
-
.add_output_format(klass, format, meth_rdoc) ⇒ Object
output in different formats FIXME Only works in parse mode, not in generation mode.
Class Method Details
.add_method(klass, meth_name, body, meth_rdoc) ⇒ Object
define the method
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xspf.rb', line 33 def self.add_method(klass, meth_name, body, meth_rdoc) code = <<-CODE # #{meth_rdoc} def #{meth_name.downcase} @#{meth_name} end def #{meth_name.downcase}=(value) @#{meth_name.downcase} = value end private def parse_#{meth_name.downcase} begin #{body} rescue NoMethodError return nil end end CODE klass.module_eval(code) # hook to write klass + name attrib to a file if $META_RDOC open($META_RDOC, 'a+') do |f| f.puts("class #{klass}\n #{code}\n end") end end end |
.add_output_format(klass, format, meth_rdoc) ⇒ Object
output in different formats FIXME Only works in parse mode, not in generation mode.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/xspf.rb', line 67 def self.add_output_format(klass, format, meth_rdoc) xslt_path = "'#{File.join( File.dirname(__FILE__), %Q{xspf2#{format}.xsl} )}'" code = <<-CODE # #{meth_rdoc} def to_#{format} xslt = XML::XSLT.new xslt.xml = self.to_xml xslt.xsl = REXML::Document.new( File.new( #{xslt_path} ) ) xslt.serve end CODE klass.module_eval(code) if $META_RDOC open($META_RDOC, 'a+') do |f| f.puts("class #{klass}\n #{code}\n end") end end end |