Author image Hoe-Kit Chew
and 2 contributors

ATTRIBUTES

_chapter_dlines

The _chapter_dlines attribute stores the default Dline for each Dlineset that makes up the chapter. In other words it has the Dline that should be visible. It is a Hashref of a location to Dline. Example:

    _chapter_dlines = {
        '0.0.2'  => Dline({ class => 'chapter-number', str => ' /Chapter One' });
        '0.1.2'  => Dline({ class => 'chapter-title',  str => ' /A Great Surprise' });
        '0.2.13' => Dline({ class => 'paragraph-start',str => ' /"Mother, have ...' });
        ...
    }

_curr_dlineset

The _curr_dlineset attribute stores the Dlineset that is currently being pointed to. In other words, it is the sentence that is currently being read and being transformed from the native language to the target language. Example:

    _curr_dlineset = {
        '0.1.0' => Dline({ class => 'chapter-title', str => 'ความประหลาดใจที่ยอดเยี่ยม /' });
        '0.1.1' => Dline({ class => 'chapter-title', str => 'ความประหลาดใจที่ /Great' });
        '0.1.2' => Dline({ class => 'chapter-title', str => ' /A Great Surprise' });
    }

METHODS

_load_chapter() :> Self

The _load_chapter() private method loads the chapter's default/targer Dlines into the _chapter_dlines attribute. It loads the chapter currently pointed to by the objects '_ptr' attribute.

html() :> HTML

The html() public method renders the current chapter into HTML.

_render(Dline) :> HTML

The _render(Dline) private function renders the given Dline into a suitable HTML string.

_render_normal(Dline) :> HTML

The _render_normal(Dline) private method renders the given Dline into the normal HTML output.

This method reads the class of the given Dline and renders the associated element. The Dline class is responsible for font-size and white-space associated with the line but not colors.

_render_pointed(Dline) :> HTML

The _render_pointed(Dline) private method renders the pointed-to line. The pointed-to line entire broken line is displayed with a background. The source language has one set of font-color and background-color while the target language has another set of font-color and background-color.

We implement this by first wrapping the entire line in a span with class "current-line". Then each segment is wrapped in a span as well. Segments in the source language is has a class of src-lang. Segments in the target language are unlabeled.

Then create a new Dline with the same class as the input, but with the generated HTML as the str. Then call _render_normal on this new Dline to generate the final HTML.

book_json() :> JSON

The book_json() public method converts the book into a JSON string. The method iterates over all Chapters and all Dlinesets in each chapter and all Dlines in all Dlinesets.

Note that the returned JSON string is already utf8 encoded so when writing the string to a file, use the form without utf8 encoding e.g. use Path::Tiny's spew() instead spew_utf8().

_next_ptr() :> undef | [Ptr,diff_chapter,diff_dlineset,diff_dline]

The _next_ptr() private method returns undef if no next pointer is available. Otherwise, it returns the next pointer (Ptr), several boolean flags indicating whether the next pointer points to a location in a different chapter, a different dlineset or a different dline.

_prev_ptr() :> undef | [PtrStr,diff_chapter,diff_dlineset,diff_dline]

The _prev_ptr() private method returns undef if no previous pointer is available. Otherwise, it returns the previous pointer (Ptr), several boolean flags indicating whether the previous pointer points to a location in a different chapter, a different dlineset or a different dline.

_max_loc($href)

Returns the max location of a href that has locations as key.

_cmp_loc($a,$b)

Returns -1, 0 or 1 depending on whether the left argument is stringwise less than, equal to or greater than the right argument.

    $a < $b : -1
    $a = $b :  0
    $a > $b :  1