Class: Template
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Template
- Defined in:
- lib/models/template.rb
Constant Summary collapse
- EXTENSION =
'.php'
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #after_initialize ⇒ Object
- #before_validation ⇒ Object
- #has_file? ⇒ Boolean
- #name ⇒ Object
- #path ⇒ Object
- #preferences ⇒ Object
- #retrieve_file ⇒ Object
- #save_file ⇒ Object
- #save_template_file=(should_save) ⇒ Object
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
6 7 8 |
# File 'lib/models/template.rb', line 6 def file @file end |
Instance Method Details
#after_initialize ⇒ Object
16 17 18 |
# File 'lib/models/template.rb', line 16 def after_initialize retrieve_file end |
#before_validation ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/models/template.rb', line 20 def before_validation self.hits ||= 0 self.template_data ||= "this is the #{self.name} template" self.refresh ||= 'y' self.template_notes ||= "Created by EEFixer" self.save_template_file = 'y' end |
#has_file? ⇒ Boolean
33 34 35 36 37 |
# File 'lib/models/template.rb', line 33 def has_file? save_file = read_attribute(:save_template_file) == 'y' ? true : false save_file = save_file && !self.preferences[:tmpl_file_basepath].blank? save_file end |
#name ⇒ Object
39 40 41 |
# File 'lib/models/template.rb', line 39 def name self.template_name end |
#path ⇒ Object
47 48 49 |
# File 'lib/models/template.rb', line 47 def path File.join(EE_ROOT, self.template_group.group_name, self.template_name) end |
#preferences ⇒ Object
43 44 45 |
# File 'lib/models/template.rb', line 43 def preferences self.site.preferences[:template] end |
#retrieve_file ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/models/template.rb', line 51 def retrieve_file path = EE_ROOT if File.exists?("#{self.path}#{EXTENSION}") @file = File.open("#{self.path}#{EXTENSION}", 'w') unless path.blank? else save_file end rescue save_file end |
#save_file ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/models/template.rb', line 62 def save_file return false if self.new_record? if !File.exists?(File.join(EE_ROOT, self.template_group.group_name)) FileUtils.mkpath(File.join(EE_ROOT, self.template_group.group_name)) end File.open("#{self.path}#{EXTENSION}", 'w') do |f| f.write self.template_data end end |
#save_template_file=(should_save) ⇒ Object
28 29 30 31 |
# File 'lib/models/template.rb', line 28 def save_template_file=(should_save) value = should_save ? 'y' : 'n' write_attribute(:save_template_file, value) end |