Class: Image

Inherits:
DocItem show all
Defined in:
lib/almirah/doc_items/image.rb

Constant Summary

Constants included from HtmlSafe

HtmlSafe::ALLOWED_URL_SCHEMES

Instance Attribute Summary collapse

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from DocItem

#get_url, #owner_document, #split_table_cells

Methods inherited from TextLine

#bold, #bold_and_italic, broken_links, #format_string, #inline_code, #italic, #link, link_registry, link_registry=, #literal_text, #owner_document, record_broken_link, reset_broken_links, #wiki_link

Methods included from HtmlSafe

#escape_attr, #escape_text, #safe_url

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #inline_code, #italic, #link, #literal_text, #wiki_link

Constructor Details

#initialize(text, path) ⇒ Image

Returns a new instance of Image.



6
7
8
9
# File 'lib/almirah/doc_items/image.rb', line 6

def initialize(text, path)
  @text = text
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/almirah/doc_items/image.rb', line 4

def path
  @path
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/almirah/doc_items/image.rb', line 4

def text
  @text
end

Instance Method Details

#getTextWithoutSpacesObject



11
12
13
# File 'lib/almirah/doc_items/image.rb', line 11

def getTextWithoutSpaces
  @text.split.join('-')
end

#to_htmlObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/almirah/doc_items/image.rb', line 15

def to_html
  s = ''
  if @@html_table_render_in_progress
    s += "</table>\n"
    @@html_table_render_in_progress = false
  end

  alt = escape_attr(@text)
  src = safe_url(@path)
  if src.nil? # disallowed scheme: render inert rather than emitting it (ADR-188, SRS-098)
    s += "<p style=\"margin-top: 15px;\">[image: #{alt}]"
    return s
  end

  s += "<p style=\"margin-top: 15px;\"><img src=\"#{escape_attr(src)}\" alt=\"#{alt}\" "
  s += 'href="javascript:void(0)" onclick="image_OnClick(this)">'
  s
end