Class: Newsletter::Element
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Newsletter::Element
- Includes:
- Deleteable
- Defined in:
- app/models/newsletter/element.rb
Class Method Summary collapse
-
.import(design, data) ⇒ Object
builds areas from data pulled out of an exported YAML file by Newsletter::Design.import(class).
Instance Method Summary collapse
-
#export_fields ⇒ Object
returns field data so that Newsletter::Design.export(instance) can export itself to a YAML file.
-
#file_path(this_name = nil) ⇒ Object
defines where the file is in the filesystem.
-
#html_text ⇒ Object
retrieves the html erb design from the file system.
-
#html_text=(text) ⇒ Object
sets and saves the html erb design to update the file after a successful save.
-
#name=(new_name) ⇒ Object
used to record old name of an element such that the design can be moved to the new name.
-
#name_as_path(this_name = nil) ⇒ Object
returns a version of name that is nice for filesytem use.
- #save(*args) ⇒ Object
-
#view_path(this_name = nil) ⇒ Object
defines the design path for the element as used in a render :partial => (without ‘_’).
Methods included from Deleteable
#delete, included, #is_deleted?, #undelete
Class Method Details
.import(design, data) ⇒ Object
builds areas from data pulled out of an exported YAML file by Newsletter::Design.import(class)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'app/models/newsletter/element.rb', line 75 def self.import(design,data) element = Element.new(:name => data[:name], :html_text => data[:html_text], :description => data[:description]) element.design = design element.save data[:areas].each do |area_data| element.areas << Area.find_all_by_design_id_and_name(design.id,area_data[:name]) end data[:fields].each do |field_data| Field.import(element,field_data) end end |
Instance Method Details
#export_fields ⇒ Object
returns field data so that Newsletter::Design.export(instance) can export itself to a YAML file
65 66 67 68 69 70 71 72 |
# File 'app/models/newsletter/element.rb', line 65 def export_fields { :name => name, :description => description, :html_text => html_text, :areas => areas.collect{|area| area.export_fields}, :fields => fields.collect{|field| field.export_fields} } end |
#file_path(this_name = nil) ⇒ Object
defines where the file is in the filesystem
42 43 44 |
# File 'app/models/newsletter/element.rb', line 42 def file_path(this_name=nil) File.dirname(view_path(this_name)) + '/_' + File.basename(view_path(this_name)) end |
#html_text ⇒ Object
retrieves the html erb design from the file system
54 55 56 57 |
# File 'app/models/newsletter/element.rb', line 54 def html_text return @html_text if @html_text @html_text = read_design end |
#html_text=(text) ⇒ Object
sets and saves the html erb design to update the file after a successful save
60 61 62 |
# File 'app/models/newsletter/element.rb', line 60 def html_text=(text) @html_text = text end |
#name=(new_name) ⇒ Object
used to record old name of an element such that the design can be moved to the new name
47 48 49 50 51 |
# File 'app/models/newsletter/element.rb', line 47 def name=(new_name) return if self[:name].eql?(new_name) @old_name = self[:name] unless @old_name self[:name] = new_name end |
#name_as_path(this_name = nil) ⇒ Object
returns a version of name that is nice for filesytem use
36 37 38 39 |
# File 'app/models/newsletter/element.rb', line 36 def name_as_path(this_name=nil) this_name = name unless this_name this_name.gsub(/[^a-zA-Z0-9-]/,'_').downcase end |
#save(*args) ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/models/newsletter/element.rb', line 90 def save(*args) transaction do move_design_on_name_change write_design super end end |
#view_path(this_name = nil) ⇒ Object
defines the design path for the element as used in a render :partial => (without ‘_’)
30 31 32 33 |
# File 'app/models/newsletter/element.rb', line 30 def view_path(this_name=nil) this_name = self[:name] unless this_name "#{::Newsletter.designs_path}/designs/#{design.name.gsub(/[^a-zA-Z0-9-]/,'_')}/elements/#{name_as_path(this_name)}.html.erb" end |