Class: CortexReaver::MainController

Inherits:
Controller
  • Object
show all
Defined in:
lib/cortex_reaver/controller/main.rb

Instance Method Summary collapse

Instance Method Details

#atomObject

TODO: We don’t implement a collective ATOM feed. Yet.



88
89
90
# File 'lib/cortex_reaver/controller/main.rb', line 88

def atom
  error_404
end

#index(*ids) ⇒ Object

the index action is called automatically when no other action is specified



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cortex_reaver/controller/main.rb', line 38

def index(*ids)
  if not ids.empty? and @page = Page.get(ids)
    # Render that page.
    @title = @page.title
   
    # Workflows
    if user.can_edit? Page.new
      workflow "Edit this page", PageController.r(:edit, @page.id), :edit, :page
    end
    if user.can_delete? Page.new
      workflow "Delete this page", PageController.r(:delete, @page.id), :delete, :page
    end

    # Set up comments
    if comment = session[:pending_comment] and comment.parent == @page
      @new_comment = session.delete :pending_comment
    else
      # Create a comment to be posted
      @new_comment = CortexReaver::Comment.new :page => @page
    end

    PageController.render_view('show')
  elsif not ids.empty?
    # Didn't have that page
    error_404
  else
    # Default welcome page
    @journals = Journal.recent.viewable_by(user)

    # Workflows
    if user.can_create? Journal.new
      workflow "New Journal", JournalController.r(:new), :new, :journal
    end
    if user.can_create? Photograph.new
      workflow "New Photograph", PhotographController.r(:new), :new, :photograph
    end
    if user.can_create? Page.new
      workflow "New Page", PageController.r(:new), :new, :page
    end

    # Feeds
    feed 'Photographs', PhotographController.r(:atom)
    feed 'Journals', JournalController.r(:atom)
    feed 'Comments', CommentController.r(:atom)

    JournalController.render_view('list', :journals => @journals)
  end
end

#sitemapObject

XML sitemap.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cortex_reaver/controller/main.rb', line 93

def sitemap
  error_404 unless request.path_info =~ /\.xml$/

  doc = LibXML::XML::Document.new
  doc.root = (root = LibXML::XML::Node.new('urlset'))
  root['xmlns'] = "http://www.sitemaps.org/schemas/sitemap/0.9"
  
  # Front page
  root << (url = LibXML::XML::Node.new('url'))
    url << (loc = LibXML::XML::Node.new('loc'))
      loc << full_url('/')
    url << (lastmod = LibXML::XML::Node.new('lastmod'))
      lastmod << Time.parse(Journal.dataset.min(:updated_on).to_s).xmlschema
    url << (changefreq = LibXML::XML::Node.new('changefreq'))
      changefreq << 'hourly'
    url << (priority = LibXML::XML::Node.new('priority'))
      priority << '1.0'

  # Indexes
  [JournalController, PhotographController].each do |c|
    root << (url = LibXML::XML::Node.new('url'))
    url << (loc = LibXML::XML::Node.new('loc'))
    url << (lastmod = LibXML::XML::Node.new('lastmod'))
    url << (changefreq = LibXML::XML::Node.new('changefreq'))
    url << (priority = LibXML::XML::Node.new('priority'))
    
    loc << full_url(c.r)
    lastmod << Time.parse(c::MODEL.dataset.min(:updated_on).to_s).xmlschema
    changefreq << 'hourly'
    priority << '0.9'
  end

  # Comments
  root << (url = LibXML::XML::Node.new('url'))
  url << (loc = LibXML::XML::Node.new('loc'))
  url << (lastmod = LibXML::XML::Node.new('lastmod'))
  url << (changefreq = LibXML::XML::Node.new('changefreq'))
  url << (priority = LibXML::XML::Node.new('priority'))
  
  loc << full_url('/comments')
  lastmod << Time.parse(Comment.dataset.min(:updated_on).to_s).xmlschema
  changefreq << 'always'
  priority << '0.5'

  # Individual pages
  Page.all.each do |page|
    root << (url = LibXML::XML::Node.new('url'))
    url << (loc = LibXML::XML::Node.new('loc'))
    url << (lastmod = LibXML::XML::Node.new('lastmod'))
    url << (changefreq = LibXML::XML::Node.new('changefreq'))
    url << (priority = LibXML::XML::Node.new('priority'))

    loc << full_url(page.url)
    lastmod << page.updated_on.xmlschema
    changefreq << 'weekly'
    priority << '0.9'
  end
  Journal.all.each do |journal|
    root << (url = LibXML::XML::Node.new('url'))
    url << (loc = LibXML::XML::Node.new('loc'))
    url << (lastmod = LibXML::XML::Node.new('lastmod'))
    url << (changefreq = LibXML::XML::Node.new('changefreq'))
    url << (priority = LibXML::XML::Node.new('priority'))
  
    loc << full_url(journal.url)
    lastmod << journal.updated_on.xmlschema
    changefreq << 'weekly'
    priority << '0.8'
  end
  Photograph.all.each do |photograph|
    root << (url = LibXML::XML::Node.new('url'))
    url << (loc = LibXML::XML::Node.new('loc'))
    url << (lastmod = LibXML::XML::Node.new('lastmod'))
    url << (changefreq = LibXML::XML::Node.new('changefreq'))
    url << (priority = LibXML::XML::Node.new('priority'))
      
    loc << full_url(photograph.url)
    lastmod << photograph.updated_on.xmlschema
    changefreq << 'weekly'
    priority << '0.8'
  end

  doc
end