diff --git a/README.md b/README.md index c5d00f4..4ce02f1 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ComfyBlog [![Gem Version](https://badge.fury.io/rb/comfy_blog.png)](http://rubygems.org/gems/comfy_blog) [![Build Status](https://secure.travis-ci.org/comfy/comfy-blog.png)](http://travis-ci.org/comfy/comfy-blog) [![Dependency Status](https://gemnasium.com/comfy/comfy-blog.png)](https://gemnasium.com/comfy/comfy-blog) [![Code Climate](https://codeclimate.com/github/comfy/comfy-blog.png)](https://codeclimate.com/github/comfy/comfy-blog) [![Coverage Status](https://coveralls.io/repos/comfy/comfy-blog/badge.png?branch=master)](https://coveralls.io/r/comfy/comfy-blog) -ComfyBlog is an simple blog management engine for [ComfortableMexicanSofa](https://github.com/comfy/comfortable-mexican-sofa) (for version >= 1.10). +ComfyBlog is an simple blog management engine for [ComfortableMexicanSofa](https://github.com/comfy/comfortable-mexican-sofa) (for version >= 1.11). ## Features @@ -13,7 +13,7 @@ ComfyBlog is an simple blog management engine for [ComfortableMexicanSofa](https Add gem definition to your Gemfile: ```ruby -gem 'comfy_blog', '~> 1.0.0' +gem 'comfy_blog', '~> 1.1.0' ``` Then from the Rails project's root run: @@ -25,8 +25,8 @@ Then from the Rails project's root run: Take a look inside your `config/routes.rb` file and you should see following lines there: ```ruby -ComfyBlog::Routing.admin :path => 'admin' -ComfyBlog::Routing.content :path => 'blog' +comfy_route :blog_admin, :path => 'admin' +comfy_route :blog, :path => 'blog' ``` You should also find view templates in `/app/views/blog` folder. Feel free to adjust them as you see fit. diff --git a/comfy_blog.gemspec b/comfy_blog.gemspec index c0ad700..51c338d 100644 --- a/comfy_blog.gemspec +++ b/comfy_blog.gemspec @@ -17,5 +17,5 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.require_paths = ['lib'] - s.add_dependency 'comfortable_mexican_sofa', '>= 1.10.0' + s.add_dependency 'comfortable_mexican_sofa', '>= 1.11.0' end diff --git a/config/blog_routes.rb b/config/blog_routes.rb index fc7e403..7f1f357 100644 --- a/config/blog_routes.rb +++ b/config/blog_routes.rb @@ -1,6 +1,6 @@ ComfyBlog::Application.routes.draw do - ComfortableMexicanSofa::Routing.admin - ComfyBlog::Routing.admin - ComfyBlog::Routing.content - ComfortableMexicanSofa::Routing.content :sitemap => true + comfy_route :cms_admin + comfy_route :blog_admin + comfy_route :blog + comfy_route :cms, :sitemap => true end \ No newline at end of file diff --git a/lib/comfy_blog/routes/blog.rb b/lib/comfy_blog/routes/blog.rb new file mode 100644 index 0000000..06b3eb3 --- /dev/null +++ b/lib/comfy_blog/routes/blog.rb @@ -0,0 +1,18 @@ +class ActionDispatch::Routing::Mapper + + def comfy_route_blog(options = {}) + options[:path] ||= 'blog' + path = ['(:cms_path)', options[:path], '(:blog_path)'].join('/') + + 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 \ No newline at end of file diff --git a/lib/comfy_blog/routes/blog_admin.rb b/lib/comfy_blog/routes/blog_admin.rb new file mode 100644 index 0000000..8211f3d --- /dev/null +++ b/lib/comfy_blog/routes/blog_admin.rb @@ -0,0 +1,18 @@ +class ActionDispatch::Routing::Mapper + + def comfy_route_blog_admin(options = {}) + options[:path] ||= 'admin' + path = [options[:path], 'sites', ':site_id'].join('/') + + 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 \ No newline at end of file diff --git a/lib/comfy_blog/routing.rb b/lib/comfy_blog/routing.rb index 8bfd343..de0c9b1 100644 --- a/lib/comfy_blog/routing.rb +++ b/lib/comfy_blog/routing.rb @@ -1,38 +1,2 @@ -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 \ No newline at end of file +require_relative 'routes/blog_admin' +require_relative 'routes/blog' \ No newline at end of file diff --git a/lib/generators/comfy/blog/blog_generator.rb b/lib/generators/comfy/blog/blog_generator.rb index 52f5c2e..62a9e53 100644 --- a/lib/generators/comfy/blog/blog_generator.rb +++ b/lib/generators/comfy/blog/blog_generator.rb @@ -31,8 +31,8 @@ def generate_initialization end def generate_routing - route_string = " ComfyBlog::Routing.admin :path => '/admin'\n" - route_string << " ComfyBlog::Routing.content :path => '/blog'\n" + route_string = " comfy_route :blog_admin, :path => '/admin'\n" + route_string << " comfy_route :blog, :path => '/blog'\n" route route_string[2..-1] end diff --git a/test/fixtures/generators/blog/routes.rb b/test/fixtures/generators/blog/routes.rb index 7476548..1321a38 100644 --- a/test/fixtures/generators/blog/routes.rb +++ b/test/fixtures/generators/blog/routes.rb @@ -1,6 +1,6 @@ Test::Application.routes.draw do - ComfyBlog::Routing.admin :path => '/admin' - ComfyBlog::Routing.content :path => '/blog' + comfy_route :blog_admin, :path => '/admin' + comfy_route :blog, :path => '/blog' end \ No newline at end of file