Class: Landable::PageRevision
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Landable::PageRevision
- Defined in:
- app/models/landable/page_revision.rb
Class Attribute Summary collapse
-
.ignored_page_attributes ⇒ Object
Returns the value of attribute ignored_page_attributes.
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
Class Attribute Details
.ignored_page_attributes ⇒ Object
Returns the value of attribute ignored_page_attributes.
10 11 12 |
# File 'app/models/landable/page_revision.rb', line 10 def ignored_page_attributes @ignored_page_attributes end |
Instance Method Details
#add_screenshot! ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/models/landable/page_revision.rb', line 96 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/landable/page_revision.rb', line 19 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
86 87 88 |
# File 'app/models/landable/page_revision.rb', line 86 def preview_path public_preview_page_revision_path(self) end |
#preview_url ⇒ Object
79 80 81 82 83 84 |
# File 'app/models/landable/page_revision.rb', line 79 def preview_url 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 |
#publish! ⇒ Object
51 52 53 |
# File 'app/models/landable/page_revision.rb', line 51 def publish! update_attribute :is_published, true end |
#republish!(options) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/landable/page_revision.rb', line 59 def republish!() unpublish! PageRevision.create!(page_id: page_id, title: title, meta_tags: page., head_content: page.head_content, body: body, path: path, redirect_url: redirect_url, status_code: status_code, theme_id: theme_id, category_id: category_id, abstract: abstract, hero_asset_id: 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
92 93 94 |
# File 'app/models/landable/page_revision.rb', line 92 def screenshot_url screenshot.try(:url) end |
#snapshot ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/models/landable/page_revision.rb', line 37 def snapshot Page.new(title: title, meta_tags: page., head_content: page.head_content, body: body, path: path, redirect_url: redirect_url, status_code: status_code, theme_id: theme_id, category_id: category_id, abstract: abstract, hero_asset_id: hero_asset_id) end |
#unpublish! ⇒ Object
55 56 57 |
# File 'app/models/landable/page_revision.rb', line 55 def unpublish! update_attribute :is_published, false end |