caboose-cms 0.4.7 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/controllers/caboose/pages_controller.rb +22 -2
- data/app/models/caboose/block.rb +19 -0
- data/app/models/caboose/block_type.rb +21 -1
- data/app/models/caboose/block_type_source.rb +55 -30
- data/app/models/caboose/schema.rb +6 -2
- data/app/views/caboose/block_type_sources/admin_edit.html.erb +1 -1
- data/app/views/caboose/blocks/_layout_basic.html.erb +1 -1
- data/app/views/caboose/pages/admin_edit_content.html.erb +14 -9
- data/app/views/caboose/pages/admin_edit_general.html.erb +1 -3
- data/app/views/caboose/pages/admin_edit_layout.html.erb +46 -0
- data/config/routes.rb +3 -1
- data/lib/caboose/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWRkMDE4MzQwODc3N2YyMTQ5ZmY4Mzc3MjkyNjFjNzJlYjBmNDBhNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWRmMzJmNjEyNjdkZGNjNDM0MTAwNzFjZWVhZGUwNmU2MzRlMmNiMA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NzhhNGFlMmU1NDE1NzFmZjNhMDMwNGIwZjk0ZjA5MDQzM2ZmMDEyY2QzOTdj
|
10
|
+
MTg2ZmIyOWFjZTkxNjgxNGFiN2UwMTBjMjQ4OWQ4OTNiNjE0YmQ2ZDI0ZDM2
|
11
|
+
MDIxY2Q1Yjg3YmI4YTQxYmYxYzM0MGQ4N2JlYmViN2M1YmYyODI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGMyODJlYWI0YjZlODkzYThkNjFkZGJiYjZlMTQ5NmM0NzFjN2EyN2JjNDI1
|
14
|
+
ZjQzM2JhODQ4ZjU1MGI1ODU0MzE2NGI3NmE0ZjMwOWUzYTFjODJjYWVhZTI2
|
15
|
+
NmY4ZDBlNWJiZjg3NDNhNGZhZDI2MWViMDkyOTJiODUyNmI0NDM=
|
@@ -131,11 +131,31 @@ module Caboose
|
|
131
131
|
def admin_edit_content
|
132
132
|
return unless user_is_allowed('pages', 'edit')
|
133
133
|
@page = Page.find(params[:id])
|
134
|
-
|
135
|
-
#
|
134
|
+
#if @page.top_level_blocks.nil? || @page.top_level_blocks.count == 0
|
135
|
+
# redirect_to '/admin/page/:id/layout'
|
136
|
+
# return
|
137
|
+
#end
|
136
138
|
@editing = true
|
137
139
|
end
|
138
140
|
|
141
|
+
# GET /admin/pages/:id/layout
|
142
|
+
def admin_edit_layout
|
143
|
+
return unless user_is_allowed('pages', 'edit')
|
144
|
+
@page = Page.find(params[:id])
|
145
|
+
render :layout => 'caboose/admin'
|
146
|
+
end
|
147
|
+
|
148
|
+
# PUT /admin/pages/:id/layout
|
149
|
+
def admin_update_layout
|
150
|
+
return unless user_is_allowed('pages', 'edit')
|
151
|
+
bt = BlockType.find(params[:block_type_id])
|
152
|
+
Block.create(:page_id => params[:id], :block_type_id => params[:block_type_id], :name => bt.name)
|
153
|
+
resp = Caboose::StdClass.new({
|
154
|
+
'redirect' => "/admin/pages/#{params[:id]}/content"
|
155
|
+
})
|
156
|
+
render :json => resp
|
157
|
+
end
|
158
|
+
|
139
159
|
# GET /admin/pages/:id/block-order
|
140
160
|
def admin_edit_block_order
|
141
161
|
return unless user_is_allowed('pages', 'edit')
|
data/app/models/caboose/block.rb
CHANGED
@@ -142,6 +142,25 @@ class Caboose::Block < ActiveRecord::Base
|
|
142
142
|
return erb.result(locals.instance_eval { binding })
|
143
143
|
end
|
144
144
|
|
145
|
+
def partial(name, options)
|
146
|
+
defaults = { :modal => false, :empty_text => '', :editing => false, :css => nil, :js => nil }
|
147
|
+
options2 = nil
|
148
|
+
if options.is_a?(Hash)
|
149
|
+
options2 = defaults.merge(options)
|
150
|
+
else
|
151
|
+
options2 = { :modal => options.modal, :empty_text => options.empty_text, :editing => options.editing, :css => options.css, :js => options.js }
|
152
|
+
end
|
153
|
+
options2[:block] = self
|
154
|
+
|
155
|
+
view = ActionView::Base.new(ActionController::Base.view_paths)
|
156
|
+
begin
|
157
|
+
str = view.render(:partial => "caboose/blocks/#{name}", :locals => options2)
|
158
|
+
rescue
|
159
|
+
Caboose.log("Partial caboose/blocks/#{name} doesn't exist.")
|
160
|
+
end
|
161
|
+
return str
|
162
|
+
end
|
163
|
+
|
145
164
|
def child_block_link
|
146
165
|
return "<div class='new_block' id='new_block_#{self.id}'>New Block</div>"
|
147
166
|
end
|
@@ -21,7 +21,9 @@ class Caboose::BlockType < ActiveRecord::Base
|
|
21
21
|
:fixed_placeholder,
|
22
22
|
:options,
|
23
23
|
:options_function,
|
24
|
-
:options_url
|
24
|
+
:options_url,
|
25
|
+
:share, # Whether or not to share the block type in the existing block store.
|
26
|
+
:downloaded # Whether the full block type has been download or just the name and description.
|
25
27
|
|
26
28
|
def render_options(empty_text = nil)
|
27
29
|
return eval(self.options_function)
|
@@ -52,5 +54,23 @@ class Caboose::BlockType < ActiveRecord::Base
|
|
52
54
|
return nil if self.children.nil? || self.children.count == 0
|
53
55
|
return self.children.collect { |bt| bt.api_hash }
|
54
56
|
end
|
57
|
+
|
58
|
+
def parse_api_hash(h)
|
59
|
+
self.name = h['name']
|
60
|
+
self.description = h['description']
|
61
|
+
self.block_type_category_id = h['block_type_category_id']
|
62
|
+
self.render_function = h['render_function']
|
63
|
+
self.use_render_function = h['use_render_function']
|
64
|
+
self.use_render_function_for_layout = h['use_render_function_for_layout']
|
65
|
+
self.allow_child_blocks = h['allow_child_blocks']
|
66
|
+
self.field_type = h['field_type']
|
67
|
+
self.default = h['default']
|
68
|
+
self.width = h['width']
|
69
|
+
self.height = h['height']
|
70
|
+
self.fixed_placeholder = h['fixed_placeholder']
|
71
|
+
self.options = h['options']
|
72
|
+
self.options_function = h['options_function']
|
73
|
+
self.options_url = h['options_url']
|
74
|
+
end
|
55
75
|
|
56
76
|
end
|
@@ -11,10 +11,11 @@ class Caboose::BlockTypeSource < ActiveRecord::Base
|
|
11
11
|
:priority,
|
12
12
|
:active
|
13
13
|
|
14
|
-
|
14
|
+
# Just get the names and descriptions of all block types from the source
|
15
|
+
def refresh_names
|
15
16
|
resp = nil
|
16
|
-
begin
|
17
|
-
resp = HTTParty.get("#{self.url}/block-types?token=#{self.token}")
|
17
|
+
begin
|
18
|
+
resp = HTTParty.get("#{self.url}/caboose/block-types?token=#{self.token}")
|
18
19
|
rescue HTTParty::Error => e
|
19
20
|
Caboose.log(e.message)
|
20
21
|
return false
|
@@ -28,37 +29,61 @@ class Caboose::BlockTypeSource < ActiveRecord::Base
|
|
28
29
|
return false
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
#end
|
32
|
+
block_types.each do |h|
|
33
|
+
next if Caboose::BlockType.where(:name => bt.name).exists?
|
34
|
+
Caboose::BlockType.create(:name => h['name'], :description => h['description'])
|
35
|
+
end
|
36
36
|
|
37
37
|
return true
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
:use_render_function => bt.use_render_function,
|
48
|
-
:use_render_function_for_layout => bt.use_render_function_for_layout,
|
49
|
-
:allow_child_blocks => bt.allow_child_blocks,
|
50
|
-
:field_type => bt.field_type,
|
51
|
-
:default => bt.default,
|
52
|
-
:width => bt.width,
|
53
|
-
:height => bt.height,
|
54
|
-
:fixed_placeholder => bt.fixed_placeholder,
|
55
|
-
:options => bt.options,
|
56
|
-
:options_function => bt.options_function,
|
57
|
-
:options_url => bt.options_url
|
58
|
-
)
|
59
|
-
bt.children.each do |bt3|
|
60
|
-
self.recursive_add(bt3, bt2.id)
|
40
|
+
# Get the full block type (including children)
|
41
|
+
def refresh(name, force = false)
|
42
|
+
bt = Caboose::BlockType.where(:name => name).first
|
43
|
+
bt = Caboose::BlockType.create(:name => name) if bt.nil?
|
44
|
+
return if bt.downloaded && !force
|
45
|
+
if force
|
46
|
+
bt.children.each { |bt2| bt2.destroy }
|
61
47
|
end
|
62
|
-
end
|
63
48
|
|
49
|
+
# Try to contact the source URL
|
50
|
+
resp = nil
|
51
|
+
begin
|
52
|
+
resp = HTTParty.get("#{self.url}/caboose/block-types/#{bt.name}?token=#{self.token}")
|
53
|
+
rescue HTTParty::Error => e
|
54
|
+
Caboose.log(e.message)
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
|
58
|
+
# Try to parse the response
|
59
|
+
h = nil
|
60
|
+
begin
|
61
|
+
h = JSON.parse(resp.body)
|
62
|
+
rescue
|
63
|
+
Caboose.log("Response body isn't valid JSON.")
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
# Grab all the fields from the hash for the top-level block
|
68
|
+
bt.parse_api_hash(h)
|
69
|
+
bt.save
|
70
|
+
|
71
|
+
# Now add all the children
|
72
|
+
h['children'].each do |h2|
|
73
|
+
recursive_add(h2, bt.id)
|
74
|
+
end
|
75
|
+
|
76
|
+
return true
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.recursive_add(h, parent_id = nil)
|
80
|
+
bt = Caboose::BlockType.new(:parent_id => parent_id)
|
81
|
+
bt.parse_api_hash(h)
|
82
|
+
bt.save
|
83
|
+
|
84
|
+
h['children'].each do |h2|
|
85
|
+
self.recursive_add(h2, bt.id)
|
86
|
+
end
|
87
|
+
return bt
|
88
|
+
end
|
64
89
|
end
|
@@ -138,7 +138,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
138
138
|
[ :render_function , :text ],
|
139
139
|
[ :use_render_function , :boolean , { :default => false }],
|
140
140
|
[ :use_render_function_for_layout , :boolean , { :default => false }],
|
141
|
-
[ :allow_child_blocks , :boolean , { :default => false }],
|
141
|
+
[ :allow_child_blocks , :boolean , { :default => false }],
|
142
142
|
|
143
143
|
# Used for field values
|
144
144
|
[ :field_type , :string ],
|
@@ -148,7 +148,11 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
148
148
|
[ :fixed_placeholder , :boolean ],
|
149
149
|
[ :options , :text ],
|
150
150
|
[ :options_function , :text ],
|
151
|
-
[ :options_url , :string ]
|
151
|
+
[ :options_url , :string ],
|
152
|
+
|
153
|
+
# Used for sharing block types
|
154
|
+
[ :share , :boolean , { :default => true }],
|
155
|
+
[ :downloaded , :boolean , { :default => false }]
|
152
156
|
],
|
153
157
|
Caboose::BlockTypeCategory => [
|
154
158
|
[ :parent_id , :integer ],
|
@@ -50,7 +50,7 @@ function refresh_block_types(bts_id)
|
|
50
50
|
type: 'get',
|
51
51
|
success: function(resp) {
|
52
52
|
if (resp.error) $('#message').empty().append($('<p/>').addClass('note error').html(resp.error));
|
53
|
-
if (resp.success) $('#message').empty().append($('<p/>').addClass('note success').html(resp.
|
53
|
+
if (resp.success) $('#message').empty().append($('<p/>').addClass('note success').html(resp.success));
|
54
54
|
}
|
55
55
|
});
|
56
56
|
}
|
@@ -21,7 +21,7 @@ page = block.page
|
|
21
21
|
<div class="container" id='block_<%= block.id %>'>
|
22
22
|
<!--[if lt IE 7]>
|
23
23
|
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
|
24
|
-
<![endif]-->
|
24
|
+
<![endif]-->
|
25
25
|
<%= raw block.render('header' , local_assigns) %>
|
26
26
|
<%= raw block.render('content', local_assigns) %>
|
27
27
|
<%= raw block.render('footer' , local_assigns) %>
|
@@ -1,18 +1,23 @@
|
|
1
1
|
|
2
2
|
<% content_for :caboose_css do %>
|
3
3
|
<style type='text/css'>
|
4
|
-
#
|
4
|
+
#tiny_header {
|
5
5
|
display: block;
|
6
6
|
color: #fff;
|
7
7
|
background-image: url(/assets/caboose/caboose_logo_small.png);
|
8
8
|
background-color: #000;
|
9
9
|
background-repeat: no-repeat;
|
10
|
-
background-position:
|
11
|
-
padding:
|
10
|
+
background-position: right 0;
|
11
|
+
padding: 0 50px 0 10px;
|
12
12
|
position: absolute;
|
13
13
|
top: 0px;
|
14
14
|
right: 0px;
|
15
|
-
z-index: 100;
|
15
|
+
z-index: 100;
|
16
|
+
}
|
17
|
+
#tiny_header a {
|
18
|
+
display: inline-block;
|
19
|
+
color: #fff;
|
20
|
+
padding: 16px 10px;
|
16
21
|
}
|
17
22
|
.block_over { background: #fff799; }
|
18
23
|
</style>
|
@@ -28,11 +33,11 @@ var controller = false;
|
|
28
33
|
$(document).ready(function() {
|
29
34
|
controller = new PageContentController(<%= @page.id %>);
|
30
35
|
|
31
|
-
$('body').append($('<
|
32
|
-
.attr('id', '
|
33
|
-
.attr('href', '/admin/pages/<%= @page.id %>/edit')
|
34
|
-
.
|
35
|
-
);
|
36
|
+
$('body').append($('<div/>')
|
37
|
+
.attr('id', 'tiny_header')
|
38
|
+
.append($('<a/>').attr('href', '/admin/pages/<%= @page.id %>/edit').html("< Back"))
|
39
|
+
.append($('<a/>').attr('href', '/admin/pages/<%= @page.id %>/layout').html("Layout"))
|
40
|
+
);
|
36
41
|
});
|
37
42
|
|
38
43
|
</script>
|
@@ -9,7 +9,6 @@
|
|
9
9
|
<div class='field_with_explanation'><div id='page_<%= @page.id %>_alias' ></div><span class='explanation'>Starts the URL over at the domain root.</span></div>
|
10
10
|
<div class='field_with_explanation'><div id='page_<%= @page.id %>_redirect_url' ></div><span class='explanation'>If the redirect URL field is set, then this page will simply redirect to that URL instead of showing the page itself.</span></div>
|
11
11
|
<div class='field_with_explanation'><div id='page_<%= @page.id %>_hide' ></div><span class='explanation'>Whether or not this page is displayed in the menu.</span></div>
|
12
|
-
<div class='field_with_explanation'><div id='page_<%= @page.id %>_layout' ></div><span class='explanation'>Specify a specific layout file for this page.</span></div>
|
13
12
|
<div class='field_with_explanation'><div id='page_<%= @page.id %>_custom_sort_children' ></div><span class='explanation'>Sort child pages alphabetically or <a href='/admin/pages/<%= @page.id %>/child-order'>custom</a>.</span></div>
|
14
13
|
<div class='field_with_explanation'><div id='page_<%= @page.id %>_content_format' ></div><span class='explanation'>Specify whether or not you want to embed ruby code in your page.</span></div>
|
15
14
|
|
@@ -62,8 +61,7 @@ $(document).ready(function() {
|
|
62
61
|
{ name: 'slug' , nice_name: 'Slug' , type: 'text' , value: <%= raw Caboose.json(@page.slug ) %> , width: 400, after_update: function() { update_uri(<%= @page.id %>); } },
|
63
62
|
{ name: 'alias' , nice_name: 'Alias' , type: 'text' , value: <%= raw Caboose.json(@page.alias ) %> , width: 400, after_update: function() { update_uri(<%= @page.id %>); } },
|
64
63
|
{ name: 'redirect_url' , nice_name: 'Redirect URL' , type: 'text' , value: <%= raw Caboose.json(@page.redirect_url ) %> , width: 400 },
|
65
|
-
{ name: 'hide' , nice_name: 'Hide' , type: 'checkbox' , value: <%= raw @page.hide %> , width: 400 },
|
66
|
-
{ name: 'layout' , nice_name: 'Layout' , type: 'text' , value: <%= raw Caboose.json(@page.layout ) %> , width: 400 },
|
64
|
+
{ name: 'hide' , nice_name: 'Hide' , type: 'checkbox' , value: <%= raw @page.hide %> , width: 400 },
|
67
65
|
{ name: 'custom_sort_children' , nice_name: 'Custom sort children' , type: 'checkbox' , value: <%= raw @page.custom_sort_children %> , width: 400 },
|
68
66
|
{ name: 'content_format' , nice_name: 'Content format' , type: 'select' , value: <%= raw Caboose.json(@page.content_format) %>, width: 400, text: <%= raw Caboose.json(@page.content_format) %>, options_url: '/pages/format-options' },
|
69
67
|
]
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
<%= render :partial => 'caboose/pages/admin_header' %>
|
3
|
+
|
4
|
+
<form action='/admin/pages/<%= @page.id %>' method='put' id='layout_form'>
|
5
|
+
<input type='hidden' name='authenticity_token' value='<%= form_authenticity_token %>' />
|
6
|
+
<p><select name='block_type_id'>
|
7
|
+
<option value=''>-- Select a layout --</option>
|
8
|
+
<% cat_ids = Caboose::BlockTypeCategory.layouts.collect{ |cat| cat.id } %>
|
9
|
+
<% Caboose::BlockType.where("block_type_category_id in (?)", cat_ids).reorder(:description).all.each do |bt| %>
|
10
|
+
<option value="<%= bt.id %>"><%= bt.description %></option>
|
11
|
+
<% end %>
|
12
|
+
</select></p>
|
13
|
+
<div id='message'></div>
|
14
|
+
<p>
|
15
|
+
<input type='button' value='< Back' onclick="window.location='/admin/pages/<%= @page.id %>/edit';" />
|
16
|
+
<input type='submit' value='Update Page Layout' />
|
17
|
+
</p>
|
18
|
+
</form>
|
19
|
+
|
20
|
+
<%= render :partial => 'caboose/pages/admin_footer' %>
|
21
|
+
<% content_for :caboose_js do %>
|
22
|
+
<script type='text/javascript'>
|
23
|
+
|
24
|
+
$(document).ready(function() {
|
25
|
+
$('#layout_form').submit(function() {
|
26
|
+
update_page_layout(<%= @page.id %>);
|
27
|
+
return false;
|
28
|
+
});
|
29
|
+
});
|
30
|
+
|
31
|
+
function update_page_layout(page_id)
|
32
|
+
{
|
33
|
+
$('#message').html("<p class='loading'>Updating layout...</p>");
|
34
|
+
$.ajax({
|
35
|
+
url: '/admin/pages/' + page_id + '/layout',
|
36
|
+
type: 'put',
|
37
|
+
data: $('#layout_form').serialize(),
|
38
|
+
success: function(resp) {
|
39
|
+
if (resp.error) $('#message').html("<p class='note error'>" + resp.error + "</p>");
|
40
|
+
if (resp.redirect) window.location = resp.redirect
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
45
|
+
</script>
|
46
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -83,7 +83,9 @@ Caboose::Engine.routes.draw do
|
|
83
83
|
get "admin/pages/:id/child-order" => "pages#admin_edit_child_sort_order"
|
84
84
|
put "admin/pages/:id/child-order" => "pages#admin_update_child_sort_order"
|
85
85
|
get "admin/pages/:id/new-blocks" => "pages#admin_new_blocks"
|
86
|
-
get "admin/pages/:id/content" => "pages#admin_edit_content"
|
86
|
+
get "admin/pages/:id/content" => "pages#admin_edit_content"
|
87
|
+
get "admin/pages/:id/layout" => "pages#admin_edit_layout"
|
88
|
+
put "admin/pages/:id/layout" => "pages#admin_update_layout"
|
87
89
|
put "admin/pages/:id/viewers" => "pages#admin_update_viewers"
|
88
90
|
put "admin/pages/:id/editors" => "pages#admin_update_editors"
|
89
91
|
put "admin/pages/:id" => "pages#admin_update"
|
data/lib/caboose/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: caboose-cms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -359,6 +359,7 @@ files:
|
|
359
359
|
- app/views/caboose/pages/admin_edit_css.html.erb
|
360
360
|
- app/views/caboose/pages/admin_edit_general.html.erb
|
361
361
|
- app/views/caboose/pages/admin_edit_js.html.erb
|
362
|
+
- app/views/caboose/pages/admin_edit_layout.html.erb
|
362
363
|
- app/views/caboose/pages/admin_edit_permissions.html.erb
|
363
364
|
- app/views/caboose/pages/admin_edit_seo.html.erb
|
364
365
|
- app/views/caboose/pages/admin_index.html.erb
|