@@ -59,6 +59,10 @@ def initialize(root = Dir.pwd)
5959 # Return the absolute path for the given file name, if it exists in the project.
6060 # @parameter file_name [String] The relative path to the project file, e.g. `readme.md`.
6161 # @returns [String] The file-system path.
62+ #
63+ # @example Get README path
64+ # base = Utopia::Project::Base.new
65+ # base.path_for("readme.md") # => "/path/to/project/readme.md" or nil
6266 def path_for ( file_name )
6367 full_path = File . expand_path ( file_name , @root )
6468 if File . exist? ( full_path )
@@ -86,6 +90,10 @@ def best(definitions)
8690
8791 # Given a lexical path, find the best definition for that path.
8892 # @returns [Tuple(Decode::Trie::Node, Decode::Definition)]
93+ #
94+ # @example Lookup a definition
95+ # base = Utopia::Project::Base.local
96+ # _, definition = base.lookup(%i[Utopia Project Base])
8997 def lookup ( path )
9098 if node = @index . trie . lookup ( path . map ( &:to_sym ) )
9199 return node , best ( node . values )
@@ -119,6 +127,10 @@ def linkify(text, definition, language: definition&.language)
119127 # Format the given text in the context of the given definition and language.
120128 # See {document} for details.
121129 # @returns [XRB::MarkupString]
130+ #
131+ # @example Format text with code links
132+ # base = Utopia::Project::Base.new
133+ # base.format("See {Utopia::Project::Base#guides}.") # => XRB::MarkupString
122134 def format ( text , definition = nil , language : definition &.language , **options )
123135 if document = self . document ( text , definition , language : language )
124136 return XRB ::Markup . raw (
@@ -132,6 +144,11 @@ def format(text, definition = nil, language: definition&.language, **options)
132144 # Updates source code references (`{language identifier}`) into links.
133145 #
134146 # @returns [Document]
147+ #
148+ # @example Convert markdown to HTML
149+ # base = Utopia::Project::Base.new
150+ # doc = base.document("# Title")
151+ # doc.to_html # => "<h1>Title</h1>\n"
135152 def document ( text , definition = nil , language : definition &.language )
136153 case text
137154 when Enumerable
@@ -145,6 +162,11 @@ def document(text, definition = nil, language: definition&.language)
145162
146163 # Compute a unique string which can be used as `id` attribute in the HTML output.
147164 # @returns [String]
165+ #
166+ # @example Compute id for a definition
167+ # base = Utopia::Project::Base.local
168+ # _, definition = base.lookup(%i[Utopia Project Base])
169+ # base.id_for(definition) # => "Utopia::Project::Base"
148170 def id_for ( definition , suffix = nil )
149171 if suffix
150172 "#{ definition . qualified_name } -#{ suffix } "
@@ -155,6 +177,11 @@ def id_for(definition, suffix = nil)
155177
156178 # Compute a link href to the given definition for use within the HTML output.
157179 # @returns [XRB::Reference]
180+ #
181+ # @example Link to a definition
182+ # base = Utopia::Project::Base.local
183+ # _, definition = base.lookup(%i[Utopia Project Base])
184+ # base.link_for(definition).to_s # => "/source/utopia/project/index#Utopia::Project::Base"
158185 def link_for ( definition )
159186 path = definition . lexical_path . map { |entry | entry . to_s }
160187
@@ -170,6 +197,12 @@ def link_for(definition)
170197 # @yields {|guide| ...} If a block is given.
171198 # @parameter guide [Guide]
172199 # @returns [Enumerator(Guide)] If no block given.
200+ #
201+ # @example List guide titles
202+ # base = Utopia::Project::Base.new
203+ # base.guides.each do |guide|
204+ # puts guide.title
205+ # end
173206 def guides
174207 return to_enum ( :guides ) unless block_given?
175208
0 commit comments