Module: XX::Markup::ClassMethods

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

Instance Method Summary collapse

Instance Method Details

#xx_ancestors(xx_which = self) ⇒ Object

–}}}


454
455
456
457
458
459
460
461
462
463
464
465
# File 'lib/xx.rb', line 454

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

–}}}


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

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

#xx_config_for(key, xx_which = nil) ⇒ Object

–}}}


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

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

–}}}


483
484
485
486
487
488
489
# File 'lib/xx.rb', line 483

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

–}}}


428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/xx.rb', line 428

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

–}}}


423
424
425
426
427
# File 'lib/xx.rb', line 423

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

#xx_remove_tag_method(tag_method) ⇒ Object

–}}}


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

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

#xx_tag_method_name(m) ⇒ Object

–{{{


416
417
418
419
420
421
422
# File 'lib/xx.rb', line 416

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