Class: Locomotive::Steam::PageRepository
- Inherits:
-
Object
- Object
- Locomotive::Steam::PageRepository
show all
- Includes:
- Models::Repository
- Defined in:
- lib/locomotive/steam/repositories/page_repository.rb
Instance Attribute Summary
#adapter, #local_conditions, #scope
Instance Method Summary
collapse
#base_url, #build, #count, #create, #delete, #find, #first, #i18n_value_of, #inc, #initialize, #initialize_copy, #k, #last, #mapper, #prepare_conditions, #query, #update
Instance Method Details
#all(conditions = {}) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 15
def all(conditions = {})
query do
where(conditions || {}).
order_by(depth: :asc, position: :asc)
end.all
end
|
#ancestors_of(page) ⇒ Object
68
69
70
71
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 68
def ancestors_of(page)
return [] if page.nil?
all(k(:_id, :in) => page.parent_ids + [page._id])
end
|
#by_fullpath(path) ⇒ Object
40
41
42
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 40
def by_fullpath(path)
first { where(fullpath: path) }
end
|
#by_handle(handle) ⇒ Object
36
37
38
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 36
def by_handle(handle)
first { where(handle: handle) }
end
|
#children_of(page) ⇒ Object
73
74
75
76
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 73
def children_of(page)
return [] if page.nil?
all(parent_id: page._id)
end
|
#editable_element_for(page, block, slug) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 83
def editable_element_for(page, block, slug)
return nil if page.nil? || page.editable_elements.nil?
page.editable_elements.first do
where(block: block, slug: slug)
end
end
|
#editable_elements_of(page) ⇒ Object
78
79
80
81
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 78
def editable_elements_of(page)
return nil if page.nil?
page.editable_elements
end
|
#matching_fullpath(list) ⇒ Object
44
45
46
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 44
def matching_fullpath(list)
all(k(:fullpath, :in) => list)
end
|
#only_handle_and_fullpath ⇒ Object
29
30
31
32
33
34
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 29
def only_handle_and_fullpath
query do
where(k(:handle, :ne) => nil).
only(:_id, :title, :handle, :fullpath)
end.all.tap { mapper.reset_entity_map }
end
|
#parent_of(page) ⇒ Object
62
63
64
65
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 62
def parent_of(page)
return nil if page.nil? || page.index?
first { where(_id: page.parent_id) }
end
|
#published ⇒ Object
22
23
24
25
26
27
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 22
def published
query do
where(published: true).
order_by(depth: :asc, position: :asc)
end.all
end
|
#root ⇒ Object
58
59
60
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 58
def root
first { where(fullpath: 'index') }
end
|
#template_for(entry, handle = nil) ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/locomotive/steam/repositories/page_repository.rb', line 48
def template_for(entry, handle = nil)
conditions = { templatized: true, target_klass_name: entry.try(:_class_name) }
conditions[:handle] = handle if handle
all(conditions).first.tap do |page|
page.content_entry = entry if page
end
end
|