page_engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.markdown +74 -0
- data/Rakefile +39 -0
- data/app/assets/images/page_engine/add.png +0 -0
- data/app/assets/images/page_engine/bullet_add.png +0 -0
- data/app/assets/images/page_engine/bullet_go.png +0 -0
- data/app/assets/images/page_engine/delete.png +0 -0
- data/app/assets/images/page_engine/page_add.png +0 -0
- data/app/assets/images/page_engine/page_copy.png +0 -0
- data/app/assets/images/page_engine/page_delete.png +0 -0
- data/app/assets/images/page_engine/page_edit.png +0 -0
- data/app/assets/images/page_engine/page_gear.png +0 -0
- data/app/assets/images/page_engine/page_green.png +0 -0
- data/app/assets/images/page_engine/page_hidden.png +0 -0
- data/app/assets/images/page_engine/page_lightning.png +0 -0
- data/app/assets/images/page_engine/page_line.jpg +0 -0
- data/app/assets/images/page_engine/page_red.png +0 -0
- data/app/assets/images/page_engine/pencil.png +0 -0
- data/app/assets/images/page_engine/waiting.gif +0 -0
- data/app/assets/images/page_engine/zoom.png +0 -0
- data/app/assets/javascripts/markitup/sets/css/set.js +52 -0
- data/app/assets/javascripts/markitup/sets/html/set.js +64 -0
- data/app/assets/javascripts/markitup/sets/javascript/set.js +6 -0
- data/app/assets/javascripts/markitup/sets/markdown/set.js +53 -0
- data/app/assets/javascripts/markitup/sets/textile/set.js +57 -0
- data/app/assets/javascripts/page_engine.js +189 -0
- data/app/assets/stylesheets/jquery-ui/smoothness/jquery-ui-1.8.15.custom.css +307 -0
- data/app/assets/stylesheets/markitup/sets/css/style.css +69 -0
- data/app/assets/stylesheets/markitup/sets/html/style.css +58 -0
- data/app/assets/stylesheets/markitup/sets/javascript/style.css +0 -0
- data/app/assets/stylesheets/markitup/sets/markdown/style.css +49 -0
- data/app/assets/stylesheets/markitup/sets/textile/style.css +58 -0
- data/app/assets/stylesheets/markitup/skins/markitup/style.css +147 -0
- data/app/assets/stylesheets/markitup/skins/simple/style.css +118 -0
- data/app/assets/stylesheets/page_engine.css +231 -0
- data/app/controllers/admin/page_snippets_controller.rb +64 -0
- data/app/controllers/admin/pages_controller.rb +167 -0
- data/app/controllers/pages_controller.rb +20 -0
- data/app/helpers/pages_helper.rb +234 -0
- data/app/models/page.rb +233 -0
- data/app/models/page_part.rb +35 -0
- data/app/models/page_role.rb +15 -0
- data/app/models/page_snippet.rb +30 -0
- data/app/views/admin/page_snippets/_form.html.haml +10 -0
- data/app/views/admin/page_snippets/destroy.js.erb +3 -0
- data/app/views/admin/page_snippets/edit.html.haml +6 -0
- data/app/views/admin/page_snippets/index.html.haml +20 -0
- data/app/views/admin/page_snippets/new.html.haml +6 -0
- data/app/views/admin/page_snippets/show.html.erb +20 -0
- data/app/views/admin/pages/_form.html.haml +56 -0
- data/app/views/admin/pages/_page.html.haml +19 -0
- data/app/views/admin/pages/_page_list.html.haml +2 -0
- data/app/views/admin/pages/_page_part_fields.html.haml +9 -0
- data/app/views/admin/pages/destroy.js.erb +1 -0
- data/app/views/admin/pages/duplicate.js.erb +5 -0
- data/app/views/admin/pages/edit.html.haml +9 -0
- data/app/views/admin/pages/index.html.haml +10 -0
- data/app/views/admin/pages/new.html.haml +10 -0
- data/app/views/admin/pages/show.html.erb +100 -0
- data/app/views/admin/pages/sort.js.erb +3 -0
- data/app/views/layouts/admin.html.haml +20 -0
- data/app/views/pages/_nav_item.html.haml +10 -0
- data/app/views/pages/_navigation.html.haml +11 -0
- data/app/views/pages/index.html.erb +2 -0
- data/app/views/pages/show.html.erb +2 -0
- data/config/routes.rb +23 -0
- data/db/migrate/20110814185929_create_page_engine.rb +77 -0
- data/db/seed.rb +8 -0
- data/lib/generators/page_engine/page_engine_generator.rb +59 -0
- data/lib/page_engine/class_methods.rb +4 -0
- data/lib/page_engine/defaults.rb +5 -0
- data/lib/page_engine/engine.rb +4 -0
- data/lib/page_engine/exceptions.rb +4 -0
- data/lib/page_engine/extensions.rb +24 -0
- data/lib/page_engine/helpers.rb +10 -0
- data/lib/page_engine/instance_methods.rb +82 -0
- data/lib/page_engine/routes_finder.rb +23 -0
- data/lib/page_engine.rb +41 -0
- data/lib/tasks/page_engine_tasks.rake +4 -0
- metadata +192 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
= simple_form_for([:admin, @parent, @page]) do |f|
|
2
|
+
= f.error_notification
|
3
|
+
= hidden_field_tag :the_page_id, @page.id
|
4
|
+
|
5
|
+
.inputs
|
6
|
+
= f.input :title
|
7
|
+
= f.input :permalink, :required => false
|
8
|
+
|
9
|
+
.page_parts
|
10
|
+
.input.new_page_part_name
|
11
|
+
%label New page part name
|
12
|
+
= text_field_tag :new_page_part_name
|
13
|
+
= link_to_add_fields 'Add page part', f, :page_parts
|
14
|
+
|
15
|
+
%ul.tabs
|
16
|
+
- @page.page_parts.each do |page_part|
|
17
|
+
%li{ :class => "#{page_part.title.parameterize} #{'tab_with_errors' if page_part.errors.any?}"}
|
18
|
+
= link_to page_part.title, "##{page_part.title.parameterize}_#{page_part.id}"
|
19
|
+
|
20
|
+
= f.simple_fields_for :page_parts do |builder|
|
21
|
+
.page_part{ :id => "#{builder.object.title.parameterize}_#{builder.object.id}" }
|
22
|
+
= render 'page_part_fields', :f => builder
|
23
|
+
|
24
|
+
- unless @roles.empty?
|
25
|
+
= f.association :required_roles, :as => :check_boxes
|
26
|
+
= f.association :excluded_roles, :as => :check_boxes
|
27
|
+
|
28
|
+
= f.input :css, :label => 'CSS', :input_html => { 'data-filter' => 'css' }
|
29
|
+
= f.input :js, :label => 'Javascript', :input_html => { 'data-filter' => 'javascript' }
|
30
|
+
= f.input :meta_description
|
31
|
+
= f.input :meta_keywords
|
32
|
+
= f.input :status, :as => :select, :collection => Page.status_values, :include_blank => false
|
33
|
+
= f.input :no_publish_window, :as => :boolean
|
34
|
+
= f.input :publish_from, :order => [:day, :month, :year]
|
35
|
+
= f.input :publish_to, :order => [:day, :month, :year]
|
36
|
+
= f.input :url
|
37
|
+
|
38
|
+
= f.input :controller_action do
|
39
|
+
= f.select :controller_action, grouped_options_for_select(@routes), :include_blank => true
|
40
|
+
|
41
|
+
= f.input :display_in_menu
|
42
|
+
= f.input :display_in_sitemap
|
43
|
+
= f.input :menu_css_class
|
44
|
+
= f.input :no_link
|
45
|
+
= f.input :layout, :as => :select, :collection => Page.layouts, :include_blank => false
|
46
|
+
|
47
|
+
- if PageEngine.class_exists?('Asset')
|
48
|
+
.field.attached_assets
|
49
|
+
%label Attached assets
|
50
|
+
%br
|
51
|
+
= render 'admin/assets/assets_box', :target => @page
|
52
|
+
|
53
|
+
.actions
|
54
|
+
= f.submit 'Save'
|
55
|
+
or
|
56
|
+
= f.submit 'Save & continue...', :name => 'continue'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
%li{ :class => "page #{page.css_status}", 'data-id' => page.id, :id => "page_#{page.id}" }
|
2
|
+
%div
|
3
|
+
%span{ :class => "icon #{page.css_status}", :title => page.css_status.humanize }
|
4
|
+
= page.css_status.humanize
|
5
|
+
|
6
|
+
= link_to page.title, edit_admin_page_path(page)
|
7
|
+
|
8
|
+
%span.controls
|
9
|
+
= link_to('Add child', new_admin_page_page_path(page), :class => 'icon add', :title => 'Add a child page')
|
10
|
+
= link_to('Edit', edit_admin_page_path(page), :class => 'icon edit', :title => 'Edit this page')
|
11
|
+
= link_to('Destroy', [:admin, page], :confirm => 'Are you sure?', :method => :delete, :class => 'icon delete', :title => 'Delete this page (children move to parent)', :remote => true)
|
12
|
+
= link_to('Duplicate', duplicate_admin_page_path(page), :class => 'icon duplicate', :title => 'Duplicate this page', :remote => true, :method => :post)
|
13
|
+
|
14
|
+
%span.permalink
|
15
|
+
= page.permalink
|
16
|
+
|
17
|
+
%ol{ :id => "page_#{page.id}_children" }
|
18
|
+
= render @pages[page.id] if @pages[page.id]
|
19
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
.delete
|
2
|
+
= f.hidden_field :_destroy
|
3
|
+
= link_to 'Delete', '#', :class => 'icon delete', :title => "Delete the current page part"
|
4
|
+
|
5
|
+
= f.error_notification
|
6
|
+
|
7
|
+
= f.input :title, :class => 'page_part_title'
|
8
|
+
= f.input :filter, :collection => Page.filters, :include_blank => false, :class => 'filter', :input_html => { :class => 'filter', :rel => "page_part_content_#{f.object.id}" }
|
9
|
+
= f.input :content, :input_html => { 'data-filter' => f.object.filter, :class => 'editor ignore_tab', :id => "page_part_content_#{f.object.id}" }
|
@@ -0,0 +1 @@
|
|
1
|
+
$('ol#page_engine').html('<%= escape_javascript(render(@pages[nil])) if @pages[nil] %>').nestedSortable('refresh');
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%h2 Pages
|
2
|
+
%p
|
3
|
+
= link_to 'New root page', new_admin_page_path, :class => 'icon_left add'
|
4
|
+
|
5
|
+
%ol#page_engine.list{ 'data-href' => sort_admin_pages_path }
|
6
|
+
= render @pages[nil] if @pages[nil]
|
7
|
+
|
8
|
+
%p
|
9
|
+
= link_to('Update positions', '#', :id => 'update_page_positions')
|
10
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
<p>
|
2
|
+
<b>Title:</b>
|
3
|
+
<%= @page.title %>
|
4
|
+
</p>
|
5
|
+
|
6
|
+
<p>
|
7
|
+
<b>Name:</b>
|
8
|
+
<%= @page.name %>
|
9
|
+
</p>
|
10
|
+
|
11
|
+
<p>
|
12
|
+
<b>Meta description:</b>
|
13
|
+
<%= @page.meta_description %>
|
14
|
+
</p>
|
15
|
+
|
16
|
+
<p>
|
17
|
+
<b>Meta keywords:</b>
|
18
|
+
<%= @page.meta_keywords %>
|
19
|
+
</p>
|
20
|
+
|
21
|
+
<p>
|
22
|
+
<b>Status:</b>
|
23
|
+
<%= @page.status %>
|
24
|
+
</p>
|
25
|
+
|
26
|
+
<p>
|
27
|
+
<b>Publish from:</b>
|
28
|
+
<%= @page.publish_from %>
|
29
|
+
</p>
|
30
|
+
|
31
|
+
<p>
|
32
|
+
<b>Publish to:</b>
|
33
|
+
<%= @page.publish_to %>
|
34
|
+
</p>
|
35
|
+
|
36
|
+
<p>
|
37
|
+
<b>Parent:</b>
|
38
|
+
<%= @page.parent_id %>
|
39
|
+
</p>
|
40
|
+
|
41
|
+
<p>
|
42
|
+
<b>Lft:</b>
|
43
|
+
<%= @page.lft %>
|
44
|
+
</p>
|
45
|
+
|
46
|
+
<p>
|
47
|
+
<b>Rgt:</b>
|
48
|
+
<%= @page.rgt %>
|
49
|
+
</p>
|
50
|
+
|
51
|
+
<p>
|
52
|
+
<b>Created by:</b>
|
53
|
+
<%= @page.created_by %>
|
54
|
+
</p>
|
55
|
+
|
56
|
+
<p>
|
57
|
+
<b>Permalink:</b>
|
58
|
+
<%= @page.permalink %>
|
59
|
+
</p>
|
60
|
+
|
61
|
+
<p>
|
62
|
+
<b>Url:</b>
|
63
|
+
<%= @page.url %>
|
64
|
+
</p>
|
65
|
+
|
66
|
+
<p>
|
67
|
+
<b>Display in menu:</b>
|
68
|
+
<%= @page.display_in_menu %>
|
69
|
+
</p>
|
70
|
+
|
71
|
+
<p>
|
72
|
+
<b>Display in sitemap:</b>
|
73
|
+
<%= @page.display_in_sitemap %>
|
74
|
+
</p>
|
75
|
+
|
76
|
+
<p>
|
77
|
+
<b>Menu css class:</b>
|
78
|
+
<%= @page.menu_css_class %>
|
79
|
+
</p>
|
80
|
+
|
81
|
+
<p>
|
82
|
+
<b>No link:</b>
|
83
|
+
<%= @page.no_link %>
|
84
|
+
</p>
|
85
|
+
|
86
|
+
<p>
|
87
|
+
<b>Controller:</b>
|
88
|
+
<%= @page.controller %>
|
89
|
+
</p>
|
90
|
+
|
91
|
+
<p>
|
92
|
+
<b>Action:</b>
|
93
|
+
<%= @page.action %>
|
94
|
+
</p>
|
95
|
+
|
96
|
+
<p>
|
97
|
+
<b>Layout:</b>
|
98
|
+
<%= @page.layout %>
|
99
|
+
</p>
|
100
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title PageEngine Admin
|
5
|
+
- if Rails.version.split('.')[1] == '1'
|
6
|
+
= stylesheet_link_tag "application"
|
7
|
+
= javascript_include_tag "application"
|
8
|
+
= csrf_meta_tags
|
9
|
+
- else
|
10
|
+
= stylesheet_link_tag :page_engine
|
11
|
+
= javascript_include_tag 'jquery.min', :page_engine
|
12
|
+
= csrf_meta_tag
|
13
|
+
%body
|
14
|
+
|
15
|
+
%ul#nav
|
16
|
+
%li= link_to('Pages', admin_pages_path)
|
17
|
+
%li= link_to('Page snippets', admin_page_snippets_path)
|
18
|
+
|
19
|
+
#content
|
20
|
+
= yield
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%li{ :class => page_menu_class(page) }
|
2
|
+
- if page.no_link || (page == options[:current] && !options[:link_current])
|
3
|
+
%span= replace_title_for(page)
|
4
|
+
- else
|
5
|
+
= link_to_page(page)
|
6
|
+
|
7
|
+
- if grouped_pages[page.id] && level + 1 <= options['depth']
|
8
|
+
%ul{ :class => "sublist_#{level}"}
|
9
|
+
- grouped_pages[page.id].each do |page|
|
10
|
+
= render 'pages/nav_item', :options => options, :page => page, :grouped_pages => grouped_pages, :level => level + 1
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%ul{ :class => options['class'], :id => options['id'] }
|
2
|
+
- if options['include_root']
|
3
|
+
%li{:class => page_menu_class(root_page)}
|
4
|
+
- if root_page.no_link || (root_page == options['current'] && !options['link_current'])
|
5
|
+
%span= replace_title_for(root_page)
|
6
|
+
- else
|
7
|
+
= link_to_page(root_page)
|
8
|
+
|
9
|
+
- if grouped_pages[root_page.id]
|
10
|
+
- grouped_pages[root_page.id].each do |page|
|
11
|
+
= render 'pages/nav_item', :options => options, :page => page, :grouped_pages => grouped_pages, :level => level
|
data/config/routes.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
resources :pages, :only => [:index, :show]
|
3
|
+
|
4
|
+
namespace :admin do
|
5
|
+
resources :page_parts
|
6
|
+
resources :page_snippets, :except => :show
|
7
|
+
resources :pages do
|
8
|
+
collection do
|
9
|
+
put :sort
|
10
|
+
post :parse_content
|
11
|
+
end
|
12
|
+
|
13
|
+
member do
|
14
|
+
post :duplicate
|
15
|
+
end
|
16
|
+
resources :pages
|
17
|
+
resources :page_parts
|
18
|
+
end
|
19
|
+
|
20
|
+
root :to => "pages#index"
|
21
|
+
end
|
22
|
+
match ":permalink", :to => "pages#show"
|
23
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class CreatePageEngine < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def self.up
|
4
|
+
create_table :pages do |t|
|
5
|
+
t.string :title
|
6
|
+
t.text :meta_description
|
7
|
+
t.text :meta_keywords
|
8
|
+
t.string :status
|
9
|
+
t.datetime :publish_from
|
10
|
+
t.datetime :publish_to
|
11
|
+
t.integer :created_by
|
12
|
+
t.string :permalink
|
13
|
+
t.string :url
|
14
|
+
t.boolean :display_in_menu, :default => true
|
15
|
+
t.boolean :display_in_sitemap, :default => true
|
16
|
+
t.string :menu_css_class
|
17
|
+
t.boolean :no_link, :default => false
|
18
|
+
t.string :controller
|
19
|
+
t.string :action
|
20
|
+
t.string :layout
|
21
|
+
t.text :js
|
22
|
+
t.text :css
|
23
|
+
t.integer :parent_id
|
24
|
+
t.integer :lft
|
25
|
+
t.integer :rgt
|
26
|
+
t.string :authorable_type
|
27
|
+
t.integer :authorable_id
|
28
|
+
|
29
|
+
t.timestamps
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table :page_parts do |t|
|
33
|
+
t.string :title
|
34
|
+
t.text :content
|
35
|
+
t.references :page
|
36
|
+
t.string :filter
|
37
|
+
|
38
|
+
t.timestamps
|
39
|
+
end
|
40
|
+
|
41
|
+
create_table :pages_roles, :id => false do |t|
|
42
|
+
t.integer :page_id, :role_id
|
43
|
+
end
|
44
|
+
|
45
|
+
create_table :page_snippets do |t|
|
46
|
+
t.string :name
|
47
|
+
t.string :filter
|
48
|
+
t.text :content
|
49
|
+
|
50
|
+
t.timestamps
|
51
|
+
end
|
52
|
+
|
53
|
+
create_table :page_roles do |t|
|
54
|
+
t.integer :page_id
|
55
|
+
t.integer :required_role_id
|
56
|
+
t.integer :excluded_role_id
|
57
|
+
end
|
58
|
+
|
59
|
+
add_index :pages, :permalink
|
60
|
+
add_index :pages, [:controller, :action]
|
61
|
+
add_index :pages, :url
|
62
|
+
add_index :page_snippets, :name
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.down
|
66
|
+
remove_index :pages, :permalink
|
67
|
+
remove_index :pages, [:controller, :action]
|
68
|
+
remove_index :pages, :url
|
69
|
+
remove_index :page_snippets, :name
|
70
|
+
|
71
|
+
drop_table :pages
|
72
|
+
drop_table :page_parts
|
73
|
+
drop_table :pages_roles
|
74
|
+
drop_table :page_snippets
|
75
|
+
drop_table :page_roles
|
76
|
+
end
|
77
|
+
end
|
data/db/seed.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
page = Page.create(:title => 'Home')
|
2
|
+
body = page.page_parts.find_by_title('body')
|
3
|
+
body.update_attributes(:filter => 'textile', :content => "h1. Welcome
|
4
|
+
|
5
|
+
Aenean dictum porttitor arcu vitae vehicula. Nullam posuere augue vitae lorem ultrices facilisis? Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent non nisi erat? Donec id eros sed metus lobortis semper sed non nulla. Cras cursus ipsum eget neque imperdiet feugiat. Etiam sed sapien id felis aliquam aliquet. Nam fermentum tempus suscipit.
|
6
|
+
|
7
|
+
Mauris non mi mi, a vulputate nunc! Phasellus aliquam urna nec lorem consectetur in porttitor sapien laoreet! Nam erat elit, aliquam quis auctor et, tempor quis arcu. Cras diam nunc, mollis pharetra pulvinar eu, dapibus in augue. Aenean malesuada nulla ac neque facilisis congue? Nulla interdum euismod eros; at tempor magna sagittis id. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam orci aliquam.
|
8
|
+
)")
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
class PageEngineGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
source_root File.expand_path('../../../../', __FILE__)
|
8
|
+
|
9
|
+
def self.next_migration_number(path)
|
10
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
11
|
+
end
|
12
|
+
|
13
|
+
def install
|
14
|
+
create_migrations
|
15
|
+
copy_stylesheets
|
16
|
+
copy_javascripts
|
17
|
+
copy_images
|
18
|
+
|
19
|
+
copy_file 'app/views/layouts/admin.html.haml', 'app/views/layouts/admin.html.haml'
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def create_migrations
|
25
|
+
begin
|
26
|
+
migration_template 'db/migrate/20110814185929_create_page_engine.rb', 'db/migrate/create_page_engine.rb'
|
27
|
+
rescue Exception => e
|
28
|
+
puts e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def copy_stylesheets
|
33
|
+
directory 'app/assets/stylesheets', 'public/stylesheets'
|
34
|
+
directory 'vendor/assets/stylesheets', 'public/stylesheets'
|
35
|
+
|
36
|
+
puts 'Updating image location'
|
37
|
+
['css', 'textile', 'markdown', 'html', 'javascript'].each do |area|
|
38
|
+
gsub_file "public/stylesheets/markitup/sets/#{area}/style.css", /\/assets\//, '/images/'
|
39
|
+
end
|
40
|
+
|
41
|
+
['markitup', 'simple'].each do |area|
|
42
|
+
gsub_file "public/stylesheets/markitup/skins/#{area}/style.css", /\/assets\//, '/images/'
|
43
|
+
end
|
44
|
+
|
45
|
+
gsub_file "public/stylesheets/page_engine.css", /\/assets\//, '/images/'
|
46
|
+
end
|
47
|
+
|
48
|
+
def copy_javascripts
|
49
|
+
directory 'app/assets/javascripts', 'public/javascripts'
|
50
|
+
directory 'vendor/assets/javascripts', 'public/javascripts'
|
51
|
+
end
|
52
|
+
|
53
|
+
def copy_images
|
54
|
+
directory 'app/assets/images', 'public/images'
|
55
|
+
directory 'vendor/assets/images', 'public/images'
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'page_engine/class_methods'
|
2
|
+
require 'page_engine/instance_methods'
|
3
|
+
require 'page_engine/exceptions'
|
4
|
+
|
5
|
+
class << ActionController::Base
|
6
|
+
def page_engine(options = {})
|
7
|
+
|
8
|
+
# Check options
|
9
|
+
raise PageEngine::PageEngineException.new("Options for page_engine must be in a hash.") unless options.is_a? Hash
|
10
|
+
options.each do |key, value|
|
11
|
+
unless [:layouts].include?(key)
|
12
|
+
raise PageEngine::PageEngineException.new("Unknown option for page_engine: #{key.inspect} => #{value.inspect}.")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
include PageEngine::InstanceMethods
|
17
|
+
extend PageEngine::ClassMethods
|
18
|
+
|
19
|
+
before_filter :find_page
|
20
|
+
layout :get_layout
|
21
|
+
|
22
|
+
Page.layouts = options[:layouts].is_a?(Array) ? options[:layouts] : ['application']
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module PageEngine
|
2
|
+
module InstanceMethods
|
3
|
+
def get_layout
|
4
|
+
if @page
|
5
|
+
@page.layout.blank? ? Page.default_layout : @page.layout
|
6
|
+
else
|
7
|
+
Page.default_layout
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def find_page permalink=nil
|
12
|
+
current_user = nil unless defined?(current_user)
|
13
|
+
|
14
|
+
unless params[:controller].split('/').first == "admin"
|
15
|
+
if permalink
|
16
|
+
@page = Page.includes(:page_parts).published.viewable_by(current_user).where(:permalink => permalink)
|
17
|
+
else
|
18
|
+
@page = Page.includes(:page_parts).published.viewable_by(current_user).with_url(request, params).first
|
19
|
+
end
|
20
|
+
# See http://stackoverflow.com/questions/1595424/request-format-returning
|
21
|
+
# This last format appears when the page is refreshed in IE
|
22
|
+
get_breadcrumbs if request.format.html? || request.format == '*/*'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def page_title_replace models=[]
|
27
|
+
models.each do |m|
|
28
|
+
key = m.class.to_s.underscore
|
29
|
+
@page.title.scan(/\{\{#{key}_([_a-z]*)\}\}/).uniq.flatten.each do |attribute|
|
30
|
+
if m.whitelist.include?(attribute) && m.respond_to?(attribute)
|
31
|
+
@page.title.gsub!("{{#{key}_#{attribute}}}", m[attribute])
|
32
|
+
value = m.send(attribute)
|
33
|
+
|
34
|
+
if value.is_a?(Date) || value.is_a?(Time)
|
35
|
+
value = value.to_formatted_s(:short_ordinal)
|
36
|
+
end
|
37
|
+
|
38
|
+
@page.title.gsub!("{{#{key}_#{attribute}}}", value.to_s)
|
39
|
+
else
|
40
|
+
@page.title.gsub!("{{#{key}_#{attribute}}}", "<span style=\"color: red;\">###NOT SUPPORTED, try #{m.whitelist.to_sentence(:two_words_connector => ' or ', :last_word_connector => ', or')}###")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def breadcrumb_replace models=[]
|
47
|
+
models.each do |m|
|
48
|
+
key = m.class.to_s.underscore
|
49
|
+
@breadcrumbs.each do |breadcrumb|
|
50
|
+
if breadcrumb.is_a? Page
|
51
|
+
breadcrumb.title.scan(/\{\{#{key}_([_a-z]*)\}\}/).uniq.flatten.each do |attribute|
|
52
|
+
if m.whitelist.include?(attribute) && m.respond_to?(attribute)
|
53
|
+
breadcrumb.title.gsub!("{{#{key}_#{attribute}}}", m[attribute])
|
54
|
+
value = m.send(attribute)
|
55
|
+
|
56
|
+
if value.is_a?(Date) || value.is_a?(Time)
|
57
|
+
value = value.to_formatted_s(:short_ordinal)
|
58
|
+
end
|
59
|
+
|
60
|
+
breadcrumb.title.gsub!("{{#{key}_#{attribute}}}", value.to_s)
|
61
|
+
else
|
62
|
+
breadcrumb.title.gsub!("{{#{key}_#{attribute}}}", "<span style=\"color: red;\">###NOT SUPPORTED, try one of #{m.whitelist.join(',')}###")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def get_breadcrumbs
|
73
|
+
current_user = nil unless defined?(current_user)
|
74
|
+
if @page
|
75
|
+
@breadcrumbs = @page.ancestors.published.viewable_by(current_user).all
|
76
|
+
else
|
77
|
+
@breadcrumbs = []
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PageEngine
|
2
|
+
class RoutesFinder
|
3
|
+
def self.available
|
4
|
+
available = {}
|
5
|
+
|
6
|
+
Rails.application.routes.routes.each do |route|
|
7
|
+
unless route.requirements.empty?
|
8
|
+
unless ['DELETE'].include?(route.verb.to_s) || route.requirements[:controller].match(/^admin.*/) || ['delete', :delete].include?(route.requirements[:method].to_s)
|
9
|
+
available[route.requirements[:controller]] = [] unless available[route.requirements[:controller]]
|
10
|
+
unless route.requirements[:controller] == 'pages' && route.requirements[:action] == 'show'
|
11
|
+
available[route.requirements[:controller]] << route.requirements[:action] unless available[route.requirements[:controller]].include?(route.requirements[:action])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
available.delete('rails/info')
|
19
|
+
available
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|