caboose-cms 0.2.104 → 0.3.1
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.
- checksums.yaml +8 -8
- data/app/models/caboose/page.rb +10 -2
- data/app/models/caboose/page_block.rb +63 -1
- data/app/models/caboose/page_block_renderer.rb +12 -0
- data/app/models/caboose/page_block_renderer_richtext.rb +68 -0
- data/app/models/caboose/schema.rb +10 -2
- data/app/models/caboose/user.rb +1 -1
- data/app/models/caboose/utilities/schema.rb +20 -1
- data/app/views/caboose/pages/admin_edit_content.html.erb +33 -12
- data/lib/caboose/version.rb +1 -1
- data/lib/tasks/sequences.rake +27 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDIzNzA4ZDY1OGM5YmNjOWRiMGU4NjQxYjE1OWQ1YmJlNGRlNTA5ZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWYxODMxNTQ0YzE1ZWQ2MjkwY2I4NWE0ZWM3Y2M4Yzg0MTAyN2E1OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmMyNjFmZDYxYjcyMWM3ZmQyZTE0NWQ0ZDljODkwMjQ2ZmUyZDNmZDE5ZTg3
|
10
|
+
YThlN2VlNWNlMDc4NWM0YjlkYWNlODZjNzBmNzE5ODVjNTRiNzBkOWNjNWE4
|
11
|
+
NDZiNzIyMjU5NjYwNDgyZmMyMjY5MTMzZmIyMjIzZDA2MjE2M2M=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTgxYjgxMDM2ZWQwZGVkNTg2NjdjMDg3ZGM3ZjliMmJlNDIyMmYyODE0ZWU2
|
14
|
+
ZTU3NDY5OThhNjhhMDZiZTdlZGQ2NWM3ZjZmOWY3ODBlMTUxMDM0NWVkYzhk
|
15
|
+
MjY4M2M2ZDFjOTM4NTU1YTFmNzEwNTJhZTA2NjI3OGExZTMxZmE=
|
data/app/models/caboose/page.rb
CHANGED
@@ -5,11 +5,11 @@ class Caboose::Page < ActiveRecord::Base
|
|
5
5
|
belongs_to :parent, :class_name => "Page"
|
6
6
|
has_many :children, :class_name => "Page", :foreign_key => 'parent_id'
|
7
7
|
has_many :page_permissions
|
8
|
-
has_many :page_blocks
|
8
|
+
has_many :page_blocks, :order => 'sort_order'
|
9
9
|
attr_accessible :parent_id,
|
10
10
|
:title,
|
11
11
|
:menu_title,
|
12
|
-
:content,
|
12
|
+
# :content, # Changed from column in pages to blocks
|
13
13
|
:blocks,
|
14
14
|
:slug,
|
15
15
|
:alias,
|
@@ -38,6 +38,14 @@ class Caboose::Page < ActiveRecord::Base
|
|
38
38
|
return title unless title.nil?
|
39
39
|
return ""
|
40
40
|
end
|
41
|
+
|
42
|
+
def blocks
|
43
|
+
self.page_blocks
|
44
|
+
end
|
45
|
+
|
46
|
+
def content
|
47
|
+
self.blocks.collect { |b| b.content }.join("\n")
|
48
|
+
end
|
41
49
|
|
42
50
|
def self.find_with_fields(page_id, fields)
|
43
51
|
return self.where(:id => page_id).select(fields).first
|
@@ -3,6 +3,68 @@ class Caboose::PageBlock < ActiveRecord::Base
|
|
3
3
|
self.table_name = "page_blocks"
|
4
4
|
|
5
5
|
belongs_to :page
|
6
|
-
attr_accessible :id, :page_id, :
|
6
|
+
attr_accessible :id, :page_id, :block_type, :sort_order, :name, :value
|
7
|
+
|
8
|
+
def render
|
9
|
+
return self["render_#{self.block_type.downcase}".to_sym]
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_richtext() return self.value end
|
13
|
+
def render_p() return "<p>#{self.value}</p>" end
|
14
|
+
def render_h1() return "<h1>#{self.value}</h1>" end
|
15
|
+
def render_h2() return "<h2>#{self.value}</h2>" end
|
16
|
+
def render_h3() return "<h3>#{self.value}</h3>" end
|
17
|
+
def render_h4() return "<h4>#{self.value}</h4>" end
|
18
|
+
def render_h5() return "<h5>#{self.value}</h5>" end
|
19
|
+
def render_h6() return "<h6>#{self.value}</h6>" end
|
20
|
+
|
21
|
+
def render_posts
|
22
|
+
obj = Caboose::StdClass(JSON.parse(self.value))
|
23
|
+
defaults = {
|
24
|
+
'limit' => 10,
|
25
|
+
'no_posts_message' => "<p>There are no posts right now.</p>",
|
26
|
+
'invalid_category_message' => "<p>Invalid post category.</p>",
|
27
|
+
'body_character_limit' => 0
|
28
|
+
}
|
29
|
+
defaults.each { |k,v| obj[k] = v if obj[k].nil? }
|
30
|
+
|
31
|
+
return obj.invalid_category_message if !Caboose::PostCategory.exists?(obj.category_id)
|
32
|
+
cat = Caboose::PostCategory.find(obj.category_id)
|
33
|
+
posts = obj.limit == 0 ? cat.posts.reorder('created_at DESC') : cat.posts.reorder('created_at DESC').limit(obj.limit)
|
34
|
+
return obj.no_posts_message posts.nil? || posts.count == 0
|
35
|
+
|
36
|
+
str = ""
|
37
|
+
posts.each do |p|
|
38
|
+
str = "<div class='post'>"
|
39
|
+
str << "<h2>#{raw p.title}</h2>"
|
40
|
+
str << "<div class='created_at'>#{p.created_at.strftime('%F %T')}</div>"
|
41
|
+
str << "<div class='post_content'>"
|
42
|
+
str << obj.body_character_limit > 0 ? Caboose.teaser_text(p.body, obj.body_character_limit) : p.body
|
43
|
+
str << "</div>"
|
44
|
+
str << "</div>"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
assoc = cat
|
49
|
+
if Caboose
|
50
|
+
|
51
|
+
|
52
|
+
if Caboose::PostCategoryMembership.exists?(:post_category_id => cat.id)
|
53
|
+
Caboose::PostCategoryMembership.where(:post_category_id => cat.id)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
@_renderer = "Caboose::PageBlock#{self.block_type.upcase}Renderer".constantize.new
|
61
|
+
@_renderer.page_block = self
|
62
|
+
@_renderer.page_block = self
|
63
|
+
|
64
|
+
self.renderer.render
|
65
|
+
end
|
66
|
+
|
67
|
+
@_renderer = "Caboose::PageBlock#{self.block_type.upcase}Renderer".constantize.new
|
68
|
+
@_renderer.page_block = self
|
7
69
|
|
8
70
|
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
class Caboose::PageBlockRendererRichtext
|
3
|
+
|
4
|
+
self.table_name = "page_blocks"
|
5
|
+
|
6
|
+
belongs_to :page
|
7
|
+
attr_accessible :id, :page_id, :block_type, :sort_order, :name, :value
|
8
|
+
|
9
|
+
@_renderer
|
10
|
+
def renderer
|
11
|
+
if @_renderer.nil?
|
12
|
+
@_renderer = "Caboose::PageBlock#{self.block_type.upcase}Renderer".constantize.new
|
13
|
+
@_renderer.page_block = self
|
14
|
+
end
|
15
|
+
return @_renderer
|
16
|
+
end
|
17
|
+
|
18
|
+
def render
|
19
|
+
self.renderer.render
|
20
|
+
end
|
21
|
+
|
22
|
+
def content
|
23
|
+
a = self.name.nil? || self.name.length == 0 ? '' : "<a name='#{self.name}'></a>"
|
24
|
+
return "#{a}#{self.value}" if self.block_type == 'richtext'
|
25
|
+
return "#{a}<p>#{self.value}</p>" if self.block_type == 'p'
|
26
|
+
return "#{a}<h1>#{self.value}</h1>" if self.block_type == 'h1'
|
27
|
+
return "#{a}<h2>#{self.value}</h2>" if self.block_type == 'h2'
|
28
|
+
return "#{a}<h3>#{self.value}</h3>" if self.block_type == 'h3'
|
29
|
+
return "#{a}<h4>#{self.value}</h4>" if self.block_type == 'h4'
|
30
|
+
return "#{a}<h5>#{self.value}</h5>" if self.block_type == 'h5'
|
31
|
+
return "#{a}<h6>#{self.value}</h6>" if self.block_type == 'h6'
|
32
|
+
|
33
|
+
if self.block_type == 'posts'
|
34
|
+
obj = Caboose::StdClass(JSON.parse(self.value))
|
35
|
+
defaults = {
|
36
|
+
'limit' => 10,
|
37
|
+
'no_posts_message' => "<p>There are no posts right now.</p>",
|
38
|
+
'invalid_category_message' => "<p>Invalid post category.</p>",
|
39
|
+
'body_character_limit' => 0
|
40
|
+
}
|
41
|
+
defaults.each { |k,v| obj[k] = v if obj[k].nil? }
|
42
|
+
|
43
|
+
return obj.invalid_category_message if !Caboose::PostCategory.exists?(obj.category_id)
|
44
|
+
cat = Caboose::PostCategory.find(obj.category_id)
|
45
|
+
posts = obj.limit == 0 ? cat.posts.reorder('created_at DESC') : cat.posts.reorder('created_at DESC').limit(obj.limit)
|
46
|
+
return obj.no_posts_message posts.nil? || posts.count == 0
|
47
|
+
|
48
|
+
str = ""
|
49
|
+
posts.each do |p|
|
50
|
+
str = "<div class='post'>"
|
51
|
+
str << "<h2>#{raw p.title}</h2>"
|
52
|
+
str << "<div class='created_at'>#{p.created_at.strftime('%F %T')}</div>"
|
53
|
+
str << "<div class='post_content'>"
|
54
|
+
str << obj.body_character_limit > 0 ? Caboose.teaser_text(p.body, obj.body_character_limit) : p.body
|
55
|
+
str << "</div>"
|
56
|
+
str << "</div>"
|
57
|
+
end
|
58
|
+
|
59
|
+
assoc = cat
|
60
|
+
if Caboose
|
61
|
+
|
62
|
+
|
63
|
+
if Caboose::PostCategoryMembership.exists?(:post_category_id => cat.id)
|
64
|
+
Caboose::PostCategoryMembership.where(:post_category_id => cat.id)
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -87,7 +87,7 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
87
87
|
],
|
88
88
|
Caboose::PageBlock => [
|
89
89
|
[ :page_id , :integer ],
|
90
|
-
[ :
|
90
|
+
[ :block_type , :string , :default => 'p' ],
|
91
91
|
[ :sort_order , :integer , :default => 0 ],
|
92
92
|
[ :name , :string ],
|
93
93
|
[ :value , :text ]
|
@@ -127,7 +127,15 @@ class Caboose::Schema < Caboose::Utilities::Schema
|
|
127
127
|
end
|
128
128
|
|
129
129
|
# Loads initial data into the database
|
130
|
-
def self.load_data
|
130
|
+
def self.load_data
|
131
|
+
|
132
|
+
c = ActiveRecord::Base.connection
|
133
|
+
if c.column_exists?(:pages, :content)
|
134
|
+
Caboose::Page.reorder(:id).all.each do |p|
|
135
|
+
Caboose::PageBlock.create( :page_id => p.id, :block_type => 'richtext', :value => p.content )
|
136
|
+
end
|
137
|
+
c.remove_column(:pages, :content)
|
138
|
+
end
|
131
139
|
|
132
140
|
admin_user = nil
|
133
141
|
if !Caboose::User.exists?(:username => 'admin')
|
data/app/models/caboose/user.rb
CHANGED
@@ -3,7 +3,7 @@ class Caboose::User < ActiveRecord::Base
|
|
3
3
|
#has_and_belongs_to_many :roles
|
4
4
|
has_many :role_memberships
|
5
5
|
has_many :roles, :through => :role_memberships
|
6
|
-
attr_accessible :email, :first_name, :last_name, :username, :token, :password
|
6
|
+
attr_accessible :email, :first_name, :last_name, :username, :token, :password, :phone
|
7
7
|
|
8
8
|
before_save do
|
9
9
|
self.email = self.email.downcase if self.email
|
@@ -6,6 +6,11 @@ class Caboose::Utilities::Schema
|
|
6
6
|
return nil
|
7
7
|
end
|
8
8
|
|
9
|
+
# Columns (in order) that were renamed in the development of the gem.
|
10
|
+
def self.renamed_columns
|
11
|
+
return nil
|
12
|
+
end
|
13
|
+
|
9
14
|
# Columns (in order) that were removed in the development of the gem.
|
10
15
|
def self.removed_columns
|
11
16
|
return nil
|
@@ -34,7 +39,8 @@ class Caboose::Utilities::Schema
|
|
34
39
|
def self.create_schema
|
35
40
|
return if self.schema.nil?
|
36
41
|
|
37
|
-
rename_tables
|
42
|
+
rename_tables
|
43
|
+
rename_columns
|
38
44
|
|
39
45
|
c = ActiveRecord::Base.connection
|
40
46
|
self.schema.each do |model, columns|
|
@@ -91,6 +97,19 @@ class Caboose::Utilities::Schema
|
|
91
97
|
end
|
92
98
|
end
|
93
99
|
|
100
|
+
# Renames a set of columns
|
101
|
+
def self.rename_columns
|
102
|
+
return if self.renamed_columns.nil?
|
103
|
+
c = ActiveRecord::Base.connection
|
104
|
+
self.renamed_columns.each do |model, cols|
|
105
|
+
next if !c.table_exists? model.table_name
|
106
|
+
cols.each do |old_name, new_name|
|
107
|
+
next if !c.column_exists? model.table_name, old_name
|
108
|
+
c.rename_column model.table_name, old_name, new_name
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
94
113
|
# Removes a set of tables
|
95
114
|
def self.remove_columns
|
96
115
|
return if self.removed_columns.nil?
|
@@ -1,9 +1,27 @@
|
|
1
1
|
|
2
2
|
<%= render :partial => 'caboose/pages/admin_header' %>
|
3
3
|
|
4
|
-
<p><
|
4
|
+
<p><input type='button' value='Add Block' onclick="add_block_at_beginning();" /></p>
|
5
|
+
|
6
|
+
<% @page.blocks.each do |b| %>
|
7
|
+
<div class='page_block'>
|
8
|
+
<div id='pageblock_<%= b.id %>_name'></div>
|
9
|
+
<div id='pageblock_<%= b.id %>_value'></div>
|
10
|
+
<div id='page_block_<%= b.id %>_message'></div>
|
11
|
+
<p><input type='button' value='Delete Block' class='delete' onclick="delete_block(<%= b.id %>);" /></p>
|
12
|
+
</div>
|
13
|
+
<p><input type='button' value='Add Block' onclick="add_block_after(<%= b.id %>);" /></p>
|
14
|
+
<% end %>
|
5
15
|
|
6
16
|
<%= render :partial => 'caboose/pages/admin_footer' %>
|
17
|
+
<% content_for :caboose_css do %>
|
18
|
+
<style type='text/css'>
|
19
|
+
|
20
|
+
div.page_block { padding: 20px; border: #ccc 1px solid; background: #efefef; }
|
21
|
+
div.page_block p { padding-bottom: 0; margin-bottom: 0; }
|
22
|
+
|
23
|
+
</style>
|
24
|
+
<% end %>
|
7
25
|
<% content_for :caboose_js do %>
|
8
26
|
<script type='text/javascript'>
|
9
27
|
|
@@ -12,19 +30,22 @@ $(window).load(function() {
|
|
12
30
|
modal = new CabooseModal(800);
|
13
31
|
});
|
14
32
|
|
15
|
-
$(document).ready(function() {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
33
|
+
$(document).ready(function() {
|
34
|
+
<% @page.blocks.each do |b| %>
|
35
|
+
m = new ModelBinder({
|
36
|
+
name: 'PageBlock',
|
37
|
+
id: <%= b.id %>,
|
38
|
+
update_url: '/admin/page-blocks/<%= b.id %>',
|
39
|
+
authenticity_token: '<%= form_authenticity_token %>',
|
40
|
+
attributes: [
|
41
|
+
{ name: 'name' , nice_name: 'Name' , type: 'text' , value: <%= raw Caboose.json(b.name) %>, width: 784 },
|
42
|
+
{ name: 'value', nice_name: 'Content', type: 'richtext', value: <%= raw Caboose.json(b.value) %>, width: 800, height: 300 }
|
43
|
+
]
|
44
|
+
});
|
45
|
+
<% end %>
|
25
46
|
});
|
26
47
|
|
27
48
|
</script>
|
28
49
|
<%= tinymce_assets %>
|
29
|
-
<%= tinymce :caboose, width: '800px', height:'
|
50
|
+
<%= tinymce :caboose, width: '800px', height:'300px' %>
|
30
51
|
<% end %>
|
data/lib/caboose/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
namespace :caboose do
|
3
|
+
desc "Corrects any sequences in tables"
|
4
|
+
task :correct_sequences => :environment do
|
5
|
+
|
6
|
+
c = ActiveRecord::Base.connection
|
7
|
+
c.tables.each do |tbl|
|
8
|
+
next if !c.column_exists? tbl, :id
|
9
|
+
|
10
|
+
rows = c.execute("select max(id) from #{tbl}")
|
11
|
+
max = rows[0]['max']
|
12
|
+
max = max.to_i if !max.nil?
|
13
|
+
|
14
|
+
rows = c.execute("select nextval('#{tbl}_id_seq')")
|
15
|
+
nextval = rows[0]['nextval']
|
16
|
+
nextval = nextval.to_i if !nextval.nil?
|
17
|
+
|
18
|
+
next if max.nil? || nextval.nil?
|
19
|
+
next if nextval >= max
|
20
|
+
|
21
|
+
# If nextval is lower than the max id, then fix it.
|
22
|
+
puts "Correcting sequence for #{tbl}..."
|
23
|
+
c.execute("select setval('#{tbl}_id_seq', (select max(id) from #{tbl}))")
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
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
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- William Barry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-12-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -187,6 +187,8 @@ files:
|
|
187
187
|
- app/models/caboose/page.rb
|
188
188
|
- app/models/caboose/page_bar_generator.rb
|
189
189
|
- app/models/caboose/page_block.rb
|
190
|
+
- app/models/caboose/page_block_renderer.rb
|
191
|
+
- app/models/caboose/page_block_renderer_richtext.rb
|
190
192
|
- app/models/caboose/page_permission.rb
|
191
193
|
- app/models/caboose/pager.rb
|
192
194
|
- app/models/caboose/permission.rb
|
@@ -270,6 +272,7 @@ files:
|
|
270
272
|
- lib/sample_files/login.css
|
271
273
|
- lib/sample_files/tinymce.yml
|
272
274
|
- lib/tasks/caboose.rake
|
275
|
+
- lib/tasks/sequences.rake
|
273
276
|
- MIT-LICENSE
|
274
277
|
- Rakefile
|
275
278
|
- README.md
|