class Utopia::Project::Guide
Provides structured access to a directory which contains documentation and source code to explain a specific process.
Constants
- README
Attributes
The base instance of the project this example is loaded from. @attribute [Base]
The description from the first paragraph in the README
. @attribute [String | Nil]
The file-system path to the root of the project. @attribute [String]
Public Class Methods
Initialize the example with the given root path. @parameter base [Base] The base instance for the project. @parameter root [String] The file-system path to the root of the example.
# File lib/utopia/project/guide.rb, line 34 def initialize(base, root) @base = base @root = root @documentation = nil @document = nil @title = nil @description = nil self.document end
Public Instance Methods
The document for the README
, if one exists.
# File lib/utopia/project/guide.rb, line 66 def document if self.readme? @document ||= self.readme_document.tap do |document| child = document.first_child if child.type == :header @title = child.first_child.string_content @description = child.next child.delete end end end end
The best documentation, extracted from the source files of the guide. @returns [Decode::Documentation]
# File lib/utopia/project/guide.rb, line 109 def documentation @documentation ||= self.best_documentation end
All files associated with this guide. @returns [Array(String)] The file-system paths.
# File lib/utopia/project/guide.rb, line 115 def files Dir.glob(File.expand_path("*", @root)) end
The hypertext reference to this guide. @returns [String]
# File lib/utopia/project/guide.rb, line 103 def href "/guides/#{self.name}/index" end
The name of the guide. @returns [String]
# File lib/utopia/project/guide.rb, line 91 def name File.basename(@root) end
Does a README
file exist for this guide? @returns [Boolean]
# File lib/utopia/project/guide.rb, line 61 def readme? File.exist?(readme_path) end
The path to the README
file for the guide. @returns [String] The file-system path.
# File lib/utopia/project/guide.rb, line 55 def readme_path File.expand_path(README, @root) end
All the source files associated with this guide. @yields {|source| …} If a block is given.
@parameter source [Decode::Source]
@returns [Enumerator(Decode::Source)] If no block is given.
# File lib/utopia/project/guide.rb, line 123 def sources return to_enum(:sources) unless block_given? files.each do |path| if source = @base.index.languages.source_for(path) yield source end end end
The title of the guide. @returns [String]
# File lib/utopia/project/guide.rb, line 97 def title @title || Trenni::Strings.to_title(self.name) end
Private Instance Methods
# File lib/utopia/project/guide.rb, line 141 def best_documentation if source = sources.first if segment = source.segments.first return segment.documentation end end end
# File lib/utopia/project/guide.rb, line 135 def readme_document content = File.read(self.readme_path) return @base.document(content) end