Class: Locomotive::EditorService

Inherits:
Struct
  • Object
show all
Includes:
Concerns::ActivityService
Defined in:
app/services/locomotive/editor_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::ActivityService

#track_activity, #without_tracking_activity

Instance Attribute Details

#accountObject

Returns the value of attribute account

Returns:

  • (Object)

    the current value of account


2
3
4
# File 'app/services/locomotive/editor_service.rb', line 2

def 
  @account
end

#localeObject

Returns the value of attribute locale

Returns:

  • (Object)

    the current value of locale


2
3
4
# File 'app/services/locomotive/editor_service.rb', line 2

def locale
  @locale
end

#pageObject

Returns the value of attribute page

Returns:

  • (Object)

    the current value of page


2
3
4
# File 'app/services/locomotive/editor_service.rb', line 2

def page
  @page
end

#siteObject

Returns the value of attribute site

Returns:

  • (Object)

    the current value of site


2
3
4
# File 'app/services/locomotive/editor_service.rb', line 2

def site
  @site
end

Instance Method Details

#find_resources(type, query, scope = nil, max_results = 10) ⇒ Object

Used by the URL picker to retrieve either a page or a content entry.


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/locomotive/editor_service.rb', line 7

def find_resources(type, query, scope = nil, max_results = 10)
  return [] if type.blank? || query.strip.blank?

  case type
  when 'page'
    find_pages(query, max_results)
  when 'content_entry'
    find_content_entries(scope, query, max_results)
  else
    Rails.logger.warn("[EditorService] Unknown type: #{type}")
    []
  end
end

#save(site_attributes, page_attributes) ⇒ Object

Save sections for both the current site (global versions) and the page


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/locomotive/editor_service.rb', line 22

def save(site_attributes, page_attributes)
  site_attributes[:sections_content] = parse_sections_content(site_attributes[:sections_content])
  site.update_attributes(site_attributes)

  page_attributes[:sections_content]          = parse_sections_content(page_attributes[:sections_content])
  page_attributes[:sections_dropzone_content] = parse_sections_dropzone_content(page_attributes[:sections_dropzone_content])
  page.update_attributes(page_attributes)

  track_activity 'page_content.updated',
    parameters: { _id: page._id, title: page.title },
    locale: locale
end