Class: Qiita::Markdown::Filters::CustomBlock::Note

Inherits:
Object
  • Object
show all
Defined in:
lib/qiita/markdown/filters/custom_block.rb

Constant Summary collapse

ALLOWED_TYPES =
%w[info warn alert].freeze
DEFAULT_TYPE =
"info".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, type) ⇒ Note

Returns a new instance of Note.

Parameters:

  • node (Nokogiri::XML::Node)
  • type (String, nil)


38
39
40
41
# File 'lib/qiita/markdown/filters/custom_block.rb', line 38

def initialize(node, type)
  @node = node
  @type = ALLOWED_TYPES.include?(type) ? type : DEFAULT_TYPE
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



31
32
33
# File 'lib/qiita/markdown/filters/custom_block.rb', line 31

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



31
32
33
# File 'lib/qiita/markdown/filters/custom_block.rb', line 31

def type
  @type
end

Instance Method Details

#convertObject



43
44
45
46
47
# File 'lib/qiita/markdown/filters/custom_block.rb', line 43

def convert
  node.inner_html = message
  node["class"] = "note #{type}"
  node.children.first.add_previous_sibling(icon) if icon
end