Module: XX::Markup::ClassMethods

Included in:
XX::Markup
Defined in:
lib/rcov/xx.rb

Instance Method Summary collapse

Instance Method Details

#xx_ancestors(xx_which = self) ⇒ Object

–}}}



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

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

–}}}



497
498
499
500
501
# File 'lib/rcov/xx.rb', line 497

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

#xx_config_for(key, xx_which = nil) ⇒ Object

–}}}



502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/rcov/xx.rb', line 502

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

–}}}



514
515
516
517
518
519
520
# File 'lib/rcov/xx.rb', line 514

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

–}}}



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/rcov/xx.rb', line 459

def xx_define_tag_method tag_method, tag_name = nil
#--{{{
  tag_method = tag_method.to_s
  tag_name ||= tag_method.sub(%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

–}}}



454
455
456
457
458
# File 'lib/rcov/xx.rb', line 454

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

#xx_remove_tag_method(tag_method) ⇒ Object

–}}}



480
481
482
483
484
# File 'lib/rcov/xx.rb', line 480

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

#xx_tag_method_name(m) ⇒ Object

–{{{



447
448
449
450
451
452
453
# File 'lib/rcov/xx.rb', line 447

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