slightcms 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/app/models/asset.rb +10 -0
- data/lib/app/models/layout.rb +3 -2
- data/lib/app/models/page.rb +85 -0
- data/lib/app/models/part.rb +21 -0
- data/lib/slightcms.rb +4 -1
- data/slightcms.gemspec +4 -1
- metadata +4 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/app/models/layout.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Slightcms
|
2
2
|
class Layout < ActiveRecord::Base
|
3
3
|
|
4
|
-
|
4
|
+
# Change default table name
|
5
|
+
set_table_name 'slightcms_layouts'
|
5
6
|
|
6
7
|
# Default order
|
7
8
|
default_scope :order => 'name'
|
8
9
|
|
9
10
|
# Associations
|
10
|
-
has_many :pages, :class_name => "
|
11
|
+
has_many :pages, :class_name => "Slightcms::Page"
|
11
12
|
|
12
13
|
# Validations
|
13
14
|
validates_presence_of :name
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Slightcms
|
2
|
+
class Page < ActiveRecord::Base
|
3
|
+
|
4
|
+
# Change default table name
|
5
|
+
set_table_name "slightcms_pages"
|
6
|
+
|
7
|
+
acts_as_tree :order => "position"
|
8
|
+
acts_as_list :scope => :parent_id
|
9
|
+
|
10
|
+
# Default order
|
11
|
+
default_scope :order => "position"
|
12
|
+
|
13
|
+
# Associations
|
14
|
+
belongs_to :layout, :class_name => "Slightcms::Layout"
|
15
|
+
has_many :parts, :class_name => "Slightcms::Part", :dependent => :destroy
|
16
|
+
|
17
|
+
# Validations
|
18
|
+
validates_presence_of :title
|
19
|
+
validates_presence_of :slug
|
20
|
+
validates_uniqueness_of :slug, :scope => :parent_id
|
21
|
+
|
22
|
+
# Callbacks
|
23
|
+
before_create :create_path
|
24
|
+
before_validation do |record|
|
25
|
+
if record.slug.blank? && !record.title.blank?
|
26
|
+
create_slug(record)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
# Render the pages content
|
33
|
+
def render_content
|
34
|
+
content = self.layout.content
|
35
|
+
self.parts each do |part|
|
36
|
+
content.gsub!(/(#{Regexp.escape("<!-- slightcms:part:#{part.name} -->")})/mi, part.render_content)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Find a page by full path
|
41
|
+
def find_by_path(path)
|
42
|
+
find :first, :conditions => {:path => path, :published => true}, :include => [:layout, :parts]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Create a unique slug for SEO purposes
|
48
|
+
def create_slug(record)
|
49
|
+
proposed_slug = record.title.downcase.gsub!(/[^a-z1-9]+/, '-')
|
50
|
+
|
51
|
+
existing = true
|
52
|
+
suffix = ""
|
53
|
+
i = 2
|
54
|
+
|
55
|
+
# Check if slug already exists
|
56
|
+
while existing != nil
|
57
|
+
existing = self.class.find :first, :conditions => {:slug => proposed_slug + suffix}
|
58
|
+
if existing
|
59
|
+
suffix = "-#{i}"
|
60
|
+
i += 1
|
61
|
+
else
|
62
|
+
self.slug = proposed_slug + suffix
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Create page's path
|
68
|
+
def create_path
|
69
|
+
self.path = parent.path + "/#{self.slug}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Generate the page's path and save the object
|
73
|
+
def create_path!
|
74
|
+
create_path
|
75
|
+
save
|
76
|
+
end
|
77
|
+
|
78
|
+
# Update the children's path
|
79
|
+
def update_children_path
|
80
|
+
children.each do |child|
|
81
|
+
create_path!
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Slightcms
|
2
|
+
class Part < ActiveRecord::Base
|
3
|
+
|
4
|
+
# Change default table name
|
5
|
+
set_table_name "slightcms_parts"
|
6
|
+
# Associations
|
7
|
+
belongs_to :page, :class_name => "Slightcms::Page"
|
8
|
+
|
9
|
+
# Validations
|
10
|
+
validates_presence_of :name
|
11
|
+
validates_uniqueness_of :name, :scope => :page_id
|
12
|
+
validates_presence_of :content
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# Render the part's content
|
17
|
+
def render_content
|
18
|
+
RedCloth.new(self.content).to_html
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/slightcms.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
module Slightcms
|
3
3
|
|
4
4
|
# :stopdoc:
|
5
|
-
VERSION = '0.0.
|
5
|
+
VERSION = '0.0.7'
|
6
6
|
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
|
7
7
|
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
|
8
8
|
# :startdoc:
|
@@ -46,3 +46,6 @@ end # module Slightcms
|
|
46
46
|
|
47
47
|
# Slightcms.require_all_libs_relative_to(__FILE__)
|
48
48
|
require "app/models/layout"
|
49
|
+
require "app/models/page"
|
50
|
+
require "app/models/part"
|
51
|
+
require "app/models/asset"
|
data/slightcms.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{slightcms}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.7"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Matthias Nitsch"]
|
@@ -28,7 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
"generators/slightcms_setup/slightcms_setup_generator.rb",
|
29
29
|
"generators/slightcms_setup/templates/INSTALL",
|
30
30
|
"generators/slightcms_setup/templates/slightcms_setup_migration.rb",
|
31
|
+
"lib/app/models/asset.rb",
|
31
32
|
"lib/app/models/layout.rb",
|
33
|
+
"lib/app/models/page.rb",
|
34
|
+
"lib/app/models/part.rb",
|
32
35
|
"lib/slightcms.rb",
|
33
36
|
"slightcms.gemspec",
|
34
37
|
"spec/slightcms_spec.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slightcms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Nitsch
|
@@ -71,7 +71,10 @@ files:
|
|
71
71
|
- generators/slightcms_setup/slightcms_setup_generator.rb
|
72
72
|
- generators/slightcms_setup/templates/INSTALL
|
73
73
|
- generators/slightcms_setup/templates/slightcms_setup_migration.rb
|
74
|
+
- lib/app/models/asset.rb
|
74
75
|
- lib/app/models/layout.rb
|
76
|
+
- lib/app/models/page.rb
|
77
|
+
- lib/app/models/part.rb
|
75
78
|
- lib/slightcms.rb
|
76
79
|
- slightcms.gemspec
|
77
80
|
- spec/slightcms_spec.rb
|