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 = " # \#{meth_rdoc}\n def \#{meth_name.downcase}\n @\#{meth_name}\n end\n \n def \#{meth_name.downcase}=(value)\n @\#{meth_name.downcase} = value\n end\n\n private\n def parse_\#{meth_name.downcase}\n begin\n \#{body}\n rescue NoMethodError\n return nil\n end\n end\n CODE\n \n klass.module_eval(code)\n \n # hook to write klass + name attrib to a file\n if $META_RDOC\n open($META_RDOC, 'a+') do |f|\n f.puts(\"class \#{klass}\\n \#{code}\\n end\")\n end\n end\n \nend\n" |
.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 = " # \#{meth_rdoc}\n def to_\#{format}\n xslt = XML::XSLT.new\n xslt.xml = self.to_xml\n xslt.xsl = REXML::Document.new( File.new( \#{xslt_path} ) )\n xslt.serve\n end\n CODE\n \n klass.module_eval(code)\n \n if $META_RDOC\n open($META_RDOC, 'a+') do |f|\n f.puts(\"class \#{klass}\\n \#{code}\\n end\")\n end\n end\n\nend\n" |