Class: Utopia::Content::Links::Resolver
- Inherits:
-
Object
- Object
- Utopia::Content::Links::Resolver
- Defined in:
- lib/utopia/content/links.rb
Overview
Represents a list of Utopia::Content::Link instances relating to the structure of the content. They are formed from the links.yaml file and the actual directory structure on disk.
Instance Attribute Summary collapse
-
#named ⇒ Object
readonly
Returns the value of attribute named.
-
#ordered ⇒ Object
readonly
Returns the value of attribute ordered.
-
#top ⇒ Object
readonly
Returns the value of attribute top.
Instance Method Summary collapse
-
#each(locale) ⇒ Object
Enumerate the contained values.
-
#indices ⇒ Object
Select index-document links.
-
#initialize(links, top = Path.root) ⇒ Resolver
constructor
Resolve and order links from a content directory and its metadata.
-
#lookup(name, locale = nil, fallback: true) ⇒ Object
Lookup.
Constructor Details
#initialize(links, top = Path.root) ⇒ Resolver
Resolve and order links from a content directory and its metadata.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/utopia/content/links.rb', line 166 def initialize(links, top = Path.root) raise ArgumentError.new("top path must be absolute") unless top.absolute? @links = links @top = top # top.components.first == '', but this isn't a problem here. @path = File.join(links.root, top.components) @ordered = [] @named = {} if File.directory?(@path) @metadata = links.(@path) load_links(@metadata.dup) do |link| @ordered << link (@named[link.name] ||= []) << link end else @metadata = nil end end |
Instance Attribute Details
#named ⇒ Object (readonly)
Returns the value of attribute named.
193 194 195 |
# File 'lib/utopia/content/links.rb', line 193 def named @named end |
#ordered ⇒ Object (readonly)
Returns the value of attribute ordered.
192 193 194 |
# File 'lib/utopia/content/links.rb', line 192 def ordered @ordered end |
#top ⇒ Object (readonly)
Returns the value of attribute top.
191 192 193 |
# File 'lib/utopia/content/links.rb', line 191 def top @top end |
Instance Method Details
#each(locale) ⇒ Object
Enumerate the contained values.
204 205 206 207 208 209 210 |
# File 'lib/utopia/content/links.rb', line 204 def each(locale) return to_enum(:each, locale) unless block_given? ordered.each do |links| yield links.find{|link| link.locale == locale} end end |
#indices ⇒ Object
Select index-document links.
197 198 199 |
# File 'lib/utopia/content/links.rb', line 197 def indices return @ordered.select{|link| link.index?} end |
#lookup(name, locale = nil, fallback: true) ⇒ Object
Lookup.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/utopia/content/links.rb', line 217 def lookup(name, locale = nil, fallback: true) # This allows generic links to serve any locale requested. if links = @named[name] generic_link = nil links.each do |link| if link.locale == locale return link elsif fallback && link.locale.nil? generic_link = link end end return generic_link end end |