Class: Iframe

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



9
10
11
# File 'app/models/iframe.rb', line 9

def config
  @config
end

Class Method Details

.form_attributesObject



42
43
44
45
46
# File 'app/models/iframe.rb', line 42

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

.preview(data) ⇒ Object



58
59
60
61
# File 'app/models/iframe.rb', line 58

def self.preview(data)
  "<iframe style='width: 90%; height: 100%; border: none;' 
    id='iframe-div' src='#{data[:iframe_url]}'></iframe>"
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.



21
22
23
# File 'app/models/iframe.rb', line 21

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`.



28
29
30
# File 'app/models/iframe.rb', line 28

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

#load_infoObject



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

def load_info
end

#render_detailsObject



54
55
56
# File 'app/models/iframe.rb', line 54

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`.



38
39
40
# File 'app/models/iframe.rb', line 38

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.



14
15
16
17
# File 'app/models/iframe.rb', line 14

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

#url_must_existObject



48
49
50
51
52
# File 'app/models/iframe.rb', line 48

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