Class Texy::Modules::DefinitionList
In: lib/texy/modules/definition_list.rb
Parent: List

Definition list module class

Methods

init   new   process_block  

Public Class methods

[Source]

# File lib/texy/modules/definition_list.rb, line 40
            def initialize(texy)
                super
                self.allowed = {
                    '*' => true,
                    '-' => true,
                    '+' => true
                }

                self.translate = [
                    ['*', '\*', ''],
                    ['-', '\-', ''],
                    ['+', '\+', '']
                ]
            end

Public Instance methods

Module initialization.

[Source]

# File lib/texy/modules/definition_list.rb, line 56
            def init
                bullets = []

                translate.each do |t|
                    bullets << t[1] if allowed[t[0]]
                end

                texy.register_block_pattern(
                    method(:process_block),
                    /^(?:#{PATTERN_MODIFIER_H}\n)?(\S.*?)\:\ *#{PATTERN_MODIFIER_H}?\n(\ +)(#{bullets.join('|')})\ +\S.*?$/
                )
            end

Callback function (for blocks)

   Term: .(title)[class]{style}>
       - description 1
       - description 2
       - description 3

[Source]

# File lib/texy/modules/definition_list.rb, line 76
            def process_block(parser, matches)
                m_content_term, m_spaces, m_bullet = matches.values_at(5, 10, 11)

                el = ListElement.new(texy)
                el.modifier.set_properties(*matches[1..4])
                el.tag = 'dl'

                bullet = ''
                type = translate.find do |type|
                    /\A#{type[1]}/ =~ m_bullet
                end

                bullet = type[1]
                el.modifier.classes << type[2]



                parser.move_backward(2)

                pattern_term = /\A\n?(\S.*?)\:\ *#{PATTERN_MODIFIER_H}?()$/

                while true
                    if el_item = process_item(parser, Regexp.quote(m_bullet), true)
                        el_item.tag = 'dd'
                        el.append_child(el_item)
                        next
                    end

                    if matches = parser.receive_next(pattern_term)
                        el_item = TextualElement.new(texy)
                        el_item.tag = 'dt'
                        el_item.modifier.set_properties(*matches[2..5]);
                        el_item.parse(matches[1])
                        el.append_child(el_item)
                        next
                    end

                    break
                end

                if handler
                    return unless handler.call(el)
                end

                parser.element.append_child(el)
            end

[Validate]