Class: Rain::Pages
Defined Under Namespace
Classes: Page
Instance Attribute Summary collapse
-
#url_paths ⇒ Object
readonly
Returns the value of attribute url_paths.
Instance Method Summary collapse
-
#initialize(metadata:) ⇒ Pages
constructor
A new instance of Pages.
- #list(file_paths:) ⇒ 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['md'], *.file_types['markdown']] @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 |
Instance Method Details
#list(file_paths:) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/pages/pages.rb', line 32 def list(file_paths:) sorted_paths = file_paths.sort_by { order(it) } sorted_paths.map do |file_path| , markdown = parse_file(file_path:) [:content] = markdown.empty? ? '' : Raindown.render(markdown:) OpenStruct.new() end end |
#page(path:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pages/pages.rb', line 21 def page(path:) path = '/home' if path == '/' url_path = File.("app/pages#{path}", Dir.pwd) file_path = @url_paths[url_path] || return , markdown = parse_file(file_path:) raindown = Raindown.render(markdown:) Page.new(, raindown) end |
#tagged(**typed_tags) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/pages/pages.rb', line 42 def tagged(**) results = [] .each do |type, tag| results = [*results, *@tags.dig(type, tag)] end results end |