Class: Rain::Pages

Inherits:
Object
  • Object
show all
Includes:
LowType
Defined in:
lib/pages/pages.rb

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathsObject (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.expand_path("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(**typed_tags)
  results = []

  typed_tags.each do |type, tag|
    results = [*results, *@tags.dig(type, tag)]
  end

  results
end