blue_pages 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ class BluePages::PagesController < ::ApplicationController
4
+
5
+ respond_to :html
6
+
7
+ def show
8
+ @page = BluePages::Page.where(:path => params[:path]).first
9
+ unless @page
10
+ render_404
11
+ end
12
+ end
13
+
14
+ protected
15
+
16
+ def render_404
17
+ render :file => File.join(Rails.root, "/public/404.html"),
18
+ :status => :not_found,
19
+ :layout => false
20
+ end
21
+
22
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ class BluePages::Page
4
+
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+ include Mongoid::Tree
8
+
9
+ store_in :blue_pages
10
+
11
+ field :title
12
+ field :permalink
13
+ field :path
14
+ field :metadata, :type => Hash
15
+ field :content
16
+ field :published, :type => Boolean, :default => true
17
+
18
+ validates_presence_of :title
19
+ validates_uniqueness_of :title
20
+
21
+ scope :published, where(:published => true)
22
+ scope :unpublished, where(:published => false)
23
+
24
+ after_rearrange :rebuild_path
25
+
26
+ def title=(new_title)
27
+ write_attribute(:permalink, Permalink.from(new_title))
28
+ write_attribute(:title, new_title)
29
+ end
30
+
31
+ protected
32
+
33
+ def rebuild_path
34
+ self.path = self.ancestors_and_self.collect(&:permalink).join('/')
35
+ end
36
+
37
+ end
data/config/routes.rb CHANGED
@@ -4,14 +4,13 @@ Rails::Application.routes.draw do
4
4
 
5
5
 
6
6
  if BluePages.route_prefix.present?
7
-
8
- match "#{BluePages.route_prefix}/*path" => "pages#show"
9
-
7
+
8
+ match "#{BluePages.route_prefix}/*path" => "blue_pages/pages#show"
9
+
10
10
  else
11
-
12
- match '*path' => "pages#show"
13
-
11
+
12
+ match '*path' => "blue_pages/pages#show"
13
+
14
14
  end
15
15
 
16
16
  end
17
-
data/lib/blue_pages.rb CHANGED
@@ -3,13 +3,12 @@
3
3
  module BluePages
4
4
 
5
5
  class Engine < Rails::Engine
6
-
7
6
  end
8
-
7
+
9
8
  def self.setup
10
9
  yield self
11
10
  end
12
-
11
+
13
12
  mattr_accessor :route_prefix
14
13
 
15
14
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Ji\xC5\x99\xC3\xAD Zajpt"
@@ -56,6 +56,8 @@ extensions: []
56
56
  extra_rdoc_files:
57
57
  - README
58
58
  files:
59
+ - app/controllers/blue_pages/pages_controller.rb
60
+ - app/models/blue_pages/page.rb
59
61
  - config/routes.rb
60
62
  - lib/blue_pages.rb
61
63
  - README