Sha256: c39707bb68c24b22a82da228879390806b497e01df38cbbea6e4891399acdadb

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module ComfyBlog::Routing
  
  def self.admin(options = {})
    options[:path] ||= 'admin'
    path = [options[:path], 'sites', ':site_id'].join('/')
    
    Rails.application.routes.draw do
      scope :module => :admin do
        namespace :blog, :as => :admin, :path => path, :except => [:show] do
          resources :blogs do
            resources :posts
            resources :comments, :only => [:index, :destroy] do
              patch :toggle_publish, :on => :member
            end
          end
        end
      end
    end
  end
  
  def self.content(options = {})
    options[:path] ||= 'blog'
    path = ['(:cms_path)', options[:path], '(:blog_path)'].join('/')
    
    Rails.application.routes.draw do
      namespace :blog, :path => path, :constraints => {:blog_path => /\w[a-z0-9_-]*/} do
        with_options :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} do |o|
          o.get ':year'               => 'posts#index', :as => :posts_of_year
          o.get ':year/:month'        => 'posts#index', :as => :posts_of_month
          o.get ':year/:month/:slug'  => 'posts#show',  :as => :posts_dated
        end
        post ':slug/comments' => 'comments#create', :as => :comments
        get  ':slug'          => 'posts#serve',     :as => :post
        get  '/'              => 'posts#serve',     :as => :posts
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
comfy_blog-1.0.0 lib/comfy_blog/routing.rb