Class: MarkdownUI::ListTag

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown-ui/tag/list_tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(content, klass = nil, type = nil, data = nil) ⇒ ListTag



3
4
5
6
7
8
# File 'lib/markdown-ui/tag/list_tag.rb', line 3

def initialize(content, klass = nil, type = nil, data = nil)
  @klass = klass
  @content = content
  @type = type
  @data = data
end

Instance Method Details

#renderObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/markdown-ui/tag/list_tag.rb', line 10

def render
  content = @content.split(';')
  klass = MarkdownUI::KlassUtil.new(@klass).klass

  data = if @data
    _data, attribute, value = @data.split(':')
    " data-#{attribute}=\'#{value}\'"
  else
    nil
  end

  list = ''
  if !content.grep(/^\<li\>.*/).empty?
    list = content.join
  else
    content.each do |c|
      list += "<li>#{c}</li>"
    end
  end

  @type = :unordered if @type.nil?

  case @type
  when :ordered
    "<ol#{klass}#{data}>#{list}</ol>"
  when :unordered
    "<ul#{klass}#{data}>#{list}</ul>"
  end
end