Class: Yuzu::Core::WebsiteFolder

Inherits:
WebsiteBase show all
Defined in:
lib/yuzu/core/website_folder.rb

Direct Known Subclasses

SiteRoot

Instance Attribute Summary

Attributes inherited from WebsiteBase

#kind, #parent, #path

Instance Method Summary collapse

Methods inherited from WebsiteBase

#==, #asset?, #blog_folder, #config, #default_stash, #file?, #folder?, #generated?, #get_link_url, #get_remote_path, #hidden?, #image?, #in_blog?, #index?, #is_blog?, #is_processable?, #link_to_self, #link_url, #processable?, #remote_path, #resource?, #root, #root?, #stash

Constructor Details

#initialize(path, parent) ⇒ WebsiteFolder

Returns a new instance of WebsiteFolder.



5
6
7
8
9
10
11
# File 'lib/yuzu/core/website_folder.rb', line 5

def initialize(path, parent)
  raise "Not a Path object." if not path.is_a?(Path)
  @path = path
  raise "@path is nil for #{self}" if @path.nil?
  @parent = parent
  @kind = :folder
end

Instance Method Details

#all_filesObject



45
46
47
# File 'lib/yuzu/core/website_folder.rb', line 45

def all_files
  @all_files ||= get_all_files
end

#all_processable_childrenArray

Returns all the descendants of this folder, as deep as the tree goes, that are “processable” as specified by the config.

Returns:

  • (Array)

    Of WebsiteFiles representing content that can be translated into HTML or other publishable form.



67
68
69
# File 'lib/yuzu/core/website_folder.rb', line 67

def all_processable_children
  all_files.select {|child| child.processable? and not child.hidden?}
end

#append_child(new_child) ⇒ Object

Add a new child object to the @children. Used by generators to add new files to the existing file-system-gathered pages. This method should only be called in a generator, since their execution is managed in such a way that new children are added at the right stage of processing.

Parameters:

Returns:

  • nothing



83
84
85
86
87
# File 'lib/yuzu/core/website_folder.rb', line 83

def append_child(new_child)
  # Ensure we get the children from disk first.
  children
  @children.push(new_child)
end

TODO Find a way for folders to know what all the categories are, or better yet, remove this interface and have another way of files, folders, and processors to ask information about the entire site. def all_categories end



24
25
26
# File 'lib/yuzu/core/website_folder.rb', line 24

def breadcrumb
  Yuzu::Renderers::BreadcrumbRenderer.new.render(self)
end

#childrenObject

Returns an array of immediate children, files and folders.



72
73
74
# File 'lib/yuzu/core/website_folder.rb', line 72

def children
  @children ||= get_children
end

#currentpathObject



28
29
30
# File 'lib/yuzu/core/website_folder.rb', line 28

def currentpath
  Yuzu::Filters::CurrentpathFilter.new.value(self)
end

#filesObject



37
38
39
# File 'lib/yuzu/core/website_folder.rb', line 37

def files
  @files ||= children.select {|child| child.file?}
end

#folder_contentsObject



113
114
115
# File 'lib/yuzu/core/website_folder.rb', line 113

def folder_contents
  @path.children
end

#foldersObject



41
42
43
# File 'lib/yuzu/core/website_folder.rb', line 41

def folders
  @folders ||= children.select {|child| child.folder?}
end

#get_all_filesObject



49
50
51
52
53
54
55
56
# File 'lib/yuzu/core/website_folder.rb', line 49

def get_all_files
  v = Visitor.new(proc {|c| c.file?})
  tr = []
  v.traverse(self) do |website_file|
    tr.push(website_file)
  end
  tr
end

#get_child_by_basename(basename) ⇒ Object



131
132
133
134
135
136
# File 'lib/yuzu/core/website_folder.rb', line 131

def get_child_by_basename(basename)
  children.each do |child|
    return child if child.path.basename == basename
  end
  nil
end

#get_child_by_filename(filename) ⇒ Object



138
139
140
141
142
143
# File 'lib/yuzu/core/website_folder.rb', line 138

def get_child_by_filename(filename)
  children.each do |child|
    return child if child.path.filename == filename
  end
  nil
end

#get_child_by_path(path) ⇒ Object



117
118
119
120
121
122
# File 'lib/yuzu/core/website_folder.rb', line 117

def get_child_by_path(path)
  children.each do |child|
    return child if child.path == path
  end
  nil
end

#get_child_by_rootname(rootname) ⇒ Object



124
125
126
127
128
129
# File 'lib/yuzu/core/website_folder.rb', line 124

def get_child_by_rootname(rootname)
  children.each do |child|
    return child if child.path.rootname == rootname
  end
  nil
end

#get_childrenObject



89
90
91
92
# File 'lib/yuzu/core/website_folder.rb', line 89

def get_children
  tr = folder_contents.collect { |child_path| get_object_for_path(child_path) }
  tr.reject {|c| c.nil?}
end

#get_has_indexObject



165
166
167
168
169
170
171
172
# File 'lib/yuzu/core/website_folder.rb', line 165

def get_has_index
  child_names = files.collect do |file|
    filename = file.filename
    ext = File.extname(filename)
    filename.sub(ext, "")
  end
  child_names.include?("index")
end

#get_object_for_path(path) ⇒ WebsiteFile, ...

Returns a WebsiteFile or WebsiteFolder for the given path.

Parameters:

  • path (Path)

    The Path object representing the on-disk file or folder.

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/yuzu/core/website_folder.rb', line 98

def get_object_for_path(path)
  # TODO Add different file types: processable, resource, etc.

  if path.file?
    WebsiteFile.new(path, self)

  elsif path.folder?
    WebsiteFolder.new(path, self)

  else
    # ignore
    nil
  end
end

#has_index?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/yuzu/core/website_folder.rb', line 161

def has_index?
  @has_index ||= get_has_index
end

#is_child?(web_obj) ⇒ Boolean

Returns:

  • (Boolean)


149
150
151
152
153
154
155
156
157
158
159
# File 'lib/yuzu/core/website_folder.rb', line 149

def is_child?(web_obj)
  folders_only = proc {|c| c.folder?}
  tr = self.is_immediate_child?(web_obj)
  return true if tr

  v = Visitor.new(folders_only)
  v.traverse(self) do |website_folder|
    tr ||= website_folder.is_immediate_child?(web_obj)
  end
  tr
end

#is_immediate_child?(web_obj) ⇒ Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/yuzu/core/website_folder.rb', line 145

def is_immediate_child?(web_obj)
  children.include?(web_obj)
end

#nameObject




33
34
35
# File 'lib/yuzu/core/website_folder.rb', line 33

def name
  @path.rootname.titlecase
end

#processable_childrenObject



58
59
60
# File 'lib/yuzu/core/website_folder.rb', line 58

def processable_children
  children.select {|child| child.processable?}
end

#to_sObject



13
14
15
# File 'lib/yuzu/core/website_folder.rb', line 13

def to_s
  "WebsiteFolder(#{@path})"
end