Method: Asciidoctor::Block#initialize

Defined in:
lib/asciidoctor/block.rb

#initialize(parent, context, opts = {}) ⇒ Block

Initialize an Asciidoctor::Block object.

Parameters:

  • parent

    The parent AbstractBlock with a compound content model to which this Block will be appended.

  • context

    The Symbol context name for the type of content (e.g., :paragraph).

  • opts (defaults to: {})

    a Hash of options to customize block initialization: (default: {}) * :content_model indicates whether blocks can be nested in this Block (:compound), otherwise how the lines should be processed (:simple, :verbatim, :raw, :empty). (default: :simple) * :attributes a Hash of attributes (key/value pairs) to assign to this Block. (default: {}) * :source a String or Array of raw source for this Block. (default: nil)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/asciidoctor/block.rb', line 50

def initialize parent, context, opts = {}
  super
  @content_model = opts[:content_model] || DEFAULT_CONTENT_MODEL[context]
  if opts.key? :subs
    # FIXME feels funky; we have to be defensive to get commit_subs to honor override
    # FIXME does not resolve substitution groups inside Array (e.g., [:normal])
    if (subs = opts[:subs])
      case subs
      # e.g., subs: :default
      # subs attribute is honored; falls back to opts[:default_subs], then built-in defaults based on context
      when :default
        @default_subs = opts[:default_subs]
      # e.g., subs: [:quotes]
      # subs attribute is not honored
      when ::Array
        @default_subs = subs.drop 0
        @attributes.delete 'subs'
      # e.g., subs: :normal or subs: 'normal'
      # subs attribute is not honored
      else
        @default_subs = nil
        @attributes['subs'] = subs.to_s
      end
      # resolve the subs eagerly only if subs option is specified
      # QUESTION should we skip subsequent calls to commit_subs?
      commit_subs
    # e.g., subs: nil
    else
      # NOTE @subs is initialized as empty array by super constructor
      # prevent subs from being resolved
      @default_subs = []
      @attributes.delete 'subs'
    end
  # defer subs resolution; subs attribute is honored
  else
    # NOTE @subs is initialized as empty array by super constructor
    # QUESTION should we honor :default_subs option (i.e., @default_subs = opts[:default_subs])?
    @default_subs = nil
  end
  if (raw_source = opts[:source]).nil_or_empty?
    @lines = []
  elsif ::String === raw_source
    @lines = Helpers.prepare_source_string raw_source
  else
    @lines = raw_source.drop 0
  end
end