Module: XX::Markup::ClassMethods

Included in:
XX::Markup
Defined in:
lib/xx.rb,
lib/xx-0.1.0.rb

Instance Method Summary collapse

Instance Method Details

#xx_ancestors(xx_which = self) ⇒ Object

–}}}



470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/xx.rb', line 470

def xx_ancestors xx_which = self
#--{{{
  list = []
  ancestors.each do |a|
    list << a if a < xx_which
  end
  xx_which.ancestors.each do |a|
    list << a if a <= Markup
  end
  list
#--}}}
end

#xx_configObject

–}}}



482
483
484
485
486
# File 'lib/xx.rb', line 482

def xx_config
#--{{{
  @@xx_config ||= Hash::new{|h,k| h[k] = {}}
#--}}}
end

#xx_config_for(key, xx_which = nil) ⇒ Object

–}}}



487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/xx.rb', line 487

def xx_config_for key, xx_which = nil 
#--{{{
  key = key.to_s 
  xx_which ||= self
  xx_ancestors(xx_which).each do |a|
    if xx_config[a].has_key? key
      return xx_config[a][key]
    end
  end
  nil
#--}}}
end

#xx_configure(key, value, xx_which = nil) ⇒ Object

–}}}



499
500
501
502
503
504
505
# File 'lib/xx.rb', line 499

def xx_configure key, value, xx_which = nil 
#--{{{
  key = key.to_s
  xx_which ||= self
  xx_config[xx_which][key] = value
#--}}}
end

#xx_define_tag_method(tag_method, tag_name = nil) ⇒ Object

–}}}



444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/xx.rb', line 444

def xx_define_tag_method tag_method, tag_name = nil
#--{{{
  tag_method = tag_method.to_s
  tag_name ||= tag_method.gsub %r/_+$/, ""

  module_eval <<-code
    def #{ tag_method } *a, &b
      hashes, nothashes = a.partition{|x| Hash === x}

      doc = xx_doc
      element = ::REXML::Element::new '#{ tag_name }'

      hashes.each{|h| h.each{|k,v| element.add_attribute k.to_s, v}}
      nothashes.each{|nh| element << ::REXML::Text::new(nh.to_s)}

      doc.create element, &b
    end
  code
  tag_method
#--}}}
end

#xx_define_tmp_method(m) ⇒ Object

–}}}



439
440
441
442
443
# File 'lib/xx.rb', line 439

def xx_define_tmp_method m 
#--{{{
  define_method(m){ raise NotImplementedError, m.to_s }
#--}}}
end

#xx_remove_tag_method(tag_method) ⇒ Object

–}}}



465
466
467
468
469
# File 'lib/xx.rb', line 465

def xx_remove_tag_method tag_method
#--{{{
  remove_method tag_method rescue nil
#--}}}
end

#xx_tag_method_name(m) ⇒ Object

–{{{



432
433
434
435
436
437
438
# File 'lib/xx.rb', line 432

def xx_tag_method_name m
#--{{{
  m = m.to_s
  tag_method, tag_name = m, m.gsub(%r/_+$/, "")
  [ tag_method, tag_name ]
#--}}}
end