Class: Pageflow::ThemeCustomizations
- Inherits:
-
Object
- Object
- Pageflow::ThemeCustomizations
- Defined in:
- lib/pageflow/theme_customizations.rb
Overview
Apply account wide customizations to themes of a specific entry type.
Instance Method Summary collapse
-
#get(site:, entry_type_name:) ⇒ ThemeCustomization
Get customization for entry type and site.
-
#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.
-
#update(site:, entry_type_name:, overrides: {}, file_ids: {}) ⇒ Object
Override theme options and files for entries of an entry type in a specific site.
-
#upload_file(site:, entry_type_name:, type_name:, attachment:) ⇒ ThemeCustomizationFile
Upload a file that shall be used to customize a theme.
Instance Method Details
#get(site:, entry_type_name:) ⇒ ThemeCustomization
Get customization for entry type and site.
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.
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.
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.
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. = theme_customization_file.save! theme_customization_file end |