Class: DynamicView

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/dynamic_view.rb

Direct Known Subclasses

PagePartial, PageTemplate

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_pathObject



43
44
45
# File 'app/models/dynamic_view.rb', line 43

def self.base_path
  File.join(Rails.root, "tmp", "views")
end

.default_bodyObject



72
73
74
# File 'app/models/dynamic_view.rb', line 72

def self.default_body
  ""
end

.find_by_file_name(file_name) ⇒ Object



39
40
41
# File 'app/models/dynamic_view.rb', line 39

def self.find_by_file_name(file_name)
  with_file_name(file_name).first
end

.inherited(subclass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/dynamic_view.rb', line 16

def self.inherited(subclass)
  super if defined? super
ensure
  subclass.class_eval do
    flush_cache_on_change
    is_publishable
    uses_soft_delete
    is_userstamped
    is_versioned :version_foreign_key => "dynamic_view_id"

    before_validation :set_publish_on_save

    validates_presence_of :name, :format, :handler
    validates_uniqueness_of :name, :scope => [:format, :handler],
      :message => "Must have a unique combination of name, format and handler"
                
  end 
end

.new_with_defaults(options = {}) ⇒ Object



35
36
37
# File 'app/models/dynamic_view.rb', line 35

def self.new_with_defaults(options={})
  new({:format => "html", :handler => "erb", :body => default_body}.merge(options))    
end

.write_all_to_disk!Object



62
63
64
# File 'app/models/dynamic_view.rb', line 62

def self.write_all_to_disk!
  all(:conditions => {:deleted => false}).each{|v| v.write_file_to_disk }
end

Instance Method Details

#display_nameObject



51
52
53
# File 'app/models/dynamic_view.rb', line 51

def display_name
  self.class.display_name(file_name)
end

#file_nameObject



47
48
49
# File 'app/models/dynamic_view.rb', line 47

def file_name
  "#{name}.#{format}.#{handler}"
end

#remove_file_from_diskObject



66
67
68
69
70
# File 'app/models/dynamic_view.rb', line 66

def remove_file_from_disk
  if respond_to?(:file_path) && File.exists?(file_path)
    File.delete(file_path)
  end
end

#set_publish_on_saveObject



76
77
78
# File 'app/models/dynamic_view.rb', line 76

def set_publish_on_save
  self.publish_on_save = true
end

#write_file_to_diskObject



55
56
57
58
59
60
# File 'app/models/dynamic_view.rb', line 55

def write_file_to_disk
  if respond_to?(:file_path) && !file_path.blank?
    FileUtils.mkpath(File.dirname(file_path))
    open(file_path, 'w'){|f| f << body}
  end
end