Module: Asciidoctor::Extensions::SyntaxProcessorDsl
- Included in:
- BlockProcessorDsl, MacroProcessorDsl
- Defined in:
- lib/asciidoctor/extensions.rb
Instance Method Summary collapse
- #content_model(value) ⇒ Object (also: #parse_content_as)
- #default_attributes(value) ⇒ Object (also: #default_attrs)
- #named(value) ⇒ Object
- #positional_attributes(*value) ⇒ Object (also: #name_positional_attributes, #positional_attrs)
- #resolve_attributes(*args) ⇒ Object (also: #resolves_attributes)
Instance Method Details
#content_model(value) ⇒ Object Also known as: parse_content_as
319 320 321 |
# File 'lib/asciidoctor/extensions.rb', line 319 def content_model value option :content_model, value end |
#default_attributes(value) ⇒ Object Also known as: default_attrs
331 332 333 |
# File 'lib/asciidoctor/extensions.rb', line 331 def default_attributes value option :default_attrs, value end |
#named(value) ⇒ Object
310 311 312 313 314 315 316 317 |
# File 'lib/asciidoctor/extensions.rb', line 310 def named value # NOTE due to how processors get initialized, we must defer this assignment in some scenarios if Processor === self @name = value else option :name, value end end |
#positional_attributes(*value) ⇒ Object Also known as: name_positional_attributes, positional_attrs
324 325 326 |
# File 'lib/asciidoctor/extensions.rb', line 324 def positional_attributes *value option :positional_attrs, value.flatten end |
#resolve_attributes(*args) ⇒ Object Also known as: resolves_attributes
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/asciidoctor/extensions.rb', line 337 def resolve_attributes *args # NOTE assume true as default value; rewrap single-argument string or symbol if (args = args.fetch 0, true).respond_to? :to_sym args = [args] end unless args.size > 1 case args when true option :positional_attrs, [] option :default_attrs, {} when ::Array names, defaults = [], {} args.each do |arg| if (arg = arg.to_s).include? '=' name, _, value = arg.partition '=' if name.include? ':' idx, _, name = name.partition ':' idx = idx == '@' ? names.size : idx.to_i names[idx] = name end defaults[name] = value elsif arg.include? ':' idx, _, name = arg.partition ':' idx = idx == '@' ? names.size : idx.to_i names[idx] = name else names << arg end end option :positional_attrs, names.compact option :default_attrs, defaults when ::Hash names, defaults = [], {} args.each do |key, val| if (name = key.to_s).include? ':' idx, _, name = name.partition ':' idx = idx == '@' ? names.size : idx.to_i names[idx] = name end defaults[name] = val if val end option :positional_attrs, names.compact option :default_attrs, defaults else raise ::ArgumentError, %(unsupported attributes specification for macro: #{args.inspect}) end end |