class ConvertInline
Attributes
args[RW]
Your code goes here…
attributes[RW]
Your code goes here…
insert[RW]
Your code goes here…
node[RW]
Your code goes here…
Public Class Methods
new(node, args = {})
click to toggle source
# File lib/convert_inline.rb, line 7 def initialize(node, args = {}) @node = node @insert = @node['insert'] @attributes = @node['attributes'] @args = args end
Public Instance Methods
convert()
click to toggle source
# File lib/convert_inline.rb, line 14 def convert return @insert if @insert.is_a?(String) && @attributes.nil? if @insert.is_a?(String) @attributes.each_key { |attr| @insert = send(attr) } else @insert = @insert.keys.first == 'wk-image' ? image : embed(@insert.keys.first) end @insert rescue NoMethodError @insert end
Private Instance Methods
blockquote()
click to toggle source
# File lib/convert_inline.rb, line 42 def blockquote "<blockquote>#{@insert}</blockquote>" end
bold()
click to toggle source
# File lib/convert_inline.rb, line 34 def bold "<strong>#{@insert}</strong>" end
embed(key)
click to toggle source
# File lib/convert_inline.rb, line 54 def embed(key) return '<hr>' if key == 'wk-divider' '<div data-id="' << key << '" data-src="' << @insert[key] << '"></div>' end
header()
click to toggle source
# File lib/convert_inline.rb, line 38 def header "<h#{@attributes['header']}>#{@insert}</h#{@attributes['header']}>" end
image()
click to toggle source
# File lib/convert_inline.rb, line 60 def image invalid_cap = @insert['wk-image']['caption'].nil? || @insert['wk-image']['caption'].strip.empty? img_src = @insert['wk-image']['src'] || @attributes['src'] || @insert['wk-image'] img_cap = invalid_cap ? '' : @insert['wk-image']['caption'] img_alt = invalid_cap ? args[:title] : @insert['wk-image']['caption'] return '' if img_src.nil? data = '<figure class="post-content-image-container">' data << '<img class="post-content-image lazy blur" data-src="' << img_src << '" alt="' << img_alt << '">' data << '<figcaption class="post-image-caption u-text-center">' << img_cap << '</figcaption>' data << '</figure>' data end
italic()
click to toggle source
# File lib/convert_inline.rb, line 30 def italic "<em>#{@insert}</em>" end
link()
click to toggle source
# File lib/convert_inline.rb, line 46 def link '<a href="' << @attributes['link'] << '" target="_blank">' << @insert << '</a>' end
list()
click to toggle source
# File lib/convert_inline.rb, line 50 def list "<ul><li>#{@insert}</li></ul>" end