From: Gregory Brown Date: 2005-12-24T00:51:19+09:00 Subject: Re: Ruby version of UMENU On 12/23/05, Steve Litt wrote: > On Friday 23 December 2005 02:08 am, Gregory Brown wrote: > > > > YAML support is built into ruby, and it's a great way to > > represent configuration data. > > > > It provides a simple way to serialize ruby objects as well as to > > load in datastructures and things like that. > > > > This is generally better and easier than parsing config files. > > Google it... I'm sure you'll find plenty o' resources. > > > > That having been said, if you provide a sane YAML format for > > UMENU, I will try to create some sort of menu generation for > > HighLine that is compatible with it. (After running it by James, > > of course). > > You mentioned that Ruby supports YAML. Would that mean that UMENU > would not need to parse the YAMLized version of .mnu files, but > instead Ruby would parse it for us? If so, what would be the format > within memory? You can serialize the objects as arrays, hashes, an array of hashes, or even Menu objects :) > There might be a temptation to place an entire menu SYSTEM within a > single file, instead of the current UMENU method of one file per > menu. For performance reasons, that would be a bad idea, as a huge > file would need to be read from disk and parsed every time someone > pressed Ctrl+9 (for example) to bring up a start menu. My menu > system has 613 command choices in 152 submenus, and takes over 2 > seconds to parse on an Athlon XP2600+ with 1.5GB of RAM. > > Also, keeping an entire menu system in memory at once could prove > problematic on low-memory systems, and in every other respect, > UMENU is designed to run in a very small footprint. > > EMDL (Easy Menu Definition Language) includes a whole menu system in > a single file. The theory is, the EMDL parser need be run only when > the menu system is changed. EMDL has been formulated specifically > for fast and easy construction, especially when using vimoutliner > (http://www.vimoutliner.org). An EMDL to YAML .mnu converter > wouldn't be hard, always assuming the YAML .mnu files are basically > just an indented and colonized version of the current .mnu files. > > Curious -- just how much YAML support does Ruby give the programmer? It's in the standard library. So... the support is pretty good :) See the other post about this and search the archives for more details. but basically: sandal:~ daedelus$ cat foo.yaml first_name: greg last_name: brown middle_name: thomas sandal:~ daedelus$ irb irb(main):001:0> require "yaml" => true irb(main):002:0> a = YAML.load(File.read("foo.yaml")) => {"first_name"=>"greg", "last_name"=>"brown", "middle_name"=>"thomas"} irb(main):003:0> a["last_name"] => "brown" In the interest of further optimizing UMENU, if you use HighLine for your line interface under the hood, you'll get platform independence... which means it can concievably help you get UMENU working on non unix platforms. Plus... who wants to write validation code when something can already do it for you? Or write a platform independant getc, etc etc. :) If you do decide to use it, let me know and I can try to help you some.