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)


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

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.



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

def node
  @node
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#convertObject



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

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