Class: Utopia::Project::Guide
- Inherits:
-
Object
- Object
- Utopia::Project::Guide
- Defined in:
- lib/utopia/project/guide.rb
Overview
Provides structured access to a directory which contains documentation and source code to explain a specific process.
Constant Summary collapse
- README =
"README.md"
Instance Attribute Summary collapse
-
#base ⇒ Object
The base instance of the project this example is loaded from.
-
#description ⇒ Object
readonly
The description from the first paragraph in the README.
-
#root ⇒ Object
readonly
The file-system path to the root of the project.
Instance Method Summary collapse
-
#document ⇒ Object
The document for the README, if one exists.
-
#documentation ⇒ Object
The best documentation, extracted from the source files of the guide.
-
#files ⇒ Object
All files associated with this guide.
-
#href ⇒ Object
The hypertext reference to this guide.
-
#initialize(base, root) ⇒ Guide
constructor
Initialize the example with the given root path.
-
#name ⇒ Object
The name of the guide.
-
#readme? ⇒ Boolean
Does a README file exist for this guide?.
-
#readme_path ⇒ Object
The path to the README file for the guide.
-
#sources ⇒ Object
All the source files associated with this guide.
-
#title ⇒ Object
The title of the guide.
Constructor Details
#initialize(base, root) ⇒ Guide
Initialize the example with the given root path.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/utopia/project/guide.rb', line 35 def initialize(base, root) @base = base @root = root @documentation = nil @document = nil @title = nil @description = nil self.document end |
Instance Attribute Details
#base ⇒ Object
The base instance of the project this example is loaded from.
93 94 95 |
# File 'lib/utopia/project/guide.rb', line 93 def base @base end |
#description ⇒ Object (readonly)
The description from the first paragraph in the README.
50 51 52 |
# File 'lib/utopia/project/guide.rb', line 50 def description @description end |
#root ⇒ Object (readonly)
The file-system path to the root of the project.
97 98 99 |
# File 'lib/utopia/project/guide.rb', line 97 def root @root end |
Instance Method Details
#document ⇒ Object
The document for the README, if one exists.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/utopia/project/guide.rb', line 68 def document if self.readme? @document ||= self.readme_document.tap do |document| root = document.root if element = root.children.first if element.type == :header @title = element.children.first.value # Remove the title: root.children.shift # Remove any blank lines: root.children.shift while root.children.first&.type == :blank # Read the description: root.children.first.[:encoding] = root.[:encoding] @description = Kramdown::Converter::Kramdown.convert(root.children.first).first end end end end end |
#documentation ⇒ Object
The best documentation, extracted from the source files of the guide.
119 120 121 |
# File 'lib/utopia/project/guide.rb', line 119 def documentation @documentation ||= self.best_documentation end |
#files ⇒ Object
All files associated with this guide.
125 126 127 |
# File 'lib/utopia/project/guide.rb', line 125 def files Dir.glob(File.("*", @root)) end |
#href ⇒ Object
The hypertext reference to this guide.
113 114 115 |
# File 'lib/utopia/project/guide.rb', line 113 def href "/guides/#{self.name}/index" end |
#name ⇒ Object
The name of the guide.
101 102 103 |
# File 'lib/utopia/project/guide.rb', line 101 def name File.basename(@root) end |
#readme? ⇒ Boolean
Does a README file exist for this guide?
62 63 64 |
# File 'lib/utopia/project/guide.rb', line 62 def readme? File.exist?(readme_path) end |
#readme_path ⇒ Object
The path to the README file for the guide.
56 57 58 |
# File 'lib/utopia/project/guide.rb', line 56 def readme_path File.(README, @root) end |
#sources ⇒ Object
All the source files associated with this guide.
133 134 135 136 137 138 139 140 141 |
# File 'lib/utopia/project/guide.rb', line 133 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 |
#title ⇒ Object
The title of the guide.
107 108 109 |
# File 'lib/utopia/project/guide.rb', line 107 def title @title || Trenni::Strings.to_title(self.name) end |