Class: Iframe
- Inherits:
-
Content
- Object
- Content
- Iframe
- Defined in:
- app/models/iframe.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
-
#create_config ⇒ Object
Create a new configuration hash if one does not already exist.
-
#load_config ⇒ Object
Load a configuration hash.
- #load_info ⇒ Object
- #render_details ⇒ Object
-
#save_config ⇒ Object
Prepare the configuration to be saved.
-
#set_kind ⇒ Object
Automatically set the kind for the content if it is new.
- #url_must_exist ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'app/models/iframe.rb', line 9 def config @config end |
Class Method Details
.form_attributes ⇒ Object
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_config ⇒ Object
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_config ⇒ Object
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_info ⇒ Object
32 33 |
# File 'app/models/iframe.rb', line 32 def load_info end |
#render_details ⇒ Object
54 55 56 |
# File 'app/models/iframe.rb', line 54 def render_details {:path => self.config['url']} end |
#save_config ⇒ Object
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_kind ⇒ Object
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_exist ⇒ Object
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 |