Class: Iframe

Inherits:
Content
  • Object
show all
Defined in:
app/models/iframe.rb

Constant Summary collapse

DISPLAY_NAME =
"IFrame"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



11
12
13
# File 'app/models/iframe.rb', line 11

def config
  @config
end

Class Method Details

.form_attributesObject



44
45
46
47
48
# File 'app/models/iframe.rb', line 44

def self.form_attributes
  attributes = super()
  # what about  :thumb_url, :title, :description
  attributes.concat([:config => [:url]])
end

Instance Method Details

#create_configObject

Create a new configuration hash if one does not already exist. Called during ‘after_initialize`, where a config may or may not exist.



23
24
25
# File 'app/models/iframe.rb', line 23

def create_config
  self.config = {} if !self.config
end

#load_configObject

Load a configuration hash. Converts the JSON data stored for the content into the configuration. Called during ‘after_find`.



30
31
32
# File 'app/models/iframe.rb', line 30

def load_config
  self.config = JSON.load(self.data)
end

#load_infoObject



34
35
# File 'app/models/iframe.rb', line 34

def load_info
end

#render_detailsObject



56
57
58
# File 'app/models/iframe.rb', line 56

def render_details
  {:path => self.config['url']}
end

#save_configObject

Prepare the configuration to be saved. Compress the config hash back into JSON to be stored in the database. Called during ‘before_valication`.



40
41
42
# File 'app/models/iframe.rb', line 40

def save_config
  self.data = JSON.dump(self.config)
end

#set_kindObject

Automatically set the kind for the content if it is new. We use this hidden type that no fields render so Dynamic Content meta content never gets displayed.



16
17
18
19
# File 'app/models/iframe.rb', line 16

def set_kind
  return unless new_record?
  self.kind = Kind.where(:name => 'Graphics').first
end

#url_must_existObject



50
51
52
53
54
# File 'app/models/iframe.rb', line 50

def url_must_exist
  if config['url'].empty? || (config['url'] =~ /[a-z]+\:\/\/.+/).nil?
    errors.add(:url, 'an absolute Url must be specified')
  end
end