Sha256: 91c8b65a39a6afb95c6220c6c29051b3554b7c20c8ea47766f9992a6b27a4353

Contents?: true

Size: 1.75 KB

Versions: 6

Compression:

Stored size: 1.75 KB

Contents

module Noodall
  class NodesController < ApplicationController
    rescue_from MongoMapper::DocumentNotFound, :with => :render_404

    def show
      if flash.any? or published_states_changed_since_global_update? or stale?(:last_modified => GlobalUpdateTime::Stamp.read, :public => true)
        permalink = params[:permalink].is_a?(String) ? params[:permalink] : params[:permalink].join('/')

        @node = Node.find_by_permalink(permalink)
        @page_title = @node.title
        @page_description = @node.description
        @page_keywords = @node.keywords

        respond_to do |format|
          format.html { render "nodes/#{@node.class.name.underscore}" }
          format.rss { render "nodes/#{@node.class.name.underscore}" }
        end
      end

    end

    def sitemap
      if stale?(:last_modified => GlobalUpdateTime::Stamp.read, :public => true)
        @page_title = 'Sitemap'
      end

      @nodes = Node.all
    end

    def search
      @nodes = Node.search(params[:q], :per_page => 10, :page => params[:page], :published_at => { :$lte => Time.zone.now }, :published_to => { :$gte => Time.zone.now })
      @page_title = 'Searching: '+ params[:q]
    end

  protected

    def published_states_changed_since_global_update?
      if Node.count(:published_at => { :$gte => GlobalUpdateTime::Stamp.read, :$lte => Time.zone.now }).zero? and Node.count(:published_to => { :$gte => GlobalUpdateTime::Stamp.read, :$lte => Time.zone.now }).zero?
        false
      else
        GlobalUpdateTime::Stamp.update!
        true
      end
    end

    def render_404(exception = nil)
      if exception
          logger.info "Rendering 404: #{exception.message}"
      end

      render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
noodall-ui-0.0.16 app/controllers/noodall/nodes_controller.rb
noodall-ui-0.0.15 app/controllers/noodall/nodes_controller.rb
noodall-ui-0.0.14 app/controllers/noodall/nodes_controller.rb
noodall-ui-0.0.13 app/controllers/noodall/nodes_controller.rb
noodall-ui-0.0.12 app/controllers/noodall/nodes_controller.rb
noodall-ui-0.0.11 app/controllers/noodall/nodes_controller.rb