Class: Pageflow::ThemeCustomizations

Inherits:
Object
  • Object
show all
Defined in:
lib/pageflow/theme_customizations.rb

Overview

Apply account wide customizations to themes of a specific entry type.

Since:

  • 15.7

Instance Method Summary collapse

Instance Method Details

#get(site:, entry_type_name:) ⇒ ThemeCustomization

Get customization for entry type and site.

Returns:

Since:

  • 15.7



36
37
38
39
# File 'lib/pageflow/theme_customizations.rb', line 36

def get(site:, entry_type_name:)
  ThemeCustomization
    .find_or_initialize_by(site: site, entry_type_name: entry_type_name)
end

#preview(site:, entry:, overrides: {}, file_ids: {}) ⇒ PublishedEntry

Construct an entry that uses the given overrides and files in its theme without actually updating the theme customization.

Returns:

Since:

  • 15.7



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pageflow/theme_customizations.rb', line 19

def preview(site:, entry:, overrides: {}, file_ids: {})
  theme_customization =
    ThemeCustomization
    .find_or_initialize_by(site: site, entry_type_name: entry.type_name)

  theme_customization.assign_attributes(overrides: overrides, selected_file_ids: file_ids)

  theme = CustomizedTheme.build(entry: entry,
                                theme: entry.draft.theme,
                                theme_customization: theme_customization)

  PublishedEntry.new(entry, entry.draft, theme: theme)
end

#update(site:, entry_type_name:, overrides: {}, file_ids: {}) ⇒ Object

Override theme options and files for entries of an entry type in a specific site.

Since:

  • 15.7



9
10
11
12
13
# File 'lib/pageflow/theme_customizations.rb', line 9

def update(site:, entry_type_name:, overrides: {}, file_ids: {})
  ThemeCustomization
    .find_or_initialize_by(site: site, entry_type_name: entry_type_name)
    .update!(overrides: overrides, selected_file_ids: file_ids)
end

#upload_file(site:, entry_type_name:, type_name:, attachment:) ⇒ ThemeCustomizationFile

Upload a file that shall be used to customize a theme. Uploading the file does not result in visible changes. Call [#update] and assign a role via the ‘file_ids` parameter.

Returns:

Since:

  • 15.7



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/pageflow/theme_customizations.rb', line 46

def upload_file(site:, entry_type_name:, type_name:, attachment:)
  theme_customization_file =
    ThemeCustomization
    .find_or_create_by(site: site, entry_type_name: entry_type_name)
    .uploaded_files
    .build(type_name: type_name)

  # Assign attachment in separate step to make sure theme
  # customization association (which is used to look up Paperclip
  # styles and validation content type) has already been set when Paperclip runs.
  theme_customization_file.attachment = attachment
  theme_customization_file.save!
  theme_customization_file
end