Class: Cms::DynamicView

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

Direct Known Subclasses

PagePartial, PageTemplate

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_pathObject



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

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

.default_bodyObject



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

def self.default_body
  ""
end

.engineObject

So that route lookup works for these resources. See PathHelper#cms_index_path_for



98
99
100
# File 'app/models/cms/dynamic_view.rb', line 98

def self.engine
  "cms"
end

.find_by_file_name(file_name) ⇒ Object



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

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

.form_nameObject



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

def self.form_name
  ActiveModel::Naming.singular(self)
end

.new_with_defaults(options = {}) ⇒ Object



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

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

.resource_collection_nameObject

Default implementation



92
93
94
# File 'app/models/cms/dynamic_view.rb', line 92

def self.resource_collection_name
  model_name.underscore
end

.resource_nameObject

Get the plural symbol for a particular resource. i.e. Cms::PageTemplate -> :page_templates



87
88
89
# File 'app/models/cms/dynamic_view.rb', line 87

def self.resource_name
  resource_collection_name.pluralize
end

.write_all_to_disk!Object



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

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

Instance Method Details

#display_nameObject



56
57
58
# File 'app/models/cms/dynamic_view.rb', line 56

def display_name
  self.class.display_name(file_name)
end

#file_nameObject



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

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

#remove_file_from_diskObject



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

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

#set_publish_on_saveObject



81
82
83
# File 'app/models/cms/dynamic_view.rb', line 81

def set_publish_on_save
  self.publish_on_save = true
end

#write_file_to_diskObject



60
61
62
63
64
65
# File 'app/models/cms/dynamic_view.rb', line 60

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