Class: Caboose::Site
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Caboose::Site
- Defined in:
- app/models/caboose/site.rb
Class Method Summary collapse
Instance Method Summary collapse
- #custom_css ⇒ Object
- #custom_css=(str) ⇒ Object
- #custom_css_url ⇒ Object
- #custom_js ⇒ Object
- #custom_js=(str) ⇒ Object
- #custom_js_url ⇒ Object
- #default_layout ⇒ Object
- #primary_domain ⇒ Object
- #retargeting_config ⇒ Object
- #smtp_config ⇒ Object
- #social_config ⇒ Object
Class Method Details
.id_for_domain(domain) ⇒ Object
46 47 48 49 50 |
# File 'app/models/caboose/site.rb', line 46 def self.id_for_domain(domain) d = Caboose::Domain.where(:domain => domain).first return nil if d.nil? return d.site_id end |
.sanitize_name(name) ⇒ Object
52 53 54 |
# File 'app/models/caboose/site.rb', line 52 def self.sanitize_name(name) self.name = self.name.downcase.gsub(' ', '_') end |
Instance Method Details
#custom_css ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'app/models/caboose/site.rb', line 81 def custom_css resp = HTTParty.get(self.custom_css_url) if resp.nil? || resp.code.to_i == 403 self.custom_css = "" return "" end return resp.body end |
#custom_css=(str) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'app/models/caboose/site.rb', line 99 def custom_css=(str) config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key']) bucket = AWS::S3.new.buckets[config['bucket']] bucket.objects["assets/#{self.name}/css/custom.css"].write(str, :acl => 'public-read') self.date_css_updated = DateTime.now.utc self.save end |
#custom_css_url ⇒ Object
66 67 68 69 70 |
# File 'app/models/caboose/site.rb', line 66 def custom_css_url url = "http://#{Caboose::cdn_domain}/assets/#{self.name}/css/custom.css" url << "?#{self.date_css_updated.strftime('%Y%m%d%H%M%S')}" if self.date_css_updated return url end |
#custom_js ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/models/caboose/site.rb', line 72 def custom_js resp = HTTParty.get(self.custom_js_url) if resp.nil? || resp.code.to_i == 403 self.custom_js = "" return "" end return resp.body end |
#custom_js=(str) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/models/caboose/site.rb', line 90 def custom_js=(str) config = YAML.load(File.read(Rails.root.join('config', 'aws.yml')))[Rails.env] AWS.config(:access_key_id => config['access_key_id'], :secret_access_key => config['secret_access_key']) bucket = AWS::S3.new.buckets[config['bucket']] bucket.objects["assets/#{self.name}/js/custom.js"].write(str, :acl => 'public-read') self.date_js_updated = DateTime.now.utc self.save end |
#custom_js_url ⇒ Object
60 61 62 63 64 |
# File 'app/models/caboose/site.rb', line 60 def custom_js_url url = "http://#{Caboose::cdn_domain}/assets/#{self.name}/js/custom.js" url << "?#{self.date_js_updated.strftime('%Y%m%d%H%M%S')}" if self.date_js_updated return url end |
#default_layout ⇒ Object
23 24 25 26 |
# File 'app/models/caboose/site.rb', line 23 def default_layout return Caboose::BlockType.where(:id => self.default_layout_id).first if self.default_layout_id return Caboose::BlockType.where(:name => 'layout_basic').first end |
#primary_domain ⇒ Object
56 57 58 |
# File 'app/models/caboose/site.rb', line 56 def primary_domain Caboose::Domain.where(:site_id => self.id, :primary => true).first end |
#retargeting_config ⇒ Object
40 41 42 43 44 |
# File 'app/models/caboose/site.rb', line 40 def retargeting_config c = Caboose::RetargetingConfig.where(:site_id => self.id).first c = Caboose::RetargetingConfig.create(:site_id => self.id) if c.nil? return c end |
#smtp_config ⇒ Object
28 29 30 31 32 |
# File 'app/models/caboose/site.rb', line 28 def smtp_config c = Caboose::SmtpConfig.where(:site_id => self.id).first c = Caboose::SmtpConfig.create(:site_id => self.id) if c.nil? return c end |
#social_config ⇒ Object
34 35 36 37 38 |
# File 'app/models/caboose/site.rb', line 34 def s = Caboose::SocialConfig.where(:site_id => self.id).first s = Caboose::SocialConfig.create(:site_id => self.id) if s.nil? return s end |