puffer_pages 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +155 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/app/controllers/pages_controller.rb +17 -0
- data/app/controllers/puffer_pages/layouts_controller.rb +13 -0
- data/app/controllers/puffer_pages/pages_controller.rb +20 -0
- data/app/controllers/puffer_pages/snippets_controller.rb +13 -0
- data/app/models/layout.rb +6 -0
- data/app/models/page.rb +114 -0
- data/app/models/page_part.rb +23 -0
- data/app/models/snippet.rb +4 -0
- data/autotest/discover.rb +2 -0
- data/config/puffer_routes.rb +3 -0
- data/config/routes.rb +9 -0
- data/lib/generators/puffer_pages/install/USAGE +6 -0
- data/lib/generators/puffer_pages/install/install_generator.rb +12 -0
- data/lib/generators/puffer_pages/install/templates/controllers/layouts_controller.rb +4 -0
- data/lib/generators/puffer_pages/install/templates/controllers/pages_controller.rb +4 -0
- data/lib/generators/puffer_pages/install/templates/controllers/snippets_controller.rb +4 -0
- data/lib/generators/puffer_pages/install/templates/migrate/20090422092419_create_pages.rb +28 -0
- data/lib/generators/puffer_pages/install/templates/migrate/20090504132337_create_page_parts.rb +18 -0
- data/lib/generators/puffer_pages/install/templates/migrate/20090506102004_create_layouts.rb +16 -0
- data/lib/generators/puffer_pages/install/templates/migrate/20090510121824_create_snippets.rb +16 -0
- data/lib/puffer_pages.rb +9 -0
- data/lib/puffer_pages/base.rb +8 -0
- data/lib/puffer_pages/engine.rb +14 -0
- data/lib/puffer_pages/extensions/core.rb +7 -0
- data/lib/puffer_pages/extensions/mapper.rb +31 -0
- data/lib/puffer_pages/liquid/page_drop.rb +43 -0
- data/lib/puffer_pages/liquid/tags/yield.rb +27 -0
- data/lib/puffer_pages/liquid/tracker.rb +29 -0
- data/puffer_pages.gemspec +216 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/controllers/admin/layouts_controller.rb +3 -0
- data/spec/dummy/app/controllers/admin/pages_controller.rb +3 -0
- data/spec/dummy/app/controllers/admin/snippets_controller.rb +3 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +45 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +22 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +26 -0
- data/spec/dummy/config/environments/production.rb +49 -0
- data/spec/dummy/config/environments/test.rb +35 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/puffer.rb +0 -0
- data/spec/dummy/config/routes.rb +59 -0
- data/spec/dummy/db/migrate/20090422092419_create_pages.rb +29 -0
- data/spec/dummy/db/migrate/20090504132337_create_page_parts.rb +18 -0
- data/spec/dummy/db/migrate/20090506102004_create_layouts.rb +16 -0
- data/spec/dummy/db/migrate/20090510121824_create_snippets.rb +16 -0
- data/spec/dummy/db/schema.rb +65 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/application.js +2 -0
- data/spec/dummy/public/javascripts/controls.js +965 -0
- data/spec/dummy/public/javascripts/dragdrop.js +974 -0
- data/spec/dummy/public/javascripts/effects.js +1123 -0
- data/spec/dummy/public/javascripts/prototype.js +6001 -0
- data/spec/dummy/public/javascripts/rails.js +175 -0
- data/spec/dummy/public/puffer/javascripts/application.js +10 -0
- data/spec/dummy/public/puffer/javascripts/rails-src.js +57 -0
- data/spec/dummy/public/puffer/javascripts/right-autocompleter-src.js +621 -0
- data/spec/dummy/public/puffer/javascripts/right-autocompleter.js +18 -0
- data/spec/dummy/public/puffer/javascripts/right-autocompleter.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right-calendar-src.js +1461 -0
- data/spec/dummy/public/puffer/javascripts/right-calendar.js +36 -0
- data/spec/dummy/public/puffer/javascripts/right-calendar.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right-in-edit-src.js +369 -0
- data/spec/dummy/public/puffer/javascripts/right-in-edit.js +13 -0
- data/spec/dummy/public/puffer/javascripts/right-in-edit.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right-lightbox-src.js +905 -0
- data/spec/dummy/public/puffer/javascripts/right-lightbox.js +24 -0
- data/spec/dummy/public/puffer/javascripts/right-lightbox.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right-sortable-src.js +428 -0
- data/spec/dummy/public/puffer/javascripts/right-sortable.js +17 -0
- data/spec/dummy/public/puffer/javascripts/right-sortable.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right-src.js +5892 -0
- data/spec/dummy/public/puffer/javascripts/right-tabs-src.js +1145 -0
- data/spec/dummy/public/puffer/javascripts/right-tabs.js +29 -0
- data/spec/dummy/public/puffer/javascripts/right-tabs.js.gz +0 -0
- data/spec/dummy/public/puffer/javascripts/right.js +95 -0
- data/spec/dummy/public/puffer/javascripts/right.js.gz +0 -0
- data/spec/dummy/public/puffer/stylesheets/puffer.css +397 -0
- data/spec/dummy/public/puffer/stylesheets/reset.css +60 -0
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/fabricators/layouts_fabricator.rb +4 -0
- data/spec/fabricators/page_parts_fabricator.rb +4 -0
- data/spec/fabricators/pages_fabricator.rb +7 -0
- data/spec/integration/navigation_spec.rb +9 -0
- data/spec/models/page_spec.rb +132 -0
- data/spec/puffer_pages_spec.rb +7 -0
- data/spec/spec_helper.rb +38 -0
- metadata +409 -0
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rails', '~> 3.0.3'
|
4
|
+
gem 'liquid'
|
5
|
+
gem 'nested_set'
|
6
|
+
gem 'puffer'
|
7
|
+
gem 'will_paginate', '~> 3.0.pre2'
|
8
|
+
gem 'cells', '~> 3.4.4'
|
9
|
+
|
10
|
+
group :development, :test do
|
11
|
+
gem "capybara", ">= 0.4.0"
|
12
|
+
gem "sqlite3-ruby", :require => "sqlite3"
|
13
|
+
|
14
|
+
gem "rspec-rails"
|
15
|
+
gem "autotest"
|
16
|
+
gem 'forgery'
|
17
|
+
gem 'fabrication', '0.9.2'
|
18
|
+
gem "jeweler"
|
19
|
+
gem "mongrel"
|
20
|
+
end
|
21
|
+
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
ZenTest (4.4.2)
|
5
|
+
abstract (1.0.0)
|
6
|
+
actionmailer (3.0.3)
|
7
|
+
actionpack (= 3.0.3)
|
8
|
+
mail (~> 2.2.9)
|
9
|
+
actionpack (3.0.3)
|
10
|
+
activemodel (= 3.0.3)
|
11
|
+
activesupport (= 3.0.3)
|
12
|
+
builder (~> 2.1.2)
|
13
|
+
erubis (~> 2.6.6)
|
14
|
+
i18n (~> 0.4)
|
15
|
+
rack (~> 1.2.1)
|
16
|
+
rack-mount (~> 0.6.13)
|
17
|
+
rack-test (~> 0.5.6)
|
18
|
+
tzinfo (~> 0.3.23)
|
19
|
+
activemodel (3.0.3)
|
20
|
+
activesupport (= 3.0.3)
|
21
|
+
builder (~> 2.1.2)
|
22
|
+
i18n (~> 0.4)
|
23
|
+
activerecord (3.0.3)
|
24
|
+
activemodel (= 3.0.3)
|
25
|
+
activesupport (= 3.0.3)
|
26
|
+
arel (~> 2.0.2)
|
27
|
+
tzinfo (~> 0.3.23)
|
28
|
+
activeresource (3.0.3)
|
29
|
+
activemodel (= 3.0.3)
|
30
|
+
activesupport (= 3.0.3)
|
31
|
+
activesupport (3.0.3)
|
32
|
+
arel (2.0.7)
|
33
|
+
autotest (4.4.6)
|
34
|
+
ZenTest (>= 4.4.1)
|
35
|
+
builder (2.1.2)
|
36
|
+
capybara (0.4.1.1)
|
37
|
+
celerity (>= 0.7.9)
|
38
|
+
culerity (>= 0.2.4)
|
39
|
+
mime-types (>= 1.16)
|
40
|
+
nokogiri (>= 1.3.3)
|
41
|
+
rack (>= 1.0.0)
|
42
|
+
rack-test (>= 0.5.4)
|
43
|
+
selenium-webdriver (>= 0.0.27)
|
44
|
+
xpath (~> 0.1.3)
|
45
|
+
celerity (0.8.7)
|
46
|
+
cells (3.4.4)
|
47
|
+
cgi_multipart_eof_fix (2.5.0)
|
48
|
+
childprocess (0.1.6)
|
49
|
+
ffi (~> 0.6.3)
|
50
|
+
culerity (0.2.15)
|
51
|
+
daemons (1.1.0)
|
52
|
+
diff-lcs (1.1.2)
|
53
|
+
erubis (2.6.6)
|
54
|
+
abstract (>= 1.0.0)
|
55
|
+
fabrication (0.9.2)
|
56
|
+
fastthread (1.0.7)
|
57
|
+
ffi (0.6.3)
|
58
|
+
rake (>= 0.8.7)
|
59
|
+
forgery (0.3.6)
|
60
|
+
gem_plugin (0.2.3)
|
61
|
+
git (1.2.5)
|
62
|
+
i18n (0.5.0)
|
63
|
+
jeweler (1.5.2)
|
64
|
+
bundler (~> 1.0.0)
|
65
|
+
git (>= 1.2.5)
|
66
|
+
rake
|
67
|
+
json_pure (1.5.1)
|
68
|
+
liquid (2.2.2)
|
69
|
+
mail (2.2.15)
|
70
|
+
activesupport (>= 2.3.6)
|
71
|
+
i18n (>= 0.4.0)
|
72
|
+
mime-types (~> 1.16)
|
73
|
+
treetop (~> 1.4.8)
|
74
|
+
mime-types (1.16)
|
75
|
+
mongrel (1.1.5)
|
76
|
+
cgi_multipart_eof_fix (>= 2.4)
|
77
|
+
daemons (>= 1.0.3)
|
78
|
+
fastthread (>= 1.0.1)
|
79
|
+
gem_plugin (>= 0.2.3)
|
80
|
+
nested_set (1.6.3)
|
81
|
+
activerecord (>= 3.0.0)
|
82
|
+
railties (>= 3.0.0)
|
83
|
+
nokogiri (1.4.4)
|
84
|
+
polyglot (0.3.1)
|
85
|
+
puffer (0.0.10)
|
86
|
+
cells (~> 3.4.4)
|
87
|
+
rails (~> 3.0.3)
|
88
|
+
will_paginate (~> 3.0.pre2)
|
89
|
+
rack (1.2.1)
|
90
|
+
rack-mount (0.6.13)
|
91
|
+
rack (>= 1.0.0)
|
92
|
+
rack-test (0.5.7)
|
93
|
+
rack (>= 1.0)
|
94
|
+
rails (3.0.3)
|
95
|
+
actionmailer (= 3.0.3)
|
96
|
+
actionpack (= 3.0.3)
|
97
|
+
activerecord (= 3.0.3)
|
98
|
+
activeresource (= 3.0.3)
|
99
|
+
activesupport (= 3.0.3)
|
100
|
+
bundler (~> 1.0)
|
101
|
+
railties (= 3.0.3)
|
102
|
+
railties (3.0.3)
|
103
|
+
actionpack (= 3.0.3)
|
104
|
+
activesupport (= 3.0.3)
|
105
|
+
rake (>= 0.8.7)
|
106
|
+
thor (~> 0.14.4)
|
107
|
+
rake (0.8.7)
|
108
|
+
rspec (2.4.0)
|
109
|
+
rspec-core (~> 2.4.0)
|
110
|
+
rspec-expectations (~> 2.4.0)
|
111
|
+
rspec-mocks (~> 2.4.0)
|
112
|
+
rspec-core (2.4.0)
|
113
|
+
rspec-expectations (2.4.0)
|
114
|
+
diff-lcs (~> 1.1.2)
|
115
|
+
rspec-mocks (2.4.0)
|
116
|
+
rspec-rails (2.4.1)
|
117
|
+
actionpack (~> 3.0)
|
118
|
+
activesupport (~> 3.0)
|
119
|
+
railties (~> 3.0)
|
120
|
+
rspec (~> 2.4.0)
|
121
|
+
rubyzip (0.9.4)
|
122
|
+
selenium-webdriver (0.1.2)
|
123
|
+
childprocess (~> 0.1.5)
|
124
|
+
ffi (~> 0.6.3)
|
125
|
+
json_pure
|
126
|
+
rubyzip
|
127
|
+
sqlite3 (1.3.3)
|
128
|
+
sqlite3-ruby (1.3.3)
|
129
|
+
sqlite3 (>= 1.3.3)
|
130
|
+
thor (0.14.6)
|
131
|
+
treetop (1.4.9)
|
132
|
+
polyglot (>= 0.3.1)
|
133
|
+
tzinfo (0.3.24)
|
134
|
+
will_paginate (3.0.pre2)
|
135
|
+
xpath (0.1.3)
|
136
|
+
nokogiri (~> 1.3)
|
137
|
+
|
138
|
+
PLATFORMS
|
139
|
+
ruby
|
140
|
+
|
141
|
+
DEPENDENCIES
|
142
|
+
autotest
|
143
|
+
capybara (>= 0.4.0)
|
144
|
+
cells (~> 3.4.4)
|
145
|
+
fabrication (= 0.9.2)
|
146
|
+
forgery
|
147
|
+
jeweler
|
148
|
+
liquid
|
149
|
+
mongrel
|
150
|
+
nested_set
|
151
|
+
puffer
|
152
|
+
rails (~> 3.0.3)
|
153
|
+
rspec-rails
|
154
|
+
sqlite3-ruby
|
155
|
+
will_paginate (~> 3.0.pre2)
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rubygems'
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rake'
|
10
|
+
require 'rake/rdoctask'
|
11
|
+
|
12
|
+
require 'rspec/core'
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
|
17
|
+
task :default => :spec
|
18
|
+
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'Puffer Pages'
|
22
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
23
|
+
rdoc.rdoc_files.include('README.rdoc')
|
24
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
require 'jeweler'
|
28
|
+
|
29
|
+
Jeweler::Tasks.new do |gem|
|
30
|
+
gem.name = "puffer_pages"
|
31
|
+
gem.summary = %Q{Content management system}
|
32
|
+
gem.description = %Q{Puffer pages is integratable rails CMS with puffer admin interface}
|
33
|
+
gem.email = "kinwizard@gmail.com"
|
34
|
+
gem.homepage = "http://github.com/puffer/puffer_pages"
|
35
|
+
gem.authors = ["pyromaniac"]
|
36
|
+
end
|
37
|
+
Jeweler::GemcutterTasks.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class PagesController < ApplicationController
|
2
|
+
|
3
|
+
def index
|
4
|
+
@page = Page.find_page("/#{params[:path]}")
|
5
|
+
render :inline => @page.render(drops), :layout => @page.render_layout, :content_type => page.content_type
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def drops
|
11
|
+
{
|
12
|
+
:self => PufferPages::Liquid::PageDrop.new(@page, request),
|
13
|
+
:root => PufferPages::Liquid::PageDrop.new(Page.root, request)
|
14
|
+
}.stringify_keys
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class PufferPages::PagesController < PufferPages::Base
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
index do
|
5
|
+
field :name
|
6
|
+
field :slug
|
7
|
+
field :layout_name
|
8
|
+
field :status
|
9
|
+
end
|
10
|
+
|
11
|
+
form do
|
12
|
+
field :name
|
13
|
+
field :slug
|
14
|
+
field :layout_name
|
15
|
+
field :status, :select => Page.statuses
|
16
|
+
field :title
|
17
|
+
field :description
|
18
|
+
field :keywords
|
19
|
+
end
|
20
|
+
end
|
data/app/models/page.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
class LayoutError < StandardError
|
2
|
+
end
|
3
|
+
|
4
|
+
class Page < ActiveRecord::Base
|
5
|
+
|
6
|
+
acts_as_nested_set
|
7
|
+
|
8
|
+
scope :with_parts, includes(:page_parts)
|
9
|
+
scope :published, where(:status => 'published')
|
10
|
+
default_scope order(:lft)
|
11
|
+
|
12
|
+
def self.statuses
|
13
|
+
%w(draft hidden published)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.root
|
17
|
+
roots.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.find_page location
|
21
|
+
page = Page.find_by_location location
|
22
|
+
raise ActiveRecord::RecordNotFound if page.nil? || page.draft?
|
23
|
+
end
|
24
|
+
|
25
|
+
has_many :page_parts, :order => "name = '#{PufferPages::MAIN_PART}' desc, name", :dependent => :destroy
|
26
|
+
belongs_to :layout, :primary_key => :name, :foreign_key => :layout_name
|
27
|
+
|
28
|
+
validates_presence_of :name
|
29
|
+
validate do |page|
|
30
|
+
page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
|
31
|
+
end
|
32
|
+
validates_uniqueness_of :slug, :scope => :parent_id
|
33
|
+
validates_format_of :slug,
|
34
|
+
:with => /\A([a-zA-Z0-9]+[\w-]*(\.[a-zA-Z0-9]+)?|\*)\Z/,
|
35
|
+
:message => :slug_format,
|
36
|
+
:unless => :root?
|
37
|
+
validates_format_of :slug,
|
38
|
+
:with => /\A\/\Z/,
|
39
|
+
:message => :root_slug_format,
|
40
|
+
:if => :root?
|
41
|
+
validates_inclusion_of :status, :in => Page.statuses
|
42
|
+
|
43
|
+
attr_protected :location
|
44
|
+
|
45
|
+
before_validation :set_status
|
46
|
+
def set_status
|
47
|
+
self.status ||= 'draft'
|
48
|
+
end
|
49
|
+
|
50
|
+
before_save :update_location
|
51
|
+
def update_location
|
52
|
+
self.location = [(swallow_nil{parent.location} || '/'), slug].compact.join('/').gsub(/\/+/, '/')
|
53
|
+
end
|
54
|
+
|
55
|
+
before_update :update_locations
|
56
|
+
def update_locations
|
57
|
+
Page.update_all "location = replace(location, '#{location_was}', '#{location}')", ["location like ?", location_was + '%'] if location_changed?
|
58
|
+
end
|
59
|
+
|
60
|
+
after_save :create_main_part
|
61
|
+
def create_main_part
|
62
|
+
page_parts.create(:name => PufferPages::MAIN_PART) if root?
|
63
|
+
end
|
64
|
+
|
65
|
+
statuses.each do |status_name|
|
66
|
+
define_method "#{status_name}?" do status == status_name end
|
67
|
+
end
|
68
|
+
|
69
|
+
def render(drops_or_context)
|
70
|
+
if inherited_layout
|
71
|
+
@template = Liquid::Template.parse(inherited_layout.body)
|
72
|
+
tracker.cleanup @template.render(drops_or_context, :registers => {:tracker => tracker, :page => self})
|
73
|
+
else
|
74
|
+
inherited_page_parts.map{|part| part.render(drops_or_context, true)}.join
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def tracker
|
79
|
+
@tracker ||= PufferPages::Liquid::Tracker.new
|
80
|
+
end
|
81
|
+
|
82
|
+
def inherited_layout_page
|
83
|
+
@inherited_layout_page ||= layout_name? ? self : swallow_nil{parent.inherited_layout_page}
|
84
|
+
end
|
85
|
+
|
86
|
+
def inherited_layout_name
|
87
|
+
@inherited_layout_name ||= swallow_nil{inherited_layout_page.layout_name}
|
88
|
+
end
|
89
|
+
|
90
|
+
def inherited_layout
|
91
|
+
@inherited_layout ||= swallow_nil{inherited_layout_page.layout}
|
92
|
+
end
|
93
|
+
|
94
|
+
def render_layout
|
95
|
+
inherited_layout ? false : inherited_layout_name
|
96
|
+
end
|
97
|
+
|
98
|
+
def inherited_page_parts
|
99
|
+
PagePart.where(:page_id => self_and_ancestors.map(&:id).reverse).group('name').order("name = '#{PufferPages::MAIN_PART}' desc, name")
|
100
|
+
end
|
101
|
+
|
102
|
+
def part name
|
103
|
+
inherited_page_parts.detect {|part| part.name = name}
|
104
|
+
end
|
105
|
+
|
106
|
+
def is_layout?
|
107
|
+
self.location.include?('*')
|
108
|
+
end
|
109
|
+
|
110
|
+
def content_type
|
111
|
+
Rack::Mime.mime_type(File.extname(slug), 'text/html')
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class PagePart < ActiveRecord::Base
|
2
|
+
belongs_to :page
|
3
|
+
|
4
|
+
validates_presence_of :name
|
5
|
+
validates_uniqueness_of :name, :scope => :page_id
|
6
|
+
|
7
|
+
attr_accessor_with_default :additional, false
|
8
|
+
|
9
|
+
def render(drops_or_context, wrap = false)
|
10
|
+
template = Liquid::Template.parse(body)
|
11
|
+
result = tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker})
|
12
|
+
main? ? result : (wrap ? "<% content_for :#{name} do %>#{result}<% end %>" : result)
|
13
|
+
end
|
14
|
+
|
15
|
+
def tracker
|
16
|
+
@tracker ||= PufferPages::Liquid::Tracker.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def main?
|
20
|
+
name == PufferPages::MAIN_PART
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|