spud_cms 0.8.17 → 0.9.0
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/README.markdown +30 -13
- data/app/assets/images/spud/admin/snippets_thumb.png +0 -0
- data/app/assets/images/spud/admin/snippets_thumb@2x.png +0 -0
- data/app/assets/javascripts/spud/admin/cms/application.js +3 -3
- data/app/controllers/pages_controller.rb +6 -23
- data/app/controllers/spud/admin/menu_items_controller.rb +6 -10
- data/app/controllers/spud/admin/menus_controller.rb +1 -1
- data/app/controllers/spud/admin/pages_controller.rb +40 -86
- data/app/controllers/spud/cms/sitemaps_controller.rb +1 -1
- data/app/helpers/spud/cms/application_helper.rb +50 -26
- data/app/models/spud_menu_item.rb +10 -13
- data/app/models/spud_page.rb +12 -4
- data/app/models/spud_page_liquid_tag.rb +4 -0
- data/app/models/spud_page_partial.rb +40 -1
- data/app/observers/page_sweeper.rb +48 -0
- data/app/views/pages/show.html.erb +9 -11
- data/app/views/spud/admin/pages/_form.html.erb +15 -16
- data/app/views/spud/admin/pages/_page_partials_form.html.erb +3 -3
- data/app/views/spud/admin/pages/index.html.erb +1 -1
- data/app/views/spud/admin/pages/show.html.erb +4 -6
- data/config/routes.rb +3 -3
- data/db/migrate/20120911190030_add_symbol_name_to_spud_page_partials.rb +5 -0
- data/db/migrate/20120912121313_modify_site_id_for_spud_pages.rb +15 -0
- data/db/migrate/20121016233715_add_content_processed_to_spud_page_partials.rb +5 -0
- data/db/migrate/20121112151110_add_layout_to_spud_pages.rb +8 -0
- data/db/migrate/20121112212113_create_spud_page_liquid_tags.rb +11 -0
- data/lib/spud_cms.rb +1 -0
- data/lib/spud_cms/configuration.rb +4 -7
- data/lib/spud_cms/engine.rb +37 -16
- data/lib/spud_cms/template_parser.rb +121 -0
- data/lib/spud_cms/version.rb +1 -1
- data/spec/controllers/pages_controller_spec.rb +108 -0
- data/spec/controllers/spud/admin/menu_items_controller_spec.rb +148 -0
- data/spec/controllers/spud/admin/menus_controller_spec.rb +121 -0
- data/spec/controllers/spud/admin/pages_controller_spec.rb +5 -13
- data/spec/controllers/spud/cms/sitemaps_controller_spec.rb +35 -4
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/db/schema.rb +146 -0
- data/spec/dummy/log/development.log +341 -0
- data/spec/dummy/log/test.log +182863 -0
- data/spec/helpers/spud/cms/application_helper_spec.rb +160 -0
- data/spec/models/spud_menu_item_spec.rb +31 -0
- data/spec/models/spud_page_liquid_tag_spec.rb +5 -0
- data/spec/models/spud_page_partial_spec.rb +44 -0
- data/spec/models/spud_page_spec.rb +1 -2
- metadata +50 -19
- data/app/assets/images/spud/admin/templates_thumb.png +0 -0
- data/app/controllers/spud/admin/templates_controller.rb +0 -73
- data/app/models/page_sweeper.rb +0 -63
- data/app/models/spud_template.rb +0 -10
- data/app/views/layouts/spud/admin/cms/detail.html.erb +0 -5
- data/spec/models/spud_template_spec.rb +0 -34
@@ -1,9 +1,9 @@
|
|
1
|
-
<div id="page_partials_form" class="formtabs">
|
2
|
-
<ul class="formtab_buttons">
|
1
|
+
<div id="page_partials_form" class="formtabs tab-content">
|
2
|
+
<ul class="formtab_buttons nav nav-tabs">
|
3
3
|
</ul>
|
4
4
|
<% last_index = 0 %>
|
5
5
|
<% spud_page_partials.each_with_index do |spud_page_partial, index| %>
|
6
|
-
<div class="formtab">
|
6
|
+
<div class="formtab tab-pane">
|
7
7
|
<input type="hidden" class="tab_name" name="spud_page[spud_page_partials_attributes][<%= index %>][name]" value="<%= spud_page_partial.name %>" />
|
8
8
|
<textarea class="wysiwym tinymce" name="spud_page[spud_page_partials_attributes][<%= index %>][content]">
|
9
9
|
<%= spud_page_partial.content %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<%=content_for :data_controls do%>
|
2
|
-
<%=link_to "New Page",new_spud_admin_page_path(),:class => "btn btn-primary",:title => "New Page"%> <%=link_to "Clear Cache",clear_spud_admin_pages_path(),:class => "btn btn-warning",:title => "Clear Page Cache" if Spud::Cms.
|
2
|
+
<%=link_to "New Page",new_spud_admin_page_path(),:class => "btn btn-primary",:title => "New Page"%> <%=link_to "Clear Cache",clear_spud_admin_pages_path(),:class => "btn btn-warning",:title => "Clear Page Cache" if Spud::Cms.cache_mode %>
|
3
3
|
<%end%>
|
4
4
|
|
5
5
|
<%=content_for :detail do%>
|
@@ -6,17 +6,15 @@
|
|
6
6
|
<%end%>
|
7
7
|
|
8
8
|
<%if !@inline.blank?%>
|
9
|
-
<%=render :inline => @inline%>
|
10
|
-
<%else%>
|
11
|
-
<h2><%=@page.name%></h2>
|
9
|
+
<%=render :inline => @inline%>
|
12
10
|
<%end%>
|
13
11
|
<%@page.spud_page_partials.each do |page_partial|%>
|
14
|
-
|
12
|
+
|
15
13
|
<%if(page_partial.name.downcase == 'body' && Spud::Cms.yield_body_as_content_block == false)%>
|
16
|
-
<%=page_partial.
|
14
|
+
<%=page_partial.postprocess_content.html_safe%>
|
17
15
|
<%else%>
|
18
16
|
<%=content_for page_partial.name.parameterize.underscore.to_sym do%>
|
19
|
-
<%=page_partial.
|
17
|
+
<%=page_partial.postprocess_content.html_safe%>
|
20
18
|
<%end%>
|
21
19
|
<%end%>
|
22
20
|
<%end%>
|
data/config/routes.rb
CHANGED
@@ -8,8 +8,8 @@ Rails.application.routes.draw do
|
|
8
8
|
post 'preview'
|
9
9
|
end
|
10
10
|
end
|
11
|
-
resources :templates
|
12
|
-
|
11
|
+
resources :templates
|
12
|
+
|
13
13
|
resources :menus do
|
14
14
|
resources :menu_items
|
15
15
|
end
|
@@ -20,7 +20,7 @@ Rails.application.routes.draw do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
root :to => 'pages#show'
|
23
|
-
|
23
|
+
|
24
24
|
# This is located in lib/spud_cms/page_route.rb to make sure it is loaded last
|
25
25
|
# match "*id", :controller => "pages",:action => "show", :as => "page"
|
26
26
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ModifySiteIdForSpudPages < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
change_column :spud_pages,:site_id,:integer,:default => 0,:null => false
|
4
|
+
change_column :spud_templates,:site_id,:integer,:default => 0,:null => false
|
5
|
+
change_column :spud_menus,:site_id,:integer,:default => 0,:null => false
|
6
|
+
SpudPage.where(:site_id => nil).each {|f| f.site_id = 0 ; f.save}
|
7
|
+
SpudMenu.where(:site_id => nil).each {|f| f.site_id = 0 ; f.save}
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
change_column :spud_pages,:site_id,:integer,:default => nil,:null => true
|
12
|
+
change_column :spud_templates,:site_id,:integer,:default => nil,:null => true
|
13
|
+
change_column :spud_menus,:site_id,:integer,:default => nil,:null => true
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class CreateSpudPageLiquidTags < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spud_page_liquid_tags do |t|
|
4
|
+
t.integer :spud_page_partial_id
|
5
|
+
t.string :tag_name
|
6
|
+
t.string :value
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
add_index :spud_page_liquid_tags, [:tag_name,:value]
|
10
|
+
end
|
11
|
+
end
|
data/lib/spud_cms.rb
CHANGED
@@ -2,16 +2,13 @@ module Spud
|
|
2
2
|
module Cms
|
3
3
|
include ActiveSupport::Configurable
|
4
4
|
|
5
|
-
config_accessor :menus_enabled,:
|
6
|
-
|
7
|
-
self.root_page_name = "home"
|
5
|
+
config_accessor :menus_enabled,:root_page_name,:yield_body_as_content_block,:default_page_layout,:enable_sitemap,:multisite_config,:max_revisions,:template_404, :cache_mode
|
8
6
|
self.menus_enabled = true
|
9
|
-
self.
|
7
|
+
self.root_page_name = "home"
|
10
8
|
self.default_page_layout = 'application'
|
11
|
-
self.default_page_parts = ["Body"]
|
12
9
|
self.yield_body_as_content_block = false
|
13
|
-
self.
|
14
|
-
|
10
|
+
self.cache_mode = nil #Options :full_page, :action
|
11
|
+
|
15
12
|
self.enable_sitemap = true
|
16
13
|
self.max_revisions = 10
|
17
14
|
self.template_404 = nil
|
data/lib/spud_cms/engine.rb
CHANGED
@@ -1,41 +1,62 @@
|
|
1
1
|
require 'spud_core'
|
2
2
|
require 'spud_permalinks'
|
3
3
|
require 'codemirror-rails'
|
4
|
+
require 'liquid'
|
5
|
+
|
4
6
|
module Spud
|
5
7
|
module Cms
|
6
8
|
class Engine < Rails::Engine
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
engine_name :spud_cms
|
10
|
+
|
11
|
+
# config.active_record.observers = [] if config.active_record.observers.nil?
|
12
|
+
# config.active_record.observers += [:page_observer]
|
13
|
+
|
14
|
+
config.generators do |g|
|
15
|
+
g.test_framework :rspec, :view_specs => false
|
16
|
+
end
|
17
|
+
|
13
18
|
initializer :admin do
|
14
19
|
Spud::Core.configure do |config|
|
15
20
|
config.admin_applications += [{:name => "Pages",:thumbnail => "spud/admin/pages_thumb.png",:url => "/spud/admin/pages",:order => 0}]
|
16
21
|
if Spud::Cms.menus_enabled
|
17
22
|
config.admin_applications += [{:name => "Menus",:thumbnail => "spud/admin/menus_thumb.png",:url => "/spud/admin/menus",:order => 2}]
|
18
23
|
end
|
19
|
-
|
20
|
-
config.admin_applications += [{:name => "Templates",:thumbnail => "spud/admin/pages_thumb.png",:url => "/spud/admin/templates",:order => 4}]
|
21
|
-
end
|
24
|
+
|
22
25
|
if Spud::Cms.enable_sitemap == true
|
23
26
|
config.sitemap_urls += [:spud_cms_sitemap_url]
|
24
27
|
end
|
25
|
-
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
initializer :model_overrides_cms do |config|
|
32
|
+
ActiveRecord::Base.class_eval do
|
33
|
+
include Spud::Searchable
|
26
34
|
end
|
27
35
|
end
|
36
|
+
initializer :cms_sweepers do |config|
|
37
|
+
Spud::Admin::ApplicationController.instance_eval do
|
38
|
+
cache_sweeper :page_sweeper, :except => [:show,:index]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
28
42
|
initializer :spud_cms_routes do |config|
|
29
43
|
config.routes_reloader.paths << File.expand_path('../page_route.rb', __FILE__)
|
30
44
|
end
|
31
|
-
|
32
|
-
|
33
|
-
# Rails.application.config.railties_order = [:main_app, :all,Spud::Core::Engine,Spud::Cms::Engine]
|
34
|
-
end
|
35
|
-
initializer :assets do |config|
|
45
|
+
|
46
|
+
initializer :assets do |config|
|
36
47
|
Rails.application.config.assets.precompile += ["spud/admin/cms*"]
|
48
|
+
Spud::Core.append_admin_javascripts('spud/admin/cms/application')
|
49
|
+
Spud::Core.append_admin_stylesheets('spud/admin/cms/application')
|
37
50
|
end
|
38
51
|
|
39
|
-
|
52
|
+
initializer :template_parser do |config|
|
53
|
+
@template_parser = Spud::Cms::TemplateParser.new()
|
54
|
+
end
|
55
|
+
|
56
|
+
def template_parser
|
57
|
+
return @template_parser
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
40
61
|
end
|
41
62
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Spud
|
2
|
+
module Cms
|
3
|
+
class TemplateParser
|
4
|
+
|
5
|
+
|
6
|
+
def layouts(site_short_name=nil)
|
7
|
+
if(site_short_name != nil)
|
8
|
+
return all_layouts.select {|k,v| v[:sites].include?(site_short_name.to_s.downcase)}
|
9
|
+
else
|
10
|
+
return all_layouts
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def all_layouts
|
15
|
+
if @layouts && Rails.env != 'development'
|
16
|
+
return @layouts
|
17
|
+
end
|
18
|
+
@layouts = {}
|
19
|
+
engines.each do |engine|
|
20
|
+
@layouts.merge! process_layouts(engine.root.join('app','views','layouts'))
|
21
|
+
end
|
22
|
+
@layouts.merge! process_layouts(Rails.application.root.join('app','views','layouts'))
|
23
|
+
|
24
|
+
check_for_defaults(@layouts)
|
25
|
+
|
26
|
+
return @layouts
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
private
|
31
|
+
def process_layouts(filepath)
|
32
|
+
layouts = {}
|
33
|
+
Dir.glob(filepath.join("**","*.html.*")) do |template|
|
34
|
+
|
35
|
+
layout = process_layout(template)
|
36
|
+
layouts[layout_path(template)] = layout if !layout.blank?
|
37
|
+
|
38
|
+
end
|
39
|
+
return layouts
|
40
|
+
end
|
41
|
+
|
42
|
+
def process_layout(template)
|
43
|
+
f = File.open(template)
|
44
|
+
header = []
|
45
|
+
f.each_line do |line|
|
46
|
+
header << line
|
47
|
+
break if line.blank?
|
48
|
+
end
|
49
|
+
f.close
|
50
|
+
# puts header
|
51
|
+
if header.blank? == false
|
52
|
+
layout = {:partials => []}
|
53
|
+
|
54
|
+
header.each do |header_line|
|
55
|
+
process_directive(header_line, layout)
|
56
|
+
end
|
57
|
+
layout[:partials] = ["Body"] if layout[:partials].blank?
|
58
|
+
layout[:sites] = [Spud::Core.config.short_name.downcase] if layout[:sites].blank?
|
59
|
+
if layout[:template_name].blank? == false
|
60
|
+
return layout
|
61
|
+
else
|
62
|
+
return nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_for_defaults(layouts)
|
69
|
+
default_layout_path = layout_path(Rails.application.root.join('app','views','layouts',Spud::Cms.default_page_layout))
|
70
|
+
puts("Checking #{default_layout_path}")
|
71
|
+
puts(layouts)
|
72
|
+
if layouts[default_layout_path].blank?
|
73
|
+
layouts[default_layout_path] = {:template_name => "Default", :partials => ["Body"], :sites => [Spud::Core.short_name.downcase], :default => true}
|
74
|
+
else
|
75
|
+
layouts[default_layout_path][:default] = true
|
76
|
+
end
|
77
|
+
|
78
|
+
Spud::Core.multisite_config.each do |config|
|
79
|
+
cms_config = Spud::Cms.site_config_for_short_name(config[:short_name])
|
80
|
+
layout_path = cms_config.blank? == false && cms_config[:default_page_layout].blank? == false ? layout_path(Rails.application.root.join('app','views','layouts',cms_config[:default_page_layout])) : default_layout_path
|
81
|
+
|
82
|
+
layout = layouts[layout_path]
|
83
|
+
if layout.blank?
|
84
|
+
layouts[layout_path] = {:template_name => "Default", :partials => ["Body"], :sites => [config[:short_name].to_s.downcase], :default => true}
|
85
|
+
else
|
86
|
+
layout[layout_path][:sites] << config[:short_name].to_s.downcase
|
87
|
+
layout[layout_path][:default] = true
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
def layout_path(template)
|
94
|
+
dir, base = File.split(template)
|
95
|
+
path_components = dir.split("/")
|
96
|
+
component = path_components.shift
|
97
|
+
while component != "layouts" do
|
98
|
+
component = path_components.shift
|
99
|
+
end
|
100
|
+
path_components << base.downcase.split(".")[0]
|
101
|
+
return "#{path_components.join("/")}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def process_directive(line,layout)
|
105
|
+
if template_matcher = line.match(/\-?\#template\_name\:(.*)/)
|
106
|
+
layout[:template_name] = template_matcher[1].strip
|
107
|
+
end
|
108
|
+
if template_matcher = line.match(/\-?\#html\:(.*)/)
|
109
|
+
layout[:partials] << template_matcher[1].strip
|
110
|
+
end
|
111
|
+
if template_matcher = line.match(/\-?\#site_name\:(.*)/)
|
112
|
+
layout[:sites] = template_matcher[1].split(",").collect {|s| s.strip.downcase}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def engines
|
117
|
+
Rails::Application::Railties.engines
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/spud_cms/version.rb
CHANGED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PagesController do
|
4
|
+
describe :show do
|
5
|
+
before(:each) do
|
6
|
+
Spud::Core.configure do |config|
|
7
|
+
config.site_name = "Test Site"
|
8
|
+
config.multisite_mode_enabled = false
|
9
|
+
config.multisite_config = []
|
10
|
+
end
|
11
|
+
Spud::Cms.configure do |config|
|
12
|
+
config.cache_mode = false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
it "should render a page" do
|
16
|
+
page = FactoryGirl.create(:spud_page)
|
17
|
+
get :show ,:id => page.url_name
|
18
|
+
assigns(:layout).should render_template(:layout => "layouts/#{Spud::Cms.default_page_layout}")
|
19
|
+
response.should be_success
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should render home page if id is blank" do
|
23
|
+
page = FactoryGirl.create(:spud_page,:name => "home")
|
24
|
+
get :show
|
25
|
+
assigns(:page).should == page
|
26
|
+
response.should be_success
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should redirect to new page url from old page url if it was changed" do
|
30
|
+
page = FactoryGirl.create(:spud_page,:name => "about")
|
31
|
+
page.name = "about us"
|
32
|
+
page.save
|
33
|
+
|
34
|
+
get :show, :id => "about"
|
35
|
+
|
36
|
+
response.should redirect_to page_url(:id => "about-us")
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
it "should not allow access to private pages when logged out" do
|
43
|
+
page = FactoryGirl.create(:spud_page,:name => "about",:visibility => 1)
|
44
|
+
|
45
|
+
get :show, :id => "about"
|
46
|
+
response.should redirect_to new_spud_user_session_url()
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "page caching" do
|
50
|
+
before(:each) do
|
51
|
+
Spud::Cms.configure do |config|
|
52
|
+
config.cache_mode = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "authorized login" do
|
60
|
+
before(:each) do
|
61
|
+
activate_authlogic
|
62
|
+
u = SpudUser.new(:login => "testuser",:email => "test@testuser.com",:password => "test",:password_confirmation => "test")
|
63
|
+
u.super_admin = true
|
64
|
+
u.save
|
65
|
+
@user = SpudUserSession.create(u)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should allow access to private pages when logged in" do
|
69
|
+
page = FactoryGirl.create(:spud_page,:name => "about",:visibility => 1)
|
70
|
+
|
71
|
+
get :show, :id => "about"
|
72
|
+
response.should be_success
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "multisite enabled" do
|
77
|
+
before(:each) do
|
78
|
+
Spud::Core.configure do |config|
|
79
|
+
config.site_name = "Test Site"
|
80
|
+
config.multisite_mode_enabled = true
|
81
|
+
config.multisite_config = [{:hosts => ["test.host"], :site_name =>"Site B", :site_id => 1}]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should not show a page on a different site" do
|
86
|
+
page = FactoryGirl.create(:spud_page,:name => "about",:site_id => 0)
|
87
|
+
get :show,:id=>"about"
|
88
|
+
response.response_code.should == 404
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should show the right page" do
|
92
|
+
page = FactoryGirl.create(:spud_page,:name => "about",:site_id => 0)
|
93
|
+
page2 = FactoryGirl.create(:spud_page,:name => "about",:site_id => 1)
|
94
|
+
get :show,:id=>"about"
|
95
|
+
assigns(:page).should == page2
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should return the homepage of the current site" do
|
99
|
+
page = FactoryGirl.create(:spud_page,:name => "home",:site_id => 0)
|
100
|
+
page_site1 = FactoryGirl.create(:spud_page,:name => "home",:site_id => 1)
|
101
|
+
|
102
|
+
get :show
|
103
|
+
assigns(:page).should == page_site1
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|