puffer_pages 0.0.14 → 0.0.15
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +11 -7
- data/Gemfile.lock +130 -114
- data/Guardfile +20 -0
- data/README.md +3 -3
- data/VERSION +1 -1
- data/app/assets/javascripts/puffer/codemirror-base.js +1 -0
- data/app/assets/javascripts/puffer/codemirror-parser.js +1 -0
- data/app/assets/javascripts/puffer/codemirror.js +1 -0
- data/{spec/dummy/public/puffer/javascripts → app/assets/javascripts/puffer}/puffer_pages.js +11 -0
- data/{lib/generators/puffer_pages/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/right-dialog.js +0 -0
- data/{lib/generators/puffer_pages/install/templates/puffer/javascripts → app/assets/javascripts/puffer}/right-tabs.js +0 -0
- data/app/assets/stylesheets/codemirror.css +135 -0
- data/app/assets/stylesheets/puffer_pages.css +12 -0
- data/{lib/generators/puffer_pages/install/templates/puffer → app/assets}/stylesheets/puffer_tree.css +0 -0
- data/{lib/generators/puffer_pages/install/templates/controllers → app/controllers/admin}/layouts_controller.rb +0 -0
- data/{lib/generators/puffer_pages/install/templates/controllers → app/controllers/admin}/pages_controller.rb +0 -0
- data/{lib/generators/puffer_pages/install/templates/controllers → app/controllers/admin}/snippets_controller.rb +0 -0
- data/app/controllers/pages_controller.rb +2 -2
- data/app/controllers/puffer_pages/layouts_controller.rb +2 -2
- data/app/controllers/puffer_pages/pages_controller.rb +1 -2
- data/app/controllers/puffer_pages/snippets_controller.rb +2 -2
- data/app/helpers/puffer_pages_helper.rb +1 -1
- data/app/models/layout.rb +1 -5
- data/app/models/page.rb +1 -105
- data/app/models/page_part.rb +1 -20
- data/app/models/puffer_pages/layout.rb +8 -0
- data/app/models/puffer_pages/page.rb +107 -0
- data/app/models/puffer_pages/page_part.rb +23 -0
- data/app/models/puffer_pages/snippet.rb +6 -0
- data/app/models/snippet.rb +1 -3
- data/app/views/{puffer_tree → puffer/tree_base}/_record.html.erb +0 -0
- data/app/views/{puffer_tree → puffer/tree_base}/toggle.js.erb +0 -0
- data/app/views/{puffer_tree → puffer/tree_base}/tree.html.erb +0 -0
- data/app/views/puffer_pages/{_page_part_builder.html.erb → pages/_page_part_builder.html.erb} +1 -1
- data/app/views/puffer_pages/{_page_parts.html.erb → pages/_page_parts.html.erb} +0 -0
- data/app/views/puffer_pages/{_tree_page.html.erb → pages/_tree_page.html.erb} +0 -0
- data/config/locales/en.yml +3 -1
- data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090422092419_create_pages.rb +0 -0
- data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090504132337_create_page_parts.rb +0 -0
- data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090506102004_create_layouts.rb +0 -0
- data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090510121824_create_snippets.rb +0 -0
- data/lib/puffer/inputs/page_parts.rb +0 -1
- data/lib/puffer/inputs/page_parts_body.rb +0 -1
- data/lib/puffer/tree_base.rb +1 -2
- data/lib/puffer_pages/engine.rb +0 -4
- data/lib/puffer_pages/liquid/file_system.rb +7 -3
- data/lib/puffer_pages/liquid/page_drop.rb +13 -6
- data/lib/puffer_pages.rb +0 -5
- data/puffer_pages.gemspec +63 -107
- data/spec/dummy/Rakefile +1 -1
- data/spec/dummy/app/assets/images/rails.png +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/controllers/puffer/dashboard_controller.rb +1 -1
- data/spec/dummy/app/controllers/puffer/sessions_controller.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.erb +3 -3
- data/spec/dummy/config/application.rb +4 -8
- data/spec/dummy/config/application.rb.orig +43 -0
- data/spec/dummy/config/boot.rb +5 -7
- data/spec/dummy/config/boot.rb.orig +6 -0
- data/spec/dummy/config/environments/development.rb +4 -3
- data/spec/dummy/config/environments/pg_test.rb +5 -1
- data/spec/dummy/config/environments/production.rb +14 -12
- data/spec/dummy/config/environments/test.rb +5 -1
- data/spec/dummy/config/initializers/secret_token.rb +1 -1
- data/spec/dummy/config/initializers/session_store.rb +1 -1
- data/spec/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/spec/dummy/config/locales/en.yml +1 -1
- data/spec/dummy/config/routes.rb +3 -1
- data/spec/dummy/config/routes.rb.orig +58 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/fabricators/pages_fabricator.rb +1 -0
- data/spec/lib/core_spec.rb +1 -1
- data/spec/lib/drops_spec.rb +13 -8
- data/spec/models/page_spec.rb +4 -3
- data/spec/spec_helper.rb +14 -1
- metadata +200 -288
- data/autotest/discover.rb +0 -2
- data/lib/generators/puffer_pages/install/USAGE +0 -6
- data/lib/generators/puffer_pages/install/install_generator.rb +0 -24
- data/lib/generators/puffer_pages/install/templates/puffer/javascripts/puffer_pages.js +0 -35
- data/lib/generators/puffer_pages/install/templates/puffer/stylesheets/puffer_pages.css +0 -4
- data/lib/generators/puffer_pages/install/templates/puffer_pages.rb +0 -16
- data/spec/dummy/app/controllers/admin/layouts_controller.rb +0 -3
- data/spec/dummy/app/controllers/admin/pages_controller.rb +0 -3
- data/spec/dummy/app/controllers/admin/snippets_controller.rb +0 -3
- data/spec/dummy/config/initializers/puffer.rb +0 -12
- data/spec/dummy/config/initializers/puffer_pages.rb +0 -16
- data/spec/dummy/public/javascripts/application.js +0 -2
- data/spec/dummy/public/javascripts/controls.js +0 -965
- data/spec/dummy/public/javascripts/dragdrop.js +0 -974
- data/spec/dummy/public/javascripts/effects.js +0 -1123
- data/spec/dummy/public/javascripts/prototype.js +0 -6001
- data/spec/dummy/public/javascripts/rails.js +0 -175
- data/spec/dummy/public/puffer/javascripts/puffer.js +0 -10
- data/spec/dummy/public/puffer/javascripts/rails.js +0 -57
- data/spec/dummy/public/puffer/javascripts/right-autocompleter.js +0 -621
- data/spec/dummy/public/puffer/javascripts/right-calendar.js +0 -1461
- data/spec/dummy/public/puffer/javascripts/right-dialog.js +0 -764
- data/spec/dummy/public/puffer/javascripts/right-tabs.js +0 -1144
- data/spec/dummy/public/puffer/javascripts/right.js +0 -5892
- data/spec/dummy/public/puffer/stylesheets/puffer.css +0 -469
- data/spec/dummy/public/puffer/stylesheets/puffer_pages.css +0 -4
- data/spec/dummy/public/puffer/stylesheets/puffer_tree.css +0 -64
- data/spec/dummy/public/puffer/stylesheets/reset.css +0 -60
- data/spec/dummy/public/stylesheets/.gitkeep +0 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
html {
|
2
|
+
cursor: text;
|
3
|
+
}
|
4
|
+
|
5
|
+
.editbox {
|
6
|
+
margin: .4em;
|
7
|
+
padding: 0;
|
8
|
+
font-family: monospace;
|
9
|
+
font-size: 10pt;
|
10
|
+
color: black;
|
11
|
+
}
|
12
|
+
|
13
|
+
pre.code, .editbox {
|
14
|
+
color: #666;
|
15
|
+
}
|
16
|
+
|
17
|
+
.editbox p {
|
18
|
+
margin: 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
span.css-at {
|
22
|
+
color: #708;
|
23
|
+
}
|
24
|
+
|
25
|
+
span.css-unit {
|
26
|
+
color: #281;
|
27
|
+
}
|
28
|
+
|
29
|
+
span.css-value {
|
30
|
+
color: #708;
|
31
|
+
}
|
32
|
+
|
33
|
+
span.css-identifier {
|
34
|
+
color: black;
|
35
|
+
}
|
36
|
+
|
37
|
+
span.css-selector {
|
38
|
+
color: #11B;
|
39
|
+
}
|
40
|
+
|
41
|
+
span.css-important {
|
42
|
+
color: #00F;
|
43
|
+
}
|
44
|
+
|
45
|
+
span.css-colorcode {
|
46
|
+
color: #299;
|
47
|
+
}
|
48
|
+
|
49
|
+
span.css-comment {
|
50
|
+
color: #A70;
|
51
|
+
}
|
52
|
+
|
53
|
+
span.css-string {
|
54
|
+
color: #A22;
|
55
|
+
}
|
56
|
+
|
57
|
+
span.js-punctuation {
|
58
|
+
color: #666666;
|
59
|
+
}
|
60
|
+
|
61
|
+
span.js-operator {
|
62
|
+
color: #666666;
|
63
|
+
}
|
64
|
+
|
65
|
+
span.js-keyword {
|
66
|
+
color: #770088;
|
67
|
+
}
|
68
|
+
|
69
|
+
span.js-atom {
|
70
|
+
color: #228811;
|
71
|
+
}
|
72
|
+
|
73
|
+
span.js-variable {
|
74
|
+
color: black;
|
75
|
+
}
|
76
|
+
|
77
|
+
span.js-variabledef {
|
78
|
+
color: #0000FF;
|
79
|
+
}
|
80
|
+
|
81
|
+
span.js-localvariable {
|
82
|
+
color: #004499;
|
83
|
+
}
|
84
|
+
|
85
|
+
span.js-property {
|
86
|
+
color: black;
|
87
|
+
}
|
88
|
+
|
89
|
+
span.js-comment {
|
90
|
+
color: #AA7700;
|
91
|
+
}
|
92
|
+
|
93
|
+
span.js-string {
|
94
|
+
color: #AA2222;
|
95
|
+
}
|
96
|
+
|
97
|
+
span.xml-tagname {
|
98
|
+
color: #A0B;
|
99
|
+
}
|
100
|
+
|
101
|
+
span.xml-attribute {
|
102
|
+
color: #281;
|
103
|
+
}
|
104
|
+
|
105
|
+
span.xml-punctuation {
|
106
|
+
color: black;
|
107
|
+
}
|
108
|
+
|
109
|
+
span.xml-attname {
|
110
|
+
color: #00F;
|
111
|
+
}
|
112
|
+
|
113
|
+
span.xml-comment {
|
114
|
+
color: #A70;
|
115
|
+
}
|
116
|
+
|
117
|
+
span.xml-cdata {
|
118
|
+
color: #48A;
|
119
|
+
}
|
120
|
+
|
121
|
+
span.xml-processing {
|
122
|
+
color: #999;
|
123
|
+
}
|
124
|
+
|
125
|
+
span.xml-entity {
|
126
|
+
color: #A22;
|
127
|
+
}
|
128
|
+
|
129
|
+
span.xml-error {
|
130
|
+
color: #F00 !important;
|
131
|
+
}
|
132
|
+
|
133
|
+
span.xml-text {
|
134
|
+
color: black;
|
135
|
+
}
|
data/{lib/generators/puffer_pages/install/templates/puffer → app/assets}/stylesheets/puffer_tree.css
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -9,8 +9,8 @@ class PagesController < ApplicationController
|
|
9
9
|
|
10
10
|
def drops
|
11
11
|
{
|
12
|
-
:self => PufferPages::Liquid::PageDrop.new(@page, @page,
|
13
|
-
:root => PufferPages::Liquid::PageDrop.new(@page.root, @page,
|
12
|
+
:self => PufferPages::Liquid::PageDrop.new(@page, @page, self),
|
13
|
+
:root => PufferPages::Liquid::PageDrop.new(@page.root, @page, self)
|
14
14
|
}.stringify_keys
|
15
15
|
end
|
16
16
|
|
@@ -2,7 +2,7 @@ class PufferPages::LayoutsController < Puffer::Base
|
|
2
2
|
unloadable
|
3
3
|
|
4
4
|
setup do
|
5
|
-
group :
|
5
|
+
group :pages
|
6
6
|
end
|
7
7
|
|
8
8
|
index do
|
@@ -11,7 +11,7 @@ class PufferPages::LayoutsController < Puffer::Base
|
|
11
11
|
|
12
12
|
form do
|
13
13
|
field :name
|
14
|
-
field :body
|
14
|
+
field :body, :html => {:codemirror => true}
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -2,7 +2,7 @@ class PufferPages::SnippetsController < Puffer::Base
|
|
2
2
|
unloadable
|
3
3
|
|
4
4
|
setup do
|
5
|
-
group :
|
5
|
+
group :pages
|
6
6
|
end
|
7
7
|
|
8
8
|
index do
|
@@ -11,7 +11,7 @@ class PufferPages::SnippetsController < Puffer::Base
|
|
11
11
|
|
12
12
|
form do
|
13
13
|
field :name
|
14
|
-
field :body
|
14
|
+
field :body, :html => {:codemirror => true}
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -14,7 +14,7 @@ module PufferPagesHelper
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def inherited_layout
|
17
|
-
record.inherited_layout_name && !record.root? ? [[t('
|
17
|
+
record.inherited_layout_name && !record.root? ? [[t('puffer_pages.inherited_layout', :name => record.inherited_layout_name), '']] : []
|
18
18
|
end
|
19
19
|
|
20
20
|
def possible_statuses
|
data/app/models/layout.rb
CHANGED
data/app/models/page.rb
CHANGED
@@ -1,106 +1,2 @@
|
|
1
|
-
class Page <
|
2
|
-
|
3
|
-
acts_as_nested_set
|
4
|
-
|
5
|
-
scope :published, where(:status => 'published')
|
6
|
-
|
7
|
-
def self.statuses
|
8
|
-
%w(draft hidden published)
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.find_page location
|
12
|
-
page = PufferPages.single_section_page_path ?
|
13
|
-
Page.find_by_slug(location) : Page.find_by_location(location)
|
14
|
-
raise ActiveRecord::RecordNotFound if page.nil? || page.draft?
|
15
|
-
page
|
16
|
-
end
|
17
|
-
|
18
|
-
has_many :page_parts, :order => "name = '#{PufferPages.primary_page_part_name}' desc, name", :dependent => :destroy
|
19
|
-
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
20
|
-
belongs_to :layout, :primary_key => :name, :foreign_key => :layout_name
|
21
|
-
|
22
|
-
validates_presence_of :name
|
23
|
-
validates_uniqueness_of :slug, :scope => (:parent_id unless PufferPages.single_section_page_path)
|
24
|
-
validates_inclusion_of :status, :in => Page.statuses
|
25
|
-
validates_format_of :slug,
|
26
|
-
:with => /\A([\w]+[\w-]*(\.[\w]+)?|\*)\Z/,
|
27
|
-
:message => :slug_format,
|
28
|
-
:unless => :root?
|
29
|
-
validate do |page|
|
30
|
-
page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
|
31
|
-
page.errors.add(:slug, :root_slug_format) if page.root? && !page.slug.nil?
|
32
|
-
end
|
33
|
-
|
34
|
-
attr_protected :location
|
35
|
-
|
36
|
-
before_validation :defaultize_attributes
|
37
|
-
def defaultize_attributes
|
38
|
-
self.status ||= 'draft'
|
39
|
-
self.slug = slug.presence
|
40
|
-
self.location = [swallow_nil{parent.location}, slug].compact.join('/').presence
|
41
|
-
end
|
42
|
-
|
43
|
-
before_update :update_locations
|
44
|
-
def update_locations
|
45
|
-
Page.update_all "location = replace(location, '#{location_was}', '#{location}')", ["location like ?", location_was + '%'] if location_changed?
|
46
|
-
end
|
47
|
-
|
48
|
-
after_save :create_main_part
|
49
|
-
def create_main_part
|
50
|
-
page_parts.create(:name => PufferPages.primary_page_part_name) if root?
|
51
|
-
end
|
52
|
-
|
53
|
-
statuses.each do |status_name|
|
54
|
-
define_method "#{status_name}?" do status == status_name end
|
55
|
-
end
|
56
|
-
|
57
|
-
def to_location
|
58
|
-
PufferPages.single_section_page_path ? slug : location
|
59
|
-
end
|
60
|
-
|
61
|
-
def render(drops_or_context)
|
62
|
-
if inherited_layout
|
63
|
-
@template = Liquid::Template.parse(inherited_layout.body)
|
64
|
-
tracker.cleanup @template.render(drops_or_context, :registers => {:tracker => tracker, :page => self, :file_system => PufferPages::Liquid::FileSystem.new})
|
65
|
-
else
|
66
|
-
inherited_page_parts.map{|part| part.render(drops_or_context, self)}.join
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def tracker
|
71
|
-
@tracker ||= PufferPages::Liquid::Tracker.new
|
72
|
-
end
|
73
|
-
|
74
|
-
def inherited_layout_page
|
75
|
-
@inherited_layout_page ||= layout_name? ? self : swallow_nil{parent.inherited_layout_page}
|
76
|
-
end
|
77
|
-
|
78
|
-
def inherited_layout_name
|
79
|
-
@inherited_layout_name ||= swallow_nil{inherited_layout_page.layout_name}
|
80
|
-
end
|
81
|
-
|
82
|
-
def inherited_layout
|
83
|
-
@inherited_layout ||= swallow_nil{inherited_layout_page.layout}
|
84
|
-
end
|
85
|
-
|
86
|
-
def render_layout
|
87
|
-
inherited_layout ? false : inherited_layout_name
|
88
|
-
end
|
89
|
-
|
90
|
-
def inherited_page_parts
|
91
|
-
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
|
92
|
-
end
|
93
|
-
|
94
|
-
def part name
|
95
|
-
inherited_page_parts.detect {|part| part.name == name}
|
96
|
-
end
|
97
|
-
|
98
|
-
def is_layout?
|
99
|
-
self.location.include?('*')
|
100
|
-
end
|
101
|
-
|
102
|
-
def content_type
|
103
|
-
Rack::Mime.mime_type(File.extname(slug.to_s), 'text/html')
|
104
|
-
end
|
105
|
-
|
1
|
+
class Page < PufferPages::Page
|
106
2
|
end
|
data/app/models/page_part.rb
CHANGED
@@ -1,21 +1,2 @@
|
|
1
|
-
class PagePart <
|
2
|
-
belongs_to :page
|
3
|
-
|
4
|
-
validates_presence_of :name
|
5
|
-
validates_uniqueness_of :name, :scope => :page_id
|
6
|
-
|
7
|
-
def render(drops_or_context, page = nil)
|
8
|
-
template = Liquid::Template.parse(body)
|
9
|
-
result = tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker, :page => page, :file_system => PufferPages::Liquid::FileSystem.new})
|
10
|
-
main? ? result : "<% content_for :#{name} do %>#{result}<% end %>"
|
11
|
-
end
|
12
|
-
|
13
|
-
def tracker
|
14
|
-
@tracker ||= PufferPages::Liquid::Tracker.new
|
15
|
-
end
|
16
|
-
|
17
|
-
def main?
|
18
|
-
name == PufferPages.primary_page_part_name
|
19
|
-
end
|
20
|
-
|
1
|
+
class PagePart < PufferPages::PagePart
|
21
2
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
class PufferPages::Page < ActiveRecord::Base
|
2
|
+
self.abstract_class = true
|
3
|
+
|
4
|
+
def self.inherited base
|
5
|
+
base.acts_as_nested_set
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
scope :published, where(:status => 'published')
|
10
|
+
|
11
|
+
def self.statuses
|
12
|
+
%w(draft hidden published)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find_page location
|
16
|
+
page = PufferPages.single_section_page_path ?
|
17
|
+
::Page.find_by_slug(location) : ::Page.find_by_location(location)
|
18
|
+
raise ActiveRecord::RecordNotFound if page.nil? || page.draft?
|
19
|
+
page
|
20
|
+
end
|
21
|
+
|
22
|
+
has_many :page_parts, :order => "name = '#{PufferPages.primary_page_part_name}' desc, name", :dependent => :destroy, :class_name => '::PagePart'
|
23
|
+
accepts_nested_attributes_for :page_parts, :allow_destroy => true
|
24
|
+
belongs_to :layout, :primary_key => :name, :foreign_key => :layout_name, :class_name => '::Layout'
|
25
|
+
|
26
|
+
validates_presence_of :name
|
27
|
+
validates_uniqueness_of :slug, :scope => (:parent_id unless PufferPages.single_section_page_path)
|
28
|
+
validates_inclusion_of :status, :in => statuses
|
29
|
+
validates_format_of :slug, :with => /\A\s*\Z/, :message => :root_slug_format, :if => :root?
|
30
|
+
validates_format_of :slug, :with => /\A([\w]+[\w-]*(\.[\w]+)?|\*)\Z/, :message => :slug_format, :unless => :root?
|
31
|
+
validate do |page|
|
32
|
+
page.errors.add(:layout_name, :blank) unless page.inherited_layout_name.present?
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_protected :location
|
36
|
+
|
37
|
+
before_validation :defaultize_attributes
|
38
|
+
def defaultize_attributes
|
39
|
+
self.status ||= 'draft'
|
40
|
+
self.slug = slug.presence
|
41
|
+
self.location = [swallow_nil{parent.location}, slug].compact.join('/').presence
|
42
|
+
end
|
43
|
+
|
44
|
+
before_update :update_locations
|
45
|
+
def update_locations
|
46
|
+
self.class.update_all "location = replace(location, '#{location_was}', '#{location}')", ["location like ?", location_was + '%'] if location_changed?
|
47
|
+
end
|
48
|
+
|
49
|
+
after_save :create_main_part
|
50
|
+
def create_main_part
|
51
|
+
page_parts.create(:name => PufferPages.primary_page_part_name) if root?
|
52
|
+
end
|
53
|
+
|
54
|
+
statuses.each do |status_name|
|
55
|
+
define_method "#{status_name}?" do status == status_name end
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_location
|
59
|
+
PufferPages.single_section_page_path ? slug : location
|
60
|
+
end
|
61
|
+
|
62
|
+
def render(drops_or_context)
|
63
|
+
if inherited_layout
|
64
|
+
@template = Liquid::Template.parse(inherited_layout.body)
|
65
|
+
tracker.cleanup @template.render(drops_or_context, :registers => {:tracker => tracker, :page => self, :file_system => PufferPages::Liquid::FileSystem.new})
|
66
|
+
else
|
67
|
+
inherited_page_parts.map{|part| part.render(drops_or_context, self)}.join
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def tracker
|
72
|
+
@tracker ||= PufferPages::Liquid::Tracker.new
|
73
|
+
end
|
74
|
+
|
75
|
+
def inherited_layout_page
|
76
|
+
@inherited_layout_page ||= layout_name? ? self : swallow_nil{parent.inherited_layout_page}
|
77
|
+
end
|
78
|
+
|
79
|
+
def inherited_layout_name
|
80
|
+
@inherited_layout_name ||= swallow_nil{inherited_layout_page.layout_name}
|
81
|
+
end
|
82
|
+
|
83
|
+
def inherited_layout
|
84
|
+
@inherited_layout ||= swallow_nil{inherited_layout_page.layout}
|
85
|
+
end
|
86
|
+
|
87
|
+
def render_layout
|
88
|
+
inherited_layout ? false : inherited_layout_name
|
89
|
+
end
|
90
|
+
|
91
|
+
def inherited_page_parts
|
92
|
+
::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
|
93
|
+
end
|
94
|
+
|
95
|
+
def part name
|
96
|
+
inherited_page_parts.detect {|part| part.name == name}
|
97
|
+
end
|
98
|
+
|
99
|
+
def is_layout?
|
100
|
+
self.location.include?('*')
|
101
|
+
end
|
102
|
+
|
103
|
+
def content_type
|
104
|
+
Rack::Mime.mime_type(File.extname(slug.to_s), 'text/html')
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class PufferPages::PagePart < ActiveRecord::Base
|
2
|
+
self.abstract_class = true
|
3
|
+
|
4
|
+
belongs_to :page, :class_name => '::Page'
|
5
|
+
|
6
|
+
validates_presence_of :name
|
7
|
+
validates_uniqueness_of :name, :scope => :page_id
|
8
|
+
|
9
|
+
def render(drops_or_context, page = nil)
|
10
|
+
template = Liquid::Template.parse(body)
|
11
|
+
result = tracker.cleanup template.render(drops_or_context, :registers => {:tracker => tracker, :page => page, :file_system => PufferPages::Liquid::FileSystem.new})
|
12
|
+
main? ? result : "<% content_for :#{name} do %>#{result}<% end %>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def tracker
|
16
|
+
@tracker ||= PufferPages::Liquid::Tracker.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def main?
|
20
|
+
name == PufferPages.primary_page_part_name
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/app/models/snippet.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/app/views/puffer_pages/{_page_part_builder.html.erb → pages/_page_part_builder.html.erb}
RENAMED
@@ -1,3 +1,3 @@
|
|
1
1
|
<%= page_part_builder.puffer_field :name, :type => :hidden %>
|
2
|
-
<%= page_part_builder.puffer_field :body, :type => :page_parts_body %>
|
2
|
+
<%= page_part_builder.puffer_field :body, :type => :page_parts_body, :html => {:codemirror => true} %>
|
3
3
|
<%= page_part_builder.puffer_field :_destroy, :type => :hidden, :html => { :class => 'destroy_mark' } %>
|
File without changes
|
File without changes
|
data/config/locales/en.yml
CHANGED
data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090422092419_create_pages.rb
RENAMED
File without changes
|
File without changes
|
data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090506102004_create_layouts.rb
RENAMED
File without changes
|
data/{lib/generators/puffer_pages/install/templates → db}/migrate/20090510121824_create_snippets.rb
RENAMED
File without changes
|
data/lib/puffer/tree_base.rb
CHANGED
data/lib/puffer_pages/engine.rb
CHANGED
@@ -2,10 +2,6 @@ module PufferPages
|
|
2
2
|
class Engine < Rails::Engine
|
3
3
|
config.autoload_paths << File.join(root, 'lib')
|
4
4
|
|
5
|
-
initializer 'puffer_pages.add_cells_paths', :after => :add_view_paths do
|
6
|
-
::Cell::Base.prepend_view_path(Cells::DEFAULT_VIEW_PATHS.map { |path| File.join(root, path) })
|
7
|
-
end
|
8
|
-
|
9
5
|
initializer 'puffer_pages.add_puffer_pages_route', :after => :add_builtin_route do |app|
|
10
6
|
app.routes_reloader.paths << File.join(root, 'config/puffer_routes.rb')
|
11
7
|
end
|
@@ -2,15 +2,18 @@ module PufferPages
|
|
2
2
|
module Liquid
|
3
3
|
class FileSystem < ::Liquid::BlankFileSystem
|
4
4
|
|
5
|
-
def read_template_file(
|
6
|
-
template_path = context[template_name]
|
7
|
-
|
5
|
+
def read_template_file(template_path, context)
|
8
6
|
case template_type template_path
|
9
7
|
when :snippet then
|
10
8
|
template_path = template_path.gsub(/^snippets\//, '')
|
11
9
|
snippet = Snippet.find_by_name(template_path)
|
12
10
|
raise ::Liquid::FileSystemError, "No such snippet '#{template_path}' found" unless snippet
|
13
11
|
snippet.body
|
12
|
+
when :layout then
|
13
|
+
template_path = template_path.gsub(/^layouts\//, '')
|
14
|
+
layout = Layout.find_by_name(template_path)
|
15
|
+
raise ::Liquid::FileSystemError, "No such layout '#{template_path}' found" unless layout
|
16
|
+
layout.body
|
14
17
|
when :page_part then
|
15
18
|
page_part = context.registers[:page].part(template_path)
|
16
19
|
raise ::Liquid::FileSystemError, "No such page_part '#{template_path}' found for current page" unless page_part
|
@@ -20,6 +23,7 @@ module PufferPages
|
|
20
23
|
|
21
24
|
def template_type template_path
|
22
25
|
return :snippet if template_path.start_with? 'snippets/'
|
26
|
+
return :layout if template_path.start_with? 'layouts/'
|
23
27
|
return :page_part
|
24
28
|
end
|
25
29
|
|
@@ -6,14 +6,16 @@ module PufferPages
|
|
6
6
|
include Rails.application.routes.url_helpers
|
7
7
|
|
8
8
|
delegate *(Page.statuses.map {|s| "#{s}?"} << {:to => :page})
|
9
|
-
delegate :
|
9
|
+
delegate :name, :title, :description, :keywords, :created_at, :updated_at, :to => :page
|
10
10
|
|
11
|
-
def initialize page, current_page = nil,
|
12
|
-
@page, @
|
11
|
+
def initialize page, current_page = nil, controller = nil
|
12
|
+
@page, @current_page, @controller = page, current_page, controller
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
%w(parent root).each do |attribute|
|
16
|
+
define_method attribute do
|
17
|
+
instance_variable_get("@#{attribute}") || instance_variable_set("@#{attribute}", self.class.new(page.parent, current_page, request))
|
18
|
+
end
|
17
19
|
end
|
18
20
|
|
19
21
|
%w(ancestors self_and_ancestors children self_and_children siblings self_and_siblings descendants, self_and_descendants).each do |attribute|
|
@@ -42,9 +44,14 @@ module PufferPages
|
|
42
44
|
page.id == drop.send(:page).id
|
43
45
|
end
|
44
46
|
|
47
|
+
def before_method method
|
48
|
+
swallow_nil{page.part(method).body}
|
49
|
+
end
|
50
|
+
|
45
51
|
private
|
46
52
|
|
47
|
-
attr_reader :page, :
|
53
|
+
attr_reader :page, :current_page, :controller
|
54
|
+
delegate :env, :request, :to => :controller, :allow_nil => true
|
48
55
|
|
49
56
|
end
|
50
57
|
end
|