Class: Rain::Pages
Defined Under Namespace
Classes: Page
Instance Attribute Summary collapse
-
#url_paths ⇒ Object
readonly
Returns the value of attribute url_paths.
Class Method Summary collapse
- .pages_path ⇒ Object
-
.url_path(file_path:) ⇒ Object
Remove segments beginning with "_" and ending with "&", "-" or "/".
Instance Method Summary collapse
-
#initialize(metadata:) ⇒ Pages
constructor
A new instance of Pages.
- #list(**typed_tags) ⇒ Object
- #page(path:) ⇒ Object
- #tagged(**typed_tags) ⇒ Object
Constructor Details
#initialize(metadata:) ⇒ Pages
Returns a new instance of Pages.
13 14 15 16 17 18 19 |
# File 'lib/pages/pages.rb', line 13 def initialize(metadata:) @file_paths = .file_types.values_at('md', 'rd', 'markdown', 'raindown').flat_map { it }.compact @url_paths = {} @tags = {} process_files end |
Instance Attribute Details
#url_paths ⇒ Object (readonly)
Returns the value of attribute url_paths.
9 10 11 |
# File 'lib/pages/pages.rb', line 9 def url_paths @url_paths end |
Class Method Details
.pages_path ⇒ Object
134 135 136 |
# File 'lib/pages/pages.rb', line 134 def pages_path File.('app/pages', Dir.pwd) end |
.url_path(file_path:) ⇒ Object
Remove segments beginning with "_" and ending with "&", "-" or "/". Example: app/pages/docs/_basics/_1-getting-started.md => app/pages/docs/getting-started.md
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pages/pages.rb', line 123 def url_path(file_path:) url_path = file_path.split(Regexp.union(['/', '&'])).map do |segment| next segment.sub(/^_\d\W/, '') if segment.sub(/^_\d\W/, '') != segment next nil if segment.sub(/^_/, '') != segment segment end.compact.join('/') url_path.delete_prefix(pages_path).delete_suffix(File.extname(url_path)) end |
Instance Method Details
#list(**typed_tags) ⇒ Object
31 32 33 34 35 |
# File 'lib/pages/pages.rb', line 31 def list(**) file_paths = tagged(**) sorted_paths = file_paths.sort_by { order(it) } sorted_paths.map { |file_path| present_file(file_path:) } end |
#page(path:) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/pages/pages.rb', line 21 def page(path:) path = '/home' if path == '/' file_path = @url_paths[path] || return , markdown = parse_file(file_path:) raindown = Raindown.render(markdown:) Page.new(, raindown) end |
#tagged(**typed_tags) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/pages/pages.rb', line 37 def tagged(**) file_paths = [] .each do |type, tag| file_paths = [*file_paths, *@tags.dig(type, tag)] end file_paths end |