class Crycco::Section

Overview

Section

Document contents are organized in sections, which have docs and code. The docs are markdown extracted from comments and the code is the actual code.

Sections can be converted to HTML using the #docs_html and #code_html methods.

Defined in:

crycco.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(language : Language, path : Path) #

On initialization we get the language definition and create a lexer and formatter for code highlighting.


[View source]

Instance Method Detail

def anchor : String #

Extract the first header from documentation for semantic anchoring


[View source]
def code : String #

[View source]
def code=(code : String) #

[View source]
def code_html #

All the code is passed through the formatter to get syntax highlighting


[View source]
def docs : String #

[View source]
def docs=(docs : String) #

[View source]
def docs_html #

Converting Documentation to HTML

The #docs_html method is responsible for converting the documentation portion of each section into final HTML output. This is where the smart file reference processing happens.

The process is:

  1. Process any smart file and symbol references (convert [[file]] and [[Symbol]] to proper links)
  2. Convert the resulting Markdown to HTML using Markd

This means that writers can use both Markdown syntax AND smart file/symbol references in their documentation comments, and they'll both be handled correctly in the final output.

You can see the implementation details of the Markdown processing in [[markd.cr]] and the smart reference processing in the #process_file_references method above.


[View source]
def file_exists?(file_path : Path) : Bool #

Check if a file exists in the processed files list


[View source]
def html_path_for_file(file_path : Path) : String #

[View source]
def language : Language #

[View source]
def language=(language : Language) #

[View source]
def path : Path #

[View source]
def path=(path : Path) #

[View source]
def process_file_references(text : String) : String #

[View source]
def resolve_file_reference(ref_name : String) : String | Nil #

[View source]
def resolve_symbol_reference(symbol_name : String) : String | Nil #

[View source]
def to_h : Hash(String, String) #

The #to_h method is used to turn the section into something that can be handled by the Crinja template engine. Just takes the data and put it in a hash.


[View source]
def to_literate : String #

#to_literate converts the section into valid markdown with code blocks as indented blocks.


[View source]
def to_markdown : String #

#to_markdown converts the section into valid markdown with code blocks for the source code.


[View source]
def to_source : String #

#to_source regenerates valid source code out of the section. This way if the section was generated by a literate document, we can extract the code and comments from it and save it to a file.


[View source]