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.
- data/app/controllers/public_pages_controller.rb +41 -44
- data/app/models/public_page.rb +18 -0
- data/app/views/public_pages/edit.html.erb +21 -0
- data/app/views/public_pages/index.html.erb +14 -0
- data/app/views/public_pages/show.html.erb +1 -0
- data/config/routes.rb +2 -1
- data/lib/generators/public_pages/migration_generator.rb +4 -2
- data/lib/public_pages/engine.rb +1 -0
- data/spec/models/public_page_spec.rb +32 -0
- data/spec/spec_helper.rb +1 -0
- metadata +11 -4
@@ -1,61 +1,58 @@
|
|
1
|
-
|
1
|
+
class PublicPagesController < ApplicationController
|
2
2
|
|
3
|
-
|
3
|
+
unloadable
|
4
4
|
|
5
|
-
|
5
|
+
respond_to :html, :xml, :css, :js
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@pages = PublicPage.all
|
11
|
-
end
|
7
|
+
def index
|
8
|
+
@pages = PublicPage.all
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def new
|
12
|
+
@page = PublicPage.new
|
13
|
+
render :action => 'edit'
|
14
|
+
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
27
|
-
|
25
|
+
def show
|
26
|
+
@page = PublicPage.find_by_url(params[:parent], params[:child])
|
28
27
|
|
29
|
-
|
28
|
+
raise ActiveRecord::RecordNotFound unless @page
|
30
29
|
|
31
|
-
|
30
|
+
respond_with @page, :layout => false
|
32
31
|
|
33
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
34
|
+
def edit
|
35
|
+
@page = PublicPage.find(params[:id])
|
36
|
+
end
|
52
37
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
data/app/models/public_page.rb
CHANGED
@@ -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 @@
|
|
1
|
+
<%= raw @page.body %>
|
data/config/routes.rb
CHANGED
@@ -6,11 +6,13 @@ module PublicPages
|
|
6
6
|
class MigrationGenerator < Rails::Generators::Base
|
7
7
|
|
8
8
|
def add_migration
|
9
|
-
generate :model, "PublicPage
|
9
|
+
generate :model, "PublicPage parent_id:integer name:string body:text"
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
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
|
data/lib/public_pages/engine.rb
CHANGED
@@ -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
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -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
|
-
-
|
9
|
-
version: 0.1.
|
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
|