| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  | class Design | 
					
						
							|  |  |  |   include Mongoid::Document | 
					
						
							|  |  |  |   include Mongoid::Timestamps | 
					
						
							| 
									
										
										
										
											2012-04-06 09:31:22 +00:00
										 |  |  |   include ParserLayout | 
					
						
							| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-05 13:20:20 +00:00
										 |  |  |   field :author, :type => String | 
					
						
							|  |  |  |   field :intro, :type => String | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |   field :title, :type => String | 
					
						
							| 
									
										
										
										
											2012-05-05 13:20:20 +00:00
										 |  |  |   field :version, :type => String | 
					
						
							| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-05 15:04:54 +00:00
										 |  |  |   has_one :css_default, as: :css, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |   has_one :layout, :autosave => true, :dependent => :destroy | 
					
						
							|  |  |  |   has_one :css_reset, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2012-11-20 02:04:50 +00:00
										 |  |  |   has_many :images, as: :imgs, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2012-11-05 15:04:54 +00:00
										 |  |  |   has_many :javascripts, as: :js, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2011-08-22 05:45:21 +00:00
										 |  |  |   has_many :pages | 
					
						
							| 
									
										
										
										
											2012-11-20 04:46:50 +00:00
										 |  |  |   has_many :themes, :autosave => true, :dependent => :destroy | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   accepts_nested_attributes_for :images, :allow_destroy => true | 
					
						
							|  |  |  |   accepts_nested_attributes_for :javascripts, :allow_destroy => true | 
					
						
							|  |  |  |   accepts_nested_attributes_for :themes, :allow_destroy => true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   validates_presence_of :author, :title | 
					
						
							| 
									
										
										
										
											2011-09-05 08:06:17 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2012-02-24 11:11:51 +00:00
										 |  |  |   after_save :parse_css_for_images | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-08 09:23:20 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2011-12-23 10:34:21 +00:00
										 |  |  |   def new_files=(*attrs) | 
					
						
							|  |  |  |     attrs[0].map  do |key,items_ary|   #Loop by JSs,Themes,Imgs | 
					
						
							|  |  |  |         self.files=([items_ary, key]) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  |   | 
					
						
							| 
									
										
										
										
											2012-01-26 04:05:25 +00:00
										 |  |  |   # def javascripts=(*attrs) | 
					
						
							|  |  |  |   #   self.files = (attrs << 'javascripts') | 
					
						
							|  |  |  |   # end | 
					
						
							|  |  |  |   #  | 
					
						
							|  |  |  |   # def themes=(*attrs) | 
					
						
							|  |  |  |   #   self.files = (attrs << 'themes') | 
					
						
							|  |  |  |   # end | 
					
						
							|  |  |  |   #  | 
					
						
							|  |  |  |   # def images=(*attrs) | 
					
						
							|  |  |  |   #   self.files = (attrs << 'images') | 
					
						
							|  |  |  |   # end | 
					
						
							| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2011-12-23 10:34:21 +00:00
										 |  |  |   # Update or create the attribute records | 
					
						
							| 
									
										
										
										
											2011-07-14 00:48:42 +00:00
										 |  |  |   def files=(attrs) | 
					
						
							| 
									
										
										
										
											2011-08-08 09:23:20 +00:00
										 |  |  |     case attrs.last | 
					
						
							| 
									
										
										
										
											2011-09-08 10:12:04 +00:00
										 |  |  |       when 'layout' | 
					
						
							|  |  |  |         files = self.layout.build | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         files = eval(attrs.last) | 
					
						
							| 
									
										
										
										
											2011-08-08 09:23:20 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-07-14 00:48:42 +00:00
										 |  |  |     attrs[0].each do |a| | 
					
						
							| 
									
										
										
										
											2011-12-23 10:34:21 +00:00
										 |  |  |         | 
					
						
							| 
									
										
										
										
											2011-09-08 10:12:04 +00:00
										 |  |  |       if a[:id].blank? && !a[:file].blank? | 
					
						
							|  |  |  |         files.build(:file => a[:file], :to_save => true) | 
					
						
							| 
									
										
										
										
											2011-07-22 07:54:38 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         files.each do |file| | 
					
						
							|  |  |  |           if file.id.to_s == a[:id] | 
					
						
							| 
									
										
										
										
											2011-07-26 10:22:17 +00:00
										 |  |  |              file.to_destroy = a[:to_destroy] | 
					
						
							| 
									
										
										
										
											2011-07-22 07:54:38 +00:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2011-07-22 03:10:14 +00:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-07-14 00:48:42 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   protected | 
					
						
							| 
									
										
										
										
											2011-09-01 11:08:45 +00:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2012-01-26 04:05:25 +00:00
										 |  |  |   def parse_css_for_images | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |     self.css_default.parse_urls | 
					
						
							| 
									
										
										
										
											2012-01-26 04:05:25 +00:00
										 |  |  |     self.themes.each do |theme| | 
					
						
							| 
									
										
										
										
											2012-10-24 10:40:38 +00:00
										 |  |  |       theme.parse_urls | 
					
						
							| 
									
										
										
										
											2011-09-01 11:08:45 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-04-06 09:31:22 +00:00
										 |  |  |     parse_body_for_images(self) | 
					
						
							| 
									
										
										
										
											2011-09-01 11:08:45 +00:00
										 |  |  |   end | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2011-07-12 08:02:41 +00:00
										 |  |  | end |