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
306 307 308 |
# File 'lib/asciidoctor/extensions.rb', line 306 def content_model value option :content_model, value end |
#default_attributes(value) ⇒ Object Also known as: default_attrs
318 319 320 |
# File 'lib/asciidoctor/extensions.rb', line 318 def default_attributes value option :default_attrs, value end |
#named(value) ⇒ Object
297 298 299 300 301 302 303 304 |
# File 'lib/asciidoctor/extensions.rb', line 297 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
311 312 313 |
# File 'lib/asciidoctor/extensions.rb', line 311 def positional_attributes *value option :positional_attrs, value.flatten end |
#resolve_attributes(*args) ⇒ Object Also known as: resolves_attributes
324 325 326 327 328 329 330 331 332 333 334 335 336 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 |
# File 'lib/asciidoctor/extensions.rb', line 324 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 |