public_pages 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,61 +1,58 @@
1
- module PublicPages
1
+ class PublicPagesController < ApplicationController
2
2
 
3
- class PublicpagesController < ApplicationController
3
+ unloadable
4
4
 
5
- unloadable
5
+ respond_to :html, :xml, :css, :js
6
6
 
7
- respond_to :html, :xml, :css, :js
8
-
9
- def index
10
- @pages = PublicPage.all
11
- end
7
+ def index
8
+ @pages = PublicPage.all
9
+ end
12
10
 
13
- def new
14
- @page = PublicPage.new
15
- end
11
+ def new
12
+ @page = PublicPage.new
13
+ render :action => 'edit'
14
+ end
16
15
 
17
- def create
18
- @page = PublicPage.new(params[:public_page])
19
- if @page.save
20
- redirect_to public_pages_path
21
- else
22
- render :action => :new, :note => 'Nothing can be blank.'
23
- end
16
+ def create
17
+ @page = PublicPage.new(params[:public_page])
18
+ if @page.save
19
+ redirect_to public_pages_path
20
+ else
21
+ render :action => :new, :note => 'Nothing can be blank.'
24
22
  end
23
+ end
25
24
 
26
- def show
27
- @page = PublicPage.find_by_full_url(:parent_url => params[:parent_url], :url => params[:url], :format => params[:format])
25
+ def show
26
+ @page = PublicPage.find_by_url(params[:parent], params[:child])
28
27
 
29
- raise ActiveRecord::RecordNotFound unless @page
28
+ raise ActiveRecord::RecordNotFound unless @page
30
29
 
31
- respond_with @page
30
+ respond_with @page, :layout => false
32
31
 
33
- end
34
-
35
- def edit
36
- @page = PublicPage.find(params[:id])
37
- end
38
-
39
- def update
40
- @page = PublicPage.find(params[:id])
41
- if @page.update_attributes(params[:public_page])
42
- redirect_to @page.public_url
43
- else
44
- render :action => :edit, :notice => 'Nothing can be blank.'
45
- end
46
- end
32
+ end
47
33
 
48
- def destroy
49
- PublicPage.find(params[:id]).destroy
50
- redirect_to public_pages_path
51
- end
34
+ def edit
35
+ @page = PublicPage.find(params[:id])
36
+ end
52
37
 
53
-
54
- def sitemap
55
- @pages = PublicPage.all
56
- respond_wth @pages
38
+ def update
39
+ @page = PublicPage.find(params[:id])
40
+ if @page.update_attributes(params[:public_page])
41
+ redirect_to :action => :edit, :notice => "Updated"
42
+ else
43
+ render :action => :edit, :notice => 'Nothing can be blank.'
57
44
  end
45
+ end
58
46
 
47
+ def destroy
48
+ PublicPage.find(params[:id]).destroy
49
+ redirect_to public_pages_path
50
+ end
59
51
 
52
+
53
+ def sitemap
54
+ @pages = PublicPage.all
55
+ respond_wth @pages
60
56
  end
57
+
61
58
  end
@@ -1,3 +1,21 @@
1
+ require "acts_as_tree"
2
+
1
3
  class PublicPage < ActiveRecord::Base
4
+ validates_presence_of :name
5
+ validates_format_of :name, :with => /^\w+$/
6
+
7
+ acts_as_tree
8
+
9
+ def self.for_select
10
+ all.map { |page| [page.name, page.id] }
11
+ end
12
+
13
+ def self.find_by_url(parent_name, child_name)
14
+ puts PublicPage.roots.map(&:name)
15
+ parent_page = PublicPage.roots.find_by_name(parent_name)
16
+ return parent_page unless parent_page && child_name
17
+
18
+ parent_page.children.find_by_name(child_name)
19
+ end
2
20
 
3
21
  end
@@ -0,0 +1,21 @@
1
+ <%= form_for @page do |f| %>
2
+
3
+ <p>
4
+ <%= f.label :name %>
5
+ <%= f.text_field :name %>
6
+ </p>
7
+
8
+ <p>
9
+ <%= f.label :parent_id %>
10
+ <%= f.select :parent_id, PublicPage.for_select, :include_blank => true %>
11
+ </p>
12
+
13
+ <p>
14
+ <%= f.label :body %>
15
+ <%= f.text_area :body %>
16
+ </p>
17
+
18
+ <p>
19
+ <%= f.submit %>
20
+ </p>
21
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <h1>Here are all of your pages</h1>
2
+
3
+ <h2>
4
+ <%= link_to "Create a new page", new_public_page_path %>
5
+ </h2>
6
+
7
+
8
+ <ul>
9
+ <% @pages.each do |page| %>
10
+ <li>
11
+ <%= link_to page.name, [:edit, page] %>
12
+ </li>
13
+ <% end %>
14
+ </ul>
@@ -0,0 +1 @@
1
+ <%= raw @page.body %>
@@ -1,5 +1,6 @@
1
1
  Rails.application.routes.draw do |map|
2
2
 
3
3
  resources :public_pages
4
+ match '/:parent(/:child)', :to => 'public_pages#show'
4
5
 
5
- end
6
+ end
@@ -6,11 +6,13 @@ module PublicPages
6
6
  class MigrationGenerator < Rails::Generators::Base
7
7
 
8
8
  def add_migration
9
- generate :model, "PublicPage name:string parent_name:string body:text"
9
+ generate :model, "PublicPage parent_id:integer name:string body:text"
10
10
  end
11
11
 
12
- def remove_the_local_model
12
+ def remove_the_local_model_and_tests
13
13
  %x{rm #{Rails.root}/app/models/public_page.rb}
14
+ %x{rm #{Rails.root}/test/unit/public_page_test.rb}
15
+ %x{rm #{Rails.root}/test/fixtures/public_pages.yml}
14
16
  end
15
17
 
16
18
  end
@@ -7,3 +7,4 @@ module PublicPages
7
7
  end
8
8
 
9
9
  end
10
+
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe PublicPage do
4
+
5
+ describe "#configuration" do
6
+
7
+ it "returns the same object every time" do
8
+ RSpec.configuration.should equal(RSpec.configuration)
9
+ end
10
+
11
+ end
12
+
13
+ describe "#configure" do
14
+
15
+ it "yields the current configuration" do
16
+ RSpec.configure do |config|
17
+ config.should == RSpec::configuration
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ describe "#world" do
24
+
25
+ it "returns the RSpec::Core::World instance the current run is using" do
26
+ RSpec.world.should be_instance_of(RSpec::Core::World)
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors: []
12
12
 
@@ -29,11 +29,16 @@ extra_rdoc_files:
29
29
  files:
30
30
  - app/controllers/public_pages_controller.rb
31
31
  - app/models/public_page.rb
32
+ - app/views/public_pages/edit.html.erb
33
+ - app/views/public_pages/index.html.erb
34
+ - app/views/public_pages/show.html.erb
32
35
  - config/routes.rb
33
36
  - lib/generators/public_pages/migration_generator.rb
34
37
  - lib/public_pages.rb
35
38
  - lib/public_pages/engine.rb
36
39
  - README
40
+ - spec/models/public_page_spec.rb
41
+ - spec/spec_helper.rb
37
42
  has_rdoc: true
38
43
  homepage:
39
44
  licenses: []
@@ -48,6 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
53
  requirements:
49
54
  - - ">="
50
55
  - !ruby/object:Gem::Version
56
+ hash: -3447327586130444845
51
57
  segments:
52
58
  - 0
53
59
  version: "0"
@@ -66,5 +72,6 @@ rubygems_version: 1.3.7
66
72
  signing_key:
67
73
  specification_version: 3
68
74
  summary: Simplest possible CMS for Rails 3
69
- test_files: []
70
-
75
+ test_files:
76
+ - spec/models/public_page_spec.rb
77
+ - spec/spec_helper.rb