Class: Markbridge::Renderers::Discourse::TagLibrary
- Inherits:
-
Object
- Object
- Markbridge::Renderers::Discourse::TagLibrary
- Defined in:
- lib/markbridge/renderers/discourse/tag_library.rb
Overview
Library of rendering tags for different element types
Class Method Summary collapse
-
.default ⇒ TagLibrary
Create the default tag library for Discourse Markdown.
Instance Method Summary collapse
-
#[](element_class) ⇒ Tag?
Get tag for an element class.
-
#auto_register! ⇒ self
Auto-register all tags using naming convention Convention: BoldTag handles AST::Bold, ItalicTag handles AST::Italic, etc.
-
#initialize ⇒ TagLibrary
constructor
A new instance of TagLibrary.
-
#register(element_class, tag) ⇒ Object
Register a tag for an element class.
Constructor Details
#initialize ⇒ TagLibrary
Returns a new instance of TagLibrary.
8 9 10 |
# File 'lib/markbridge/renderers/discourse/tag_library.rb', line 8 def initialize @tags = {} end |
Class Method Details
.default ⇒ TagLibrary
Create the default tag library for Discourse Markdown
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/markbridge/renderers/discourse/tag_library.rb', line 52 def self.default library = new # Auto-register tags based on naming convention library.auto_register! # Special cases: inline tags that don't follow the convention library.register AST::LineBreak, Tags::LineBreakTag.new library.register AST::HorizontalRule, Tags::HorizontalRuleTag.new library end |
Instance Method Details
#[](element_class) ⇒ Tag?
Get tag for an element class
23 24 25 |
# File 'lib/markbridge/renderers/discourse/tag_library.rb', line 23 def [](element_class) @tags[element_class] end |
#auto_register! ⇒ self
Auto-register all tags using naming convention Convention: BoldTag handles AST::Bold, ItalicTag handles AST::Italic, etc.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/markbridge/renderers/discourse/tag_library.rb', line 30 def auto_register! Tags.constants.each do |tag_constant| tag_class = Tags.const_get(tag_constant) next unless tag_class.is_a?(Class) && tag_class < Tag # Extract element name from tag name: BoldTag → Bold element_name = tag_constant.to_s.sub(/Tag$/, "") element_class = begin AST.const_get(element_name) rescue StandardError nil end register(element_class, tag_class.new) if element_class end self end |
#register(element_class, tag) ⇒ Object
Register a tag for an element class
15 16 17 18 |
# File 'lib/markbridge/renderers/discourse/tag_library.rb', line 15 def register(element_class, tag) @tags[element_class] = tag self end |