Class: Landable::PageRevision
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Landable::PageRevision
- Defined in:
- app/models/landable/page_revision.rb
Constant Summary collapse
- @@ignored_page_attributes =
[ 'page_id', 'imported_at', 'created_at', 'deleted_at', 'updated_at', 'published_revision_id', 'is_publishable', 'updated_by_author_id', 'lock_version', 'audit_flags', 'page_name' ]
Instance Method Summary collapse
- #add_screenshot! ⇒ Object
- #page_id=(id) ⇒ Object
- #preview_path ⇒ Object
- #preview_url ⇒ Object
- #publish! ⇒ Object
- #republish!(options) ⇒ Object
- #screenshot_url ⇒ Object
- #snapshot ⇒ Object
- #unpublish! ⇒ Object
Instance Method Details
#add_screenshot! ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'app/models/landable/page_revision.rb', line 109 def add_screenshot! return nil if preview_url.blank? unless Landable.configuration.screenshots_enabled Rails.logger.info "Screenshots disabled; skipping for #{path}" return end attempts_left = 3 begin attempts_left -= 1 self.screenshot = ScreenshotService.capture(preview_url) # we've got a trigger preventing updates to other columns, so! muck # about under the hood to commit the asset, and explicitly only update # this column. store_screenshot! write_screenshot_identifier update_column :screenshot, self[:screenshot] rescue ScreenshotService::Error => error Rails.logger.warn "Failed to generate screenshot (#{attempts_left} attempt(s) left) for #{path}: #{error.inspect}" retry if attempts_left > 0 end end |
#page_id=(id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/landable/page_revision.rb', line 30 def page_id=(id) # set the value self[:page_id] = id # copy grab attributes from the page self.title = page.title self.body = page.body self.head_content = page.head_content self.path = page.path self.status_code = page.status_code self.category_id = page.category_id self.theme_id = page.theme_id self. = page. self.redirect_url = page.redirect_url self.abstract = page.abstract self.hero_asset_id = page.hero_asset_id end |
#preview_path ⇒ Object
99 100 101 |
# File 'app/models/landable/page_revision.rb', line 99 def preview_path public_preview_page_revision_path(self) end |
#preview_url ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/models/landable/page_revision.rb', line 90 def preview_url begin public_preview_page_revision_url(self, host: Landable.configuration.public_host) rescue ArgumentError Rails.logger.warn "Failed to generate preview url for page revision #{id} - missing Landable.configuration.public_host" nil end end |
#publish! ⇒ Object
62 63 64 |
# File 'app/models/landable/page_revision.rb', line 62 def publish! update_attribute :is_published, true end |
#republish!(options) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/landable/page_revision.rb', line 70 def republish!() unpublish! PageRevision.create!(page_id: self.page_id, title: self.title, meta_tags: page., head_content: page.head_content, body: self.body, path: self.path, redirect_url: self.redirect_url, status_code: self.status_code, theme_id: self.theme_id, category_id: self.category_id, abstract: self.abstract, hero_asset_id: self.hero_asset_id, notes: "Publishing update for template #{[:template]}: #{[:notes]}", is_minor: [:is_minor], author_id: [:author_id], is_published: true) end |
#screenshot_url ⇒ Object
105 106 107 |
# File 'app/models/landable/page_revision.rb', line 105 def screenshot_url screenshot.try(:url) end |
#snapshot ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/landable/page_revision.rb', line 48 def snapshot Page.new(title: self.title, meta_tags: page., head_content: page.head_content, body: self.body, path: self.path, redirect_url: self.redirect_url, status_code: self.status_code, theme_id: self.theme_id, category_id: self.category_id, abstract: self.abstract, hero_asset_id: self.hero_asset_id) end |
#unpublish! ⇒ Object
66 67 68 |
# File 'app/models/landable/page_revision.rb', line 66 def unpublish! update_attribute :is_published, false end |