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
readonly
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
- #documentation ⇒ Object
- #files ⇒ Object
- #href ⇒ Object
-
#initialize(base, root) ⇒ Guide
constructor
Initialize the example with the given root path.
- #name ⇒ Object
- #readme? ⇒ Boolean
- #readme_path ⇒ Object
- #sources ⇒ Object
- #title ⇒ Object
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 (readonly)
The base instance of the project this example is loaded from.
86 87 88 |
# File 'lib/utopia/project/guide.rb', line 86 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.
89 90 91 |
# File 'lib/utopia/project/guide.rb', line 89 def root @root end |
Instance Method Details
#document ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/utopia/project/guide.rb', line 62 def document if self.readme? @document ||= Kramdown::Document.new(File.read(self.readme_path), syntax_highlighter: nil).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
103 104 105 |
# File 'lib/utopia/project/guide.rb', line 103 def documentation @documentation ||= self.best_documentation end |
#files ⇒ Object
107 108 109 |
# File 'lib/utopia/project/guide.rb', line 107 def files Dir.glob(File.("*", @root)) end |
#href ⇒ Object
99 100 101 |
# File 'lib/utopia/project/guide.rb', line 99 def href "/guides/#{self.name}/index" end |
#name ⇒ Object
91 92 93 |
# File 'lib/utopia/project/guide.rb', line 91 def name File.basename(@root) end |
#readme? ⇒ Boolean
58 59 60 |
# File 'lib/utopia/project/guide.rb', line 58 def readme? File.exist?(readme_path) end |
#readme_path ⇒ Object
54 55 56 |
# File 'lib/utopia/project/guide.rb', line 54 def readme_path File.(README, @root) end |
#sources ⇒ Object
111 112 113 114 115 116 117 118 119 |
# File 'lib/utopia/project/guide.rb', line 111 def sources return to_enum(:sources) unless block_given? files.each do |path| if source = Decode::Source.for?(path) yield source end end end |
#title ⇒ Object
95 96 97 |
# File 'lib/utopia/project/guide.rb', line 95 def title @title || Trenni::Strings.to_title(self.name) end |