Class: Iframe
- Inherits:
-
Content
- Object
- Content
- Iframe
- Defined in:
- app/models/iframe.rb
Constant Summary collapse
- DISPLAY_NAME =
"IFrame"
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.
11 12 13 |
# File 'app/models/iframe.rb', line 11 def config @config end |
Class Method Details
.form_attributes ⇒ Object
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_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.
23 24 25 |
# File 'app/models/iframe.rb', line 23 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`.
30 31 32 |
# File 'app/models/iframe.rb', line 30 def load_config self.config = JSON.load(self.data) end |
#load_info ⇒ Object
34 35 |
# File 'app/models/iframe.rb', line 34 def load_info end |
#render_details ⇒ Object
56 57 58 |
# File 'app/models/iframe.rb', line 56 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`.
40 41 42 |
# File 'app/models/iframe.rb', line 40 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.
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_exist ⇒ Object
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 |