Class: Coradoc::Element::Image::Core

Inherits:
Base
  • Object
show all
Extended by:
AttributeList::Matchers
Defined in:
lib/coradoc/element/image/core.rb

Direct Known Subclasses

BlockImage, InlineImage

Constant Summary collapse

VALIDATORS_POSITIONAL =
[
  [:alt, String],
  [:width, Integer],
  [:height, Integer],
]
VALIDATORS_NAMED =
{
  id: String,
  alt: String,
  fallback: String,
  title: String,
  width: Integer,
  height: Integer,
  link: String, # change to that URI regexp
  window: String,
  scale: Integer,
  scaledwidth: /\A[0-9]{1,2}%\z/,
  pdfwidth: /\A[0-9]+vw\z/,
  role: many(/.*/, "left", "right", "th", "thumb", "related", "rel"),
  opts: many("nofollow", "noopener", "inline", "interactive"),
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeList::Matchers

many, one

Methods inherited from Base

#children_accessors, children_accessors, declare_children, #simplify_block_content, visit, #visit

Constructor Details

#initialize(title, id, src, options = {}) ⇒ Core

Returns a new instance of Core.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/coradoc/element/image/core.rb', line 9

def initialize(title, id, src, options = {})
  @title = title
  @id = id
  @anchor = @id.nil? ? nil : Inline::Anchor.new(@id)
  @src = src
  @attributes = options.fetch(:attributes, AttributeList.new)
  @annotate_missing = options.fetch(:annotate_missing, nil)
  @title = options.fetch(:title, nil) unless @title
  if @attributes.any?
    @attributes.validate_positional(VALIDATORS_POSITIONAL)
    @attributes.validate_named(VALIDATORS_NAMED)
  end
  @line_break = options.fetch(:line_break, "")
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/coradoc/element/image/core.rb', line 5

def attributes
  @attributes
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/coradoc/element/image/core.rb', line 5

def id
  @id
end

#srcObject

Returns the value of attribute src.



5
6
7
# File 'lib/coradoc/element/image/core.rb', line 5

def src
  @src
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/coradoc/element/image/core.rb', line 5

def title
  @title
end

Instance Method Details

#to_adocObject



24
25
26
27
28
29
30
# File 'lib/coradoc/element/image/core.rb', line 24

def to_adoc
  missing = "// FIXME: Missing image: #{@annotate_missing}\n" if @annotate_missing
  anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
  title = ".#{@title}\n" unless @title.to_s.empty?
  attrs = @attributes_macro.to_adoc
  [missing, anchor, title, "image", @colons, @src, attrs, @line_break].join("")
end