class Smooster::Deploy::Page
Attributes
filename[RW]
extend Smooster::Deploy::Pages
site_template_id[RW]
extend Smooster::Deploy::Pages
smo_id[RW]
extend Smooster::Deploy::Pages
title[RW]
extend Smooster::Deploy::Pages
url[RW]
extend Smooster::Deploy::Pages
Public Instance Methods
attributes()
click to toggle source
# File lib/smooster/deploy/page.rb, line 10 def attributes {'title' => title, 'filename' => filename, 'site_template_id' => site_template_id, 'smo_id' => smo_id, 'url' => url} end
filename=(filename)
click to toggle source
# File lib/smooster/deploy/page.rb, line 22 def filename=(filename) @filename = sanitize_filename(filename) end
load_smo_id()
click to toggle source
# File lib/smooster/deploy/page.rb, line 18 def load_smo_id store.transaction { store[self.site_template_id][:smo_id] if store[self.site_template_id].present? } end
sanitize_filename(filename)
click to toggle source
# File lib/smooster/deploy/page.rb, line 52 def sanitize_filename(filename) # Split the name when finding a period which is preceded by some # character, and is followed by some character other than a period, # if there is no following period that is followed by something # other than a period (yeah, confusing, I know) fn = filename.split /(?<=.)\.(?=[^.])(?!.*\.[^.])/m # We now have one or two parts (depending on whether we could find # a suitable period). For each of these parts, replace any unwanted # sequence of characters with an underscore fn.map! { |s| s.gsub /[^a-z0-9\-]+/i, '-' } # Finally, join the parts with a period and return the result return fn.join '.' end
save()
click to toggle source
# File lib/smooster/deploy/page.rb, line 46 def save store.transaction do store[self.site_template_id] = {:smo_id => self.smo_id} end end
store()
click to toggle source
# File lib/smooster/deploy/page.rb, line 14 def store Smooster::Application.instance.pages_store end
upload()
click to toggle source
# File lib/smooster/deploy/page.rb, line 26 def upload #return false if self.checksum.to_s == self.load_checksum.to_s if self.smo_id.present? #response = RestClient.put "#{Smooster::Application.instance.api_url()}/#{Smooster::Application.instance.site_id()}/site_templates/#{self.smo_id}", {:site_template => {:body => self.body, :title => self.title}}, {"Authorization" => 'Token token="'+ Smooster::Application.instance.api_key() +'"', "Accept" => 'application/vnd.smoosterid.v2'} else begin response = RestClient.post "#{Smooster::Application.instance.api_url()}/#{Smooster::Application.instance.site_id()}/folders/root/pages", {:page => {:title => self.title, :filename => self.filename, :site_template_id => self.site_template_id, :folder_id => "root"}}, {"Authorization" => 'Token token="'+ Smooster::Application.instance.api_key() +'"', "Accept" => 'application/vnd.smoosterid.v2'} data = JSON.parse(response) self.url = data['url'] self.smo_id = data['smo_id'] self.save rescue => e Smooster::Application.instance.logger.error "Error in page create for #{self.title} / #{self.filename}!: #{e} / #{e.backtrace.inspect}" puts "This page failed to create: #{self.title} / #{self.filename}".colorize(:red) end end end