SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 235 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

The
result from the preceding would be this, where 16 could be any number between 0 and 99:

Hello


A random number: 16
YAML
Sometimes you don??™t want to specify the formatting in the content at all. You just want the
content to contain structured, hierarchical data, and then format it as you see fit. In some
cases XML is good for this, but if you want a more readable data format I recommend YAML:
Welcome to CoMpoSe:
- This is a small example of what you can do with something like
YAML. Most of what you'd like to do just works, so write everything
like you're used to, and it will be fine.
- "For example, a list of things could look like this:"
- - A thing
- Another thing
- - Some subthing
- More subthings
- A final thing
- You can also create tables and other formatting tools with Textile,
but all that information is available in the documentation, which
can be easily found with Google.
You still have some structure here, but almost all presentation information is gone. To
render this, you need to get more low level, though. First of all, you need to load the YAML file,
and then walk the tree generated and execute operations depending on where you are. Here??™s
the program:
CHAPTER 8 ?–  CONTENT RENDERING 154
require 'yaml'
content = YAML.load_file ARGV[0]
def print_para para
case para
when String: puts "

#{para}

"
when Array:
puts "
    "
    para.each do |el|
    print "
  • "
    print_para el
    puts "
  • "
    end
    puts "
"
end
end
content.


Pages:
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247