Module: XX::Markup::InstanceMethods
- Included in:
- XX::Markup
- Defined in:
- lib/rcov/xx.rb
Instance Method Summary collapse
-
#method_missing(m, *a, &b) ⇒ Object
–{{{.
-
#xx_ancestors ⇒ Object
–}}}.
- #xx_any_(*objects, &b) ⇒ Object (also: #x_, #h_)
- #xx_cdata_(*objects, &b) ⇒ Object (also: #c_)
- #xx_class ⇒ Object
-
#xx_config ⇒ Object
–}}}.
-
#xx_config_for(*a, &b) ⇒ Object
–}}}.
-
#xx_configure(*a, &b) ⇒ Object
–}}}.
-
#xx_define_tag_method(*a, &b) ⇒ Object
–}}}.
-
#xx_define_tmp_method(*a, &b) ⇒ Object
–}}}.
-
#xx_doc ⇒ Object
–}}}.
- #xx_markup_(*objects, &b) ⇒ Object
- #xx_parse_attributes(string) ⇒ Object (also: #att_)
- #xx_parse_yaml_attributes(string) ⇒ Object (also: #at_, #yat_)
-
#xx_remove_tag_method(*a, &b) ⇒ Object
–}}}.
-
#xx_tag_(tag_name, *a, &b) ⇒ Object
(also: #g_)
–}}}.
-
#xx_tag_method_name(*a, &b) ⇒ Object
–}}}.
-
#xx_text_(*objects, &b) ⇒ Object
(also: #text_, #t_)
–}}}.
- #xx_which(*argv) ⇒ Object
-
#xx_with_doc_in_effect(*a, &b) ⇒ Object
–}}}.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
–{{{
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 |
# File 'lib/rcov/xx.rb', line 207 def method_missing m, *a, &b #--{{{ m = m.to_s tag_method, tag_name = xx_class::xx_tag_method_name m c_method_missing = xx_class::xx_config_for "method_missing", xx_which = xx_class::xx_config_for "tags", xx_which pat = case c_method_missing when ::XX::CRAZY_LIKE_A_HELL %r/.*/ when ::XX::PERMISSIVE %r/_$/o when ::XX::STRICT %r/_$/o else super(m.to_sym, *a, &b) end super(m.to_sym, *a, &b) unless m =~ pat if c_method_missing == ::XX::STRICT super(m.to_sym, *a, &b) unless .include? tag_name end ret, defined = nil begin xx_class::xx_define_tmp_method tag_method xx_class::xx_define_tag_method tag_method, tag_name ret = send tag_method, *a, &b defined = true ensure xx_class::xx_remove_tag_method tag_method unless defined end ret #--}}} end |
Instance Method Details
#xx_ancestors ⇒ Object
–}}}
438 439 440 441 442 443 |
# File 'lib/rcov/xx.rb', line 438 def xx_ancestors #--{{{ raise Error, "no xx_which in effect" unless xx_which xx_class.xx_ancestors xx_which #--}}} end |
#xx_any_(*objects, &b) ⇒ Object Also known as: x_, h_
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/rcov/xx.rb', line 357 def xx_any_ *objects, &b #--{{{ doc = xx_doc nothing = %r/.^/m text = ::REXML::Text::new("", respect_whitespace=true, parent=nil, raw=true, entity_filter=nil, illegal=nothing ) objects.each do |object| text << object.to_s if object end doc.create text, &b #--}}} end |
#xx_cdata_(*objects, &b) ⇒ Object Also known as: c_
377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/rcov/xx.rb', line 377 def xx_cdata_ *objects, &b #--{{{ doc = xx_doc cdata = ::REXML::CData::new "" objects.each do |object| cdata << object.to_s if object end doc.create cdata, &b #--}}} end |
#xx_class ⇒ Object
413 414 415 416 417 |
# File 'lib/rcov/xx.rb', line 413 def xx_class #--{{{ @xx_class ||= self.class #--}}} end |
#xx_config ⇒ Object
–}}}
444 445 446 447 448 |
# File 'lib/rcov/xx.rb', line 444 def xx_config #--{{{ xx_class.xx_config #--}}} end |
#xx_config_for(*a, &b) ⇒ Object
–}}}
449 450 451 452 453 |
# File 'lib/rcov/xx.rb', line 449 def xx_config_for *a, &b #--{{{ xx_class.xx_config_for(*a, &b) #--}}} end |
#xx_configure(*a, &b) ⇒ Object
–}}}
454 455 456 457 458 |
# File 'lib/rcov/xx.rb', line 454 def xx_configure *a, &b #--{{{ xx_class.xx_configure(*a, &b) #--}}} end |
#xx_define_tag_method(*a, &b) ⇒ Object
–}}}
428 429 430 431 432 |
# File 'lib/rcov/xx.rb', line 428 def xx_define_tag_method *a, &b #--{{{ xx_class.xx_define_tag_method(*a, &b) #--}}} end |
#xx_define_tmp_method(*a, &b) ⇒ Object
–}}}
423 424 425 426 427 |
# File 'lib/rcov/xx.rb', line 423 def xx_define_tmp_method *a, &b #--{{{ xx_class.xx_define_tmp_methodr(*a, &b) #--}}} end |
#xx_doc ⇒ Object
–}}}
316 317 318 319 320 |
# File 'lib/rcov/xx.rb', line 316 def xx_doc #--{{{ @xx_docs.last rescue raise "no xx_doc in effect!" #--}}} end |
#xx_markup_(*objects, &b) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'lib/rcov/xx.rb', line 339 def xx_markup_ *objects, &b #--{{{ doc = xx_doc doc2 = ::REXML::Document::new "" objects.each do |object| (doc2.root ? doc2.root : doc2) << ::REXML::Document::new(object.to_s) end ret = doc.create doc2, &b puts doc2.to_s STDIN.gets ret #--}}} end |
#xx_parse_attributes(string) ⇒ Object Also known as: att_
391 392 393 394 395 396 397 398 |
# File 'lib/rcov/xx.rb', line 391 def xx_parse_attributes string #--{{{ string = string.to_s tokens = string.split %r/,/o tokens.map{|t| t.sub!(%r/[^=]+=/){|key_eq| key_eq.chop << " : "}} xx_parse_yaml_attributes(tokens.join(',')) #--}}} end |
#xx_parse_yaml_attributes(string) ⇒ Object Also known as: at_, yat_
400 401 402 403 404 405 406 407 408 409 410 |
# File 'lib/rcov/xx.rb', line 400 def xx_parse_yaml_attributes string #--{{{ require "yaml" string = string.to_s string = "{" << string unless string =~ %r/^\s*[{]/o string = string << "}" unless string =~ %r/[}]\s*$/o obj = ::YAML::load string raise ArgumentError, "<#{ obj.class }> not Hash!" unless Hash === obj obj #--}}} end |
#xx_remove_tag_method(*a, &b) ⇒ Object
–}}}
433 434 435 436 437 |
# File 'lib/rcov/xx.rb', line 433 def xx_remove_tag_method *a, &b #--{{{ xx_class.xx_tag_remove_method(*a, &b) #--}}} end |
#xx_tag_(tag_name, *a, &b) ⇒ Object Also known as: g_
–}}}
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/rcov/xx.rb', line 248 def xx_tag_ tag_name, *a, &b #--{{{ tag_method, tag_name = xx_class::xx_tag_method_name tag_name ret, defined = nil begin xx_class::xx_define_tmp_method tag_method xx_class::xx_define_tag_method tag_method, tag_name ret = send tag_method, *a, &b defined = true ensure xx_class::xx_remove_tag_method tag_method unless defined end ret #--}}} end |
#xx_tag_method_name(*a, &b) ⇒ Object
–}}}
418 419 420 421 422 |
# File 'lib/rcov/xx.rb', line 418 def xx_tag_method_name *a, &b #--{{{ xx_class.xx_tag_method_name(*a, &b) #--}}} end |
#xx_text_(*objects, &b) ⇒ Object Also known as: text_, t_
–}}}
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/rcov/xx.rb', line 321 def xx_text_ *objects, &b #--{{{ doc = xx_doc text = ::REXML::Text::new("", respect_whitespace=true, parent=nil ) objects.each do |object| text << object.to_s if object end doc.create text, &b #--}}} end |
#xx_which(*argv) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rcov/xx.rb', line 267 def xx_which *argv #--{{{ @xx_which = nil unless defined? @xx_which if argv.empty? @xx_which else xx_which = @xx_which begin @xx_which = argv.shift return yield ensure @xx_which = xx_which end end #--}}} end |
#xx_with_doc_in_effect(*a, &b) ⇒ Object
–}}}
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/rcov/xx.rb', line 283 def xx_with_doc_in_effect *a, &b #--{{{ @xx_docs ||= [] doc = ::XX::Document::new(*a) ddoc = doc.doc begin @xx_docs.push doc b.call doc if b doctype = xx_config_for "doctype", xx_which if doctype unless ddoc.doctype doctype = ::REXML::DocType::new doctype unless ::REXML::DocType === doctype ddoc << doctype end end xmldecl = xx_config_for "xmldecl", xx_which if xmldecl if ddoc.xml_decl == ::REXML::XMLDecl::default xmldecl = ::REXML::XMLDecl::new xmldecl unless ::REXML::XMLDecl === xmldecl ddoc << xmldecl end end return doc ensure @xx_docs.pop end #--}}} end |