puffer_pages 0.0.11 → 0.0.12
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/VERSION +1 -1
- data/app/controllers/pages_controller.rb +2 -2
- data/app/models/page.rb +12 -7
- data/lib/puffer_pages/liquid/page_drop.rb +12 -29
- data/puffer_pages.gemspec +1 -1
- data/spec/lib/drops_spec.rb +8 -5
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.12
|
@@ -9,8 +9,8 @@ class PagesController < ApplicationController
|
|
9
9
|
|
10
10
|
def drops
|
11
11
|
{
|
12
|
-
:self => PufferPages::Liquid::PageDrop.new(@page, request),
|
13
|
-
:root => PufferPages::Liquid::PageDrop.new(
|
12
|
+
:self => PufferPages::Liquid::PageDrop.new(@page, @page, request),
|
13
|
+
:root => PufferPages::Liquid::PageDrop.new(@page.root, @page, request)
|
14
14
|
}.stringify_keys
|
15
15
|
end
|
16
16
|
|
data/app/models/page.rb
CHANGED
@@ -10,12 +10,9 @@ class Page < ActiveRecord::Base
|
|
10
10
|
%w(draft hidden published)
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.root
|
14
|
-
roots.first
|
15
|
-
end
|
16
|
-
|
17
13
|
def self.find_page location
|
18
|
-
page =
|
14
|
+
page = PufferPages.single_section_page_path ?
|
15
|
+
Page.find_by_slug(location) : Page.find_by_location(location)
|
19
16
|
raise ActiveRecord::RecordNotFound if page.nil? || page.draft?
|
20
17
|
page
|
21
18
|
end
|
@@ -28,7 +25,7 @@ class Page < ActiveRecord::Base
|
|
28
25
|
validate do |page|
|
29
26
|
page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
|
30
27
|
end
|
31
|
-
validates_uniqueness_of :slug, :scope => :parent_id
|
28
|
+
validates_uniqueness_of :slug, :scope => (:parent_id unless PufferPages.single_section_page_path)
|
32
29
|
validates_format_of :slug,
|
33
30
|
:with => /\A([\w]+[\w-]*(\.[\w]+)?|\*)\Z/,
|
34
31
|
:message => :slug_format,
|
@@ -65,6 +62,10 @@ class Page < ActiveRecord::Base
|
|
65
62
|
define_method "#{status_name}?" do status == status_name end
|
66
63
|
end
|
67
64
|
|
65
|
+
def to_location
|
66
|
+
PufferPages.single_section_page_path ? slug : location
|
67
|
+
end
|
68
|
+
|
68
69
|
def render(drops_or_context)
|
69
70
|
if inherited_layout
|
70
71
|
@template = Liquid::Template.parse(inherited_layout.body)
|
@@ -95,7 +96,7 @@ class Page < ActiveRecord::Base
|
|
95
96
|
end
|
96
97
|
|
97
98
|
def inherited_page_parts
|
98
|
-
|
99
|
+
PagePart.where(:page_parts => {:page_id => self_and_ancestors.map(&:id)}).joins(:page).order("page_parts.name = '#{PufferPages.primary_page_part_name}' desc, page_parts.name, pages.lft desc").uniq_by &:name
|
99
100
|
end
|
100
101
|
|
101
102
|
def part name
|
@@ -110,4 +111,8 @@ class Page < ActiveRecord::Base
|
|
110
111
|
Rack::Mime.mime_type(File.extname(slug), 'text/html')
|
111
112
|
end
|
112
113
|
|
114
|
+
def self_and_children
|
115
|
+
[self] + children
|
116
|
+
end
|
117
|
+
|
113
118
|
end
|
@@ -5,59 +5,42 @@ module PufferPages
|
|
5
5
|
include ActionController::UrlFor
|
6
6
|
include Rails.application.routes.url_helpers
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
8
|
+
delegate *(Page.statuses.map {|s| "#{s}?"} << {:to => :page})
|
9
|
+
delegate :root, :name, :title, :description, :keywords, :created_at, :updated_at, :to => :page
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
page.send(attribute)
|
15
|
-
end
|
11
|
+
def initialize page, current_page = nil, request = nil
|
12
|
+
@page, @request, @current_page = page, request, current_page
|
16
13
|
end
|
17
14
|
|
18
15
|
def parent
|
19
|
-
@parent ||= self.class.new(page.parent,
|
16
|
+
@parent ||= self.class.new(page.parent, current_page, request)
|
20
17
|
end
|
21
18
|
|
22
|
-
%w(ancestors children).each do |attribute|
|
19
|
+
%w(ancestors self_and_ancestors children self_and_children siblings self_and_siblings descendants, self_and_descendants).each do |attribute|
|
23
20
|
define_method attribute do
|
24
|
-
instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", page.send(attribute).map{ |ac| self.class.new(ac, request)})
|
21
|
+
instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", page.send(attribute).map{ |ac| self.class.new(ac, current_page, request)})
|
25
22
|
end
|
26
23
|
end
|
27
24
|
|
28
|
-
def ancestors?
|
29
|
-
!page.root?
|
30
|
-
end
|
31
|
-
|
32
|
-
def children?
|
33
|
-
page.children.present?
|
34
|
-
end
|
35
|
-
|
36
25
|
def path
|
37
|
-
puffer_page_path page.
|
26
|
+
puffer_page_path page.to_location
|
38
27
|
end
|
39
28
|
|
40
29
|
def url
|
41
|
-
puffer_page_url page.
|
30
|
+
puffer_page_url page.to_location
|
42
31
|
end
|
43
32
|
|
44
33
|
def current?
|
45
|
-
|
34
|
+
page == current_page
|
46
35
|
end
|
47
36
|
|
48
37
|
def ancestor?
|
49
|
-
|
38
|
+
page.is_ancestor_of? current_page
|
50
39
|
end
|
51
40
|
|
52
41
|
private
|
53
42
|
|
54
|
-
|
55
|
-
@request
|
56
|
-
end
|
57
|
-
|
58
|
-
def page
|
59
|
-
@page
|
60
|
-
end
|
43
|
+
attr_reader :page, :request, :current_page
|
61
44
|
|
62
45
|
end
|
63
46
|
end
|
data/puffer_pages.gemspec
CHANGED
data/spec/lib/drops_spec.rb
CHANGED
@@ -4,14 +4,14 @@ describe 'Drops' do
|
|
4
4
|
|
5
5
|
include
|
6
6
|
|
7
|
-
def render_page(
|
7
|
+
def render_page(current_page, page = nil)
|
8
8
|
request = ActionController::TestRequest.new
|
9
9
|
request.env["rack.url_scheme"] = "http"
|
10
10
|
request.host = 'test.com'
|
11
11
|
request.port = 80
|
12
|
-
request.path = "/#{
|
13
|
-
|
14
|
-
'page' => (PufferPages::Liquid::PageDrop.new(
|
12
|
+
request.path = "/#{current_page.location}"
|
13
|
+
current_page.render 'self' => PufferPages::Liquid::PageDrop.new(current_page, current_page, request),
|
14
|
+
'page' => (PufferPages::Liquid::PageDrop.new(page, current_page, request) if page)
|
15
15
|
end
|
16
16
|
|
17
17
|
describe 'page drop' do
|
@@ -20,6 +20,9 @@ describe 'Drops' do
|
|
20
20
|
@root = Fabricate :page, :layout_name => 'foo_layout'
|
21
21
|
@foo = Fabricate :page, :slug => 'hello', :parent => @root
|
22
22
|
@bar = Fabricate :page, :slug => 'world', :parent => @foo
|
23
|
+
@root.reload
|
24
|
+
@foo.reload
|
25
|
+
@bar.reload
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'should render proper url and path' do
|
@@ -39,7 +42,7 @@ describe 'Drops' do
|
|
39
42
|
it 'should render proper ancestor?' do
|
40
43
|
@layout = Fabricate :layout, :name => 'foo_layout', :body => "{{ page.ancestor? }}"
|
41
44
|
|
42
|
-
render_page(@foo, @foo).should == '
|
45
|
+
render_page(@foo, @foo).should == 'false'
|
43
46
|
render_page(@foo, @root).should == 'true'
|
44
47
|
render_page(@foo, @bar).should == 'false'
|
45
48
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puffer_pages
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 12
|
10
|
+
version: 0.0.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- pyromaniac
|