slightcms 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg
2
+ doc
3
+ Manifest
data/Rakefile CHANGED
@@ -7,6 +7,10 @@ begin
7
7
  gemspec.email = "matthias.nitsch@me.com"
8
8
  gemspec.homepage = "http://github.com/mnitsch/slightcms"
9
9
  gemspec.authors = ["Matthias Nitsch"]
10
+ gemspec.add_dependency('rails', '>= 2.3.5')
11
+ gemspec.add_dependency('acts_as_tree', '>= 0.1.0')
12
+ gemspec.add_dependency('acts_as_list', '>= 0.1.2')
13
+ gemspec.add_dependency('acts_as_versioned', '>= 0.2.3')
10
14
  end
11
15
  Jeweler::GemcutterTasks.new
12
16
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ reguire 'app/slightcms_page'
@@ -0,0 +1,70 @@
1
+ class SlightcmsPage < ActiveRecord::Base
2
+
3
+ #has_many :elements, :class_name => "SlightcmsPageElement", :foreign_key => "page_id"
4
+
5
+ #cts_as_tree :order => "position, title"
6
+ #acts_as_list :scope => :parent_id
7
+
8
+ validates_presence_of :title
9
+ validates_uniqueness_of :slug, :scope => :parent_id
10
+
11
+ before_validation do |record|
12
+ if record.slug.blank? && !record.title.blank?
13
+ generate_slug(record)
14
+ end
15
+ end
16
+
17
+ before_create :generate_full_path
18
+
19
+ # Render page's content to valid html
20
+ def to_html
21
+ elements = children.map {|child| child.to_html}
22
+ elements.join('\n')
23
+ end
24
+
25
+ protected
26
+
27
+ # Find a page by full path
28
+ def find_by_path(path)
29
+ find :first, :conditions => {:path => path, :published => true}
30
+ end
31
+
32
+ # Generate a unique slug for seo purposes
33
+ def generate_slug(record)
34
+ proposed_slug = record.title.downcase.gsub!(/[^a-z1-9]+/, '-')
35
+
36
+ existing = true
37
+ suffix = ""
38
+ i = 1
39
+
40
+ # Check if slug already exists
41
+ while existing != nil
42
+ existing = self.class.find :first, :conditions => {:slug => proposed_slug + suffix}
43
+ if existing
44
+ suffix = "-#{i}"
45
+ i += 1
46
+ else
47
+ self.slug = proposed_slug + suffix
48
+ end
49
+ end
50
+ end
51
+
52
+ # Generate the page's full path
53
+ def generate_path
54
+ self.path = parent_node.path + "/#{self.slug}"
55
+ end
56
+
57
+ # Generate the page's full path and save the object
58
+ def generate_path!
59
+ generate_path
60
+ save
61
+ end
62
+
63
+ # Update the children's path
64
+ def update_children_path
65
+ children.each do |child|
66
+ generate_path!
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,20 @@
1
+ require 'redcloth'
2
+ require 'acts-as-list'
3
+
4
+ class SlightcmsPageElement < ActiveRecord::Base
5
+
6
+ belongs_to :page, :class_name => "SlightcmsPage", :foreign_key => "page_id"
7
+
8
+ validates_presence_of :title
9
+ validates_presence_of :content
10
+
11
+ acts_as_list :scope => :page_id
12
+
13
+ after_save :expire_parent_page_cache
14
+
15
+ # Render the element's content into valid html
16
+ def to_html
17
+ RedCloth.new(self.content).to_html
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ class SlightcmsPageElementSweeper < ActionController::Caching::Sweeper
2
+
3
+ observe SlightcmsPageElement
4
+
5
+ def after_save(element)
6
+ expire_cache(element)
7
+ end
8
+
9
+ def after_destroy(element)
10
+ expire_cache(element)
11
+ end
12
+
13
+ private
14
+
15
+ # Expire page cache for given record
16
+ def expire_cache(record)
17
+ expire_page(:controller => :slightcms_pages, :action => :show, :path => record.page.full_path)
18
+ end
19
+
20
+ end
@@ -0,0 +1,20 @@
1
+ class SlightcmsPageSweeper < ActionController::Caching::Sweeper
2
+
3
+ observe SlightcmsPage
4
+
5
+ def before_save(page)
6
+ expire_cache(page)
7
+ end
8
+
9
+ def after_destroy(page)
10
+ expire_cache(page)
11
+ end
12
+
13
+ private
14
+
15
+ # Expire page cache for given record
16
+ def expire_cache(record)
17
+ expire_page(:controller => :slightcms_pages, :action => :show, :path => record.full_path)
18
+ end
19
+
20
+ end
data/slightcms.gemspec ADDED
@@ -0,0 +1,58 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{slightcms}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matthias Nitsch"]
12
+ s.date = %q{2010-01-06}
13
+ s.description = %q{}
14
+ s.email = %q{matthias.nitsch@me.com}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "init.rb",
24
+ "lib/slightcms/slightcms_page.rb",
25
+ "lib/slightcms/slightcms_page_element.rb",
26
+ "lib/slightcms/slightcms_page_element_sweeper.rb",
27
+ "lib/slightcms/slightcms_page_sweeper.rb",
28
+ "slightcms.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/mnitsch/slightcms}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{slightCMS is a small CMS, built for integration into existing rails applications}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<rails>, [">= 2.3.5"])
42
+ s.add_runtime_dependency(%q<acts_as_tree>, [">= 0.1.0"])
43
+ s.add_runtime_dependency(%q<acts_as_list>, [">= 0.1.2"])
44
+ s.add_runtime_dependency(%q<acts_as_versioned>, [">= 0.2.3"])
45
+ else
46
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
47
+ s.add_dependency(%q<acts_as_tree>, [">= 0.1.0"])
48
+ s.add_dependency(%q<acts_as_list>, [">= 0.1.2"])
49
+ s.add_dependency(%q<acts_as_versioned>, [">= 0.2.3"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rails>, [">= 2.3.5"])
53
+ s.add_dependency(%q<acts_as_tree>, [">= 0.1.0"])
54
+ s.add_dependency(%q<acts_as_list>, [">= 0.1.2"])
55
+ s.add_dependency(%q<acts_as_versioned>, [">= 0.2.3"])
56
+ end
57
+ end
58
+
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.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Nitsch
@@ -9,10 +9,49 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-03 00:00:00 +01:00
12
+ date: 2010-01-06 00:00:00 +01:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.5
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: acts_as_tree
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: acts_as_list
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.2
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: acts_as_versioned
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 0.2.3
54
+ version:
16
55
  description: ""
17
56
  email: matthias.nitsch@me.com
18
57
  executables: []
@@ -22,10 +61,16 @@ extensions: []
22
61
  extra_rdoc_files:
23
62
  - README.rdoc
24
63
  files:
64
+ - .gitignore
25
65
  - README.rdoc
26
66
  - Rakefile
27
67
  - VERSION
28
- - lib/slightcms.rb
68
+ - init.rb
69
+ - lib/slightcms/slightcms_page.rb
70
+ - lib/slightcms/slightcms_page_element.rb
71
+ - lib/slightcms/slightcms_page_element_sweeper.rb
72
+ - lib/slightcms/slightcms_page_sweeper.rb
73
+ - slightcms.gemspec
29
74
  has_rdoc: true
30
75
  homepage: http://github.com/mnitsch/slightcms
31
76
  licenses: []
data/lib/slightcms.rb DELETED
File without changes