Module: Sheet::Instance

Included in:
JavascriptPage, StylesheetPage
Defined in:
app/models/sheet.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/sheet.rb', line 5

def self.included(base)
  base.class_eval {
    before_validation :set_title
    before_validation :set_breadcrumb
    before_validation :set_published
    class_inheritable_accessor :sheet_root
    
    def self.root
      Page.root.children.first(:conditions => {:class_name => self.to_s})
    rescue NoMethodError => e
      e.extend Sheet::InvalidHomePage
      raise e
    end

    def self.create_root
      s = self.new_with_defaults
      s.parent_id = Page.root.id
      s.created_by_id = ''
      s.slug = self.name == 'StylesheetPage' ? 'css' : 'js'
      s.save
    end

    def self.default_page_parts
      PagePart.new(:name => 'body')
    end
    
    def self.create_or_update_from_upload!(file)
      slug = file.original_filename.to_slug().gsub(/-dot-css$/,'.css').gsub(/-js/,'.js')
      @sheet = StylesheetPage.find_by_slug(slug) || JavascriptPage.find_by_slug(slug)
      if @sheet.nil?
        @sheet = self.new_with_defaults
        @sheet.upload = file
        @sheet.save!
      else
        @sheet.part('body').update_attribute :content, file.read
      end
      @sheet
    end
    
  }
end

Instance Method Details

#cache?Boolean

Returns:

  • (Boolean)


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

def cache?
  true
end

#cache_markerObject



104
105
106
# File 'app/models/sheet.rb', line 104

def cache_marker
  Radiant::Config['sheets.use_cache_param?'] ? "?#{digest}" : ''
end

#child_path(child) ⇒ Object



100
101
102
# File 'app/models/sheet.rb', line 100

def child_path(child)
  clean_path(path + '/' + child.slug + child.cache_marker)
end

#digestObject



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

def digest
  @generated_digest ||= digest!
end

#digest!Object



96
97
98
# File 'app/models/sheet.rb', line 96

def digest!
  Digest::MD5.hexdigest(self.render)
end

#find_by_path(path, live = true, clean = true) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/sheet.rb', line 60

def find_by_path(path, live = true, clean = true)
  path = clean_path(path) if clean
  my_path = self.path
  if (my_path == path) && (not live or published?)
    self
  elsif (path =~ /^#{Regexp.quote(my_path)}([^\/]*)/)
    slug_child = children.find_by_slug($1)
    if slug_child
      return slug_child
    else
      super
    end
  end
end

#find_by_url(*args) ⇒ Object



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

def find_by_url(*args)
  ActiveSupport::Deprecation.warn("`find_by_url' has been deprecated; use `find_by_path' instead.", caller)
  find_by_path(*args)
end

#layoutObject



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

def layout
  nil
end

#upload=(file) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/sheet.rb', line 80

def upload=(file)
  case
  when file.blank?
    self.errors.add(:upload, 'not given. Please upload a file.')
  when !file.kind_of?(ActionController::UploadedFile)
    self.errors.add(:upload, 'is an unusable format.')
  else
    self.slug = file.original_filename.to_slug().gsub(/-dot-css$/,'.css').gsub(/-js/,'.js')
    self.part('body').content = file.read
  end
end

#virtual?Boolean

so that it is ignored when finding children in radius tags

Returns:

  • (Boolean)


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

def virtual?
  true
end