Class: Utopia::Content::Links
- Inherits:
-
Object
- Object
- Utopia::Content::Links
- Defined in:
- lib/utopia/content/links.rb
Defined Under Namespace
Classes: Resolved
Constant Summary collapse
- XNODE_FILTER =
/^(.+)#{Regexp.escape XNODE_EXTENSION}$/
- INDEX_XNODE_FILTER =
/^(index(\..+)*)#{Regexp.escape XNODE_EXTENSION}$/
- DEFAULT_INDEX_OPTIONS =
{ :directories => true, :files => true, :virtuals => true, :indices => false, :sort => :order, :display => :display, }
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #for(path, locale = nil) ⇒ Object
- #index(path, **options) ⇒ Object
-
#initialize(root) ⇒ Links
constructor
A new instance of Links.
- #metadata(path) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
106 107 108 |
# File 'lib/utopia/content/links.rb', line 106 def root @root end |
Class Method Details
Instance Method Details
#for(path, locale = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/utopia/content/links.rb', line 52 def for(path, locale = nil) links = Resolved.new(self, path.dirname) links.lookup(path.last, locale) end |
#index(path, **options) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/utopia/content/links.rb', line 67 def index(path, **) = DEFAULT_INDEX_OPTIONS.merge() ordered = Resolved.new(self, path, ).ordered # This option filters a link based on the display parameter. if display_key = [:display] ordered.reject!{|link| link.info[display_key] == false} end # Named: if name = [:name] # We use pattern === name, which matches either the whole string, or matches a regexp. ordered.select!{|link| name === link.name} end if locale = [:locale] locales = {} ordered.each do |link| if link.locale == locale locales[link.name] = link elsif link.locale == nil locales[link.name] ||= link end end ordered = locales.values end # Sort: if sort_key = [:sort] # Sort by sort_key, otherwise by title. ordered.sort_by!{|link| [link[sort_key] || [:sort_default] || 0, link.title]} end return ordered end |
#metadata(path) ⇒ Object
240 241 242 243 244 |
# File 'lib/utopia/content/links.rb', line 240 def (path) @cache.fetch_or_store(path.to_s) do load(path).freeze end end |