Class: TextLine

Inherits:
TextLineBuilderContext show all
Defined in:
lib/almirah/doc_items/text_line.rb

Direct Known Subclasses

ControlledTableColumn, DocItem

Constant Summary collapse

@@lazy_doc_id_dict =
{}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_lazy_doc_id(id) ⇒ Object



247
248
249
250
# File 'lib/almirah/doc_items/text_line.rb', line 247

def self.add_lazy_doc_id(id)
  doc_id = id.to_s.downcase
  @@lazy_doc_id_dict[doc_id] = doc_id
end

Instance Method Details

#bold(str) ⇒ Object



262
263
264
# File 'lib/almirah/doc_items/text_line.rb', line 262

def bold(str)
  "<b>#{str}</b>"
end

#bold_and_italic(str) ⇒ Object



266
267
268
# File 'lib/almirah/doc_items/text_line.rb', line 266

def bold_and_italic(str)
  "<b><i>#{str}</i></b>"
end

#format_string(str) ⇒ Object



252
253
254
255
256
# File 'lib/almirah/doc_items/text_line.rb', line 252

def format_string(str)
  tlp = TextLineParser.new
  tlb = TextLineBuilder.new(self)
  tlb.restore(tlp.tokenize(str))
end

#italic(str) ⇒ Object



258
259
260
# File 'lib/almirah/doc_items/text_line.rb', line 258

def italic(str)
  "<i>#{str}</i>"
end


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/almirah/doc_items/text_line.rb', line 270

def link(link_text, link_url)
  # define default result first
  result = "<a target=\"_blank\" rel=\"noopener\" href=\"#{link_url}\" class=\"external\">#{link_text}</a>"

  lazy_doc_id = nil
  anchor = nil

  if res = /(\w+)[.]md$/.match(link_url)          # link
    lazy_doc_id = res[1].to_s.downcase

  elsif res = /(\w*)[.]md(#.*)$/.match(link_url)  # link with anchor
    if res && res.length > 2
      lazy_doc_id = res[1]
      anchor = res[2]
    end
  end

  if lazy_doc_id && @@lazy_doc_id_dict.key?(lazy_doc_id)
    result = if anchor
               "<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html#{anchor}\" class=\"external\">#{link_text}</a>"
             else
               "<a href=\".\\..\\#{lazy_doc_id}\\#{lazy_doc_id}.html\" class=\"external\">#{link_text}</a>"
             end
  end
  result
end