slightcms 0.0.2 → 0.0.4

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/.bnsignore ADDED
@@ -0,0 +1,18 @@
1
+ # The list of files that should be ignored by Mr Bones.
2
+ # Lines that start with '#' are comments.
3
+ #
4
+ # A .gitignore file can be used instead by setting it as the ignore
5
+ # file in your Rakefile:
6
+ #
7
+ # Bones {
8
+ # ignore_file '.gitignore'
9
+ # }
10
+ #
11
+ # For a project with a C extension, the following would be a good set of
12
+ # exclude patterns (uncomment them if you want to use them):
13
+ # *.[oa]
14
+ # *~
15
+ announcement.txt
16
+ coverage
17
+ doc
18
+ pkg
data/History.rdoc ADDED
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2010-01-06
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
data/README.rdoc CHANGED
@@ -0,0 +1,42 @@
1
+ = slightCMS
2
+ by Matthias Nitsch
3
+ http://github.com/mnitsch/slightcms
4
+
5
+ == DESCRIPTION:
6
+
7
+ slightCMS is a small CMS, built for integration into existing rails applications
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIXME (list of features or problems)
12
+
13
+ == REQUIREMENTS:
14
+
15
+ * FIXME (list of requirements)
16
+
17
+ == INSTALL:
18
+
19
+ * gem install slightcms
20
+
21
+ == LICENSE:
22
+
23
+ (The MIT License)
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining
26
+ a copy of this software and associated documentation files (the
27
+ 'Software'), to deal in the Software without restriction, including
28
+ without limitation the rights to use, copy, modify, merge, publish,
29
+ distribute, sublicense, and/or sell copies of the Software, and to
30
+ permit persons to whom the Software is furnished to do so, subject to
31
+ the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be
34
+ included in all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
37
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
39
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
40
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
41
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -15,4 +15,8 @@ begin
15
15
  Jeweler::GemcutterTasks.new
16
16
  rescue LoadError
17
17
  puts "Jeweler not available. Install it with: gem install jeweler"
18
- end
18
+ end
19
+
20
+
21
+
22
+ # EOF
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.4
data/bin/slightcms ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(
4
+ File.join(File.dirname(__FILE__), %w[.. lib slightcms]))
5
+
6
+ # Put your code here
7
+
@@ -0,0 +1,26 @@
1
+ class Rails::Generator::Commands::Create
2
+ def draw_routes
3
+ file_start = 'ActionController::Routing::Routes.draw do |map|'
4
+ unless options[:pretend]
5
+ gsub_file 'config/routes.rb', /(#{Regexp.escape(file_start)})/mi do |match|
6
+ "#{match}\n map.slightcms_pages '/:path', :controller => :slightcms_pages, :action => :show\n"
7
+ end
8
+ end
9
+ end
10
+ end
11
+
12
+ class SlightcmsSetupGenerator < Rails::Generator::Base
13
+ def manifest
14
+ record do |m|
15
+ # Setup directories
16
+ m.directory('db/migrate')
17
+ m.directory('public/slightcms/assets')
18
+
19
+ # Setup migration file
20
+ m.file('slightcms_setup_migration.rb', '#{Time.now.to_s}_slightcms_setup.rb'
21
+
22
+ # Setup routes in routes.rb
23
+ m.draw_routes
24
+ end
25
+ end
26
+ end
@@ -0,0 +1 @@
1
+ TEST
@@ -0,0 +1,61 @@
1
+ class SlightcmsSetup < ActiveRecord::Migration
2
+ def self.up
3
+ # Create layouts-table
4
+ create_table :slightcms_layouts do |t|
5
+ t.string :name, :null => false
6
+ t.text :content
7
+ t.timestamps
8
+ end
9
+
10
+ # Create pages-table
11
+ create_table :slightcms_pages do |t|
12
+ t.integer :parent_id
13
+ t.integer :layout_id, :null => false
14
+ t.integer :status_id
15
+ t.integer :position
16
+ t.string :path, :null => false
17
+ t.string :title, :null => false
18
+ t.string :slug, :null => false
19
+ t.string :keywords
20
+ t.string :description
21
+ t.boolean :published
22
+ t.timestamps
23
+ end
24
+ add_index :slightcms_pages, :parent_id
25
+ add_index :slightcms_pages, :layout_id
26
+ add_index :slightcms_pages, :path
27
+ add_index :slightcms_pages, :published
28
+
29
+ # Create page-parts-table
30
+ create_table :slightcms_page_parts do |t|
31
+ t.integer :page_id
32
+ t.string :name, :null => false
33
+ t.text :content
34
+ t.timestamps
35
+ end
36
+ add_index :slightcms_page_parts, :page_id
37
+
38
+ # Create assets-table
39
+ create_table :slightcms_assets do |t|
40
+ t.string :name
41
+ t.string :content_type
42
+ t.string :filename
43
+ t.integer :size
44
+ t.timestamps
45
+ end
46
+
47
+ # Create statuses-table
48
+ create_table :slightcms_statuses do |t|
49
+ t.string :name, :null => false
50
+ t.timestamps
51
+ end
52
+
53
+ end
54
+
55
+ def self.down
56
+ drop_table :slightcms_layouts
57
+ drop_table :slightcms_pages
58
+ drop_table :slightcms_page_parts
59
+ drop_table :slightcms_assets
60
+ end
61
+ end
@@ -0,0 +1,14 @@
1
+ class SlightcmsLayout < ActiveRecord::Base
2
+
3
+ # Default order
4
+ default_scope :order => 'name'
5
+
6
+ # Associations
7
+ has_many :pages, :class_name => "SlightcmsPage"
8
+
9
+ # Validations
10
+ validates_presence_of :name
11
+ validates_uniqueness_of :name
12
+ validates_presence_of :content
13
+
14
+ end
@@ -0,0 +1,81 @@
1
+ class SlightcmsPage < ActiveRecord::Base
2
+
3
+ acts_as_tree :order => "position"
4
+ acts_as_list :scope => :parent_id
5
+
6
+ # Default order
7
+ default_scope :order => "position"
8
+
9
+ # Associations
10
+ belongs_to :layout, :class_name => :slightcms_layout
11
+ has_many :parts, :class_name => :slightcms_page_part, :dependent => :destroy
12
+
13
+ # Validations
14
+ validates_presence_of :title
15
+ validates_presence_of :slug
16
+ validates_uniqueness_of :slug, :scope => :parent_id
17
+
18
+ # Callbacks
19
+ before_create :create_path
20
+ before_validation do |record|
21
+ if record.slug.blank? && !record.title.blank?
22
+ create_slug(record)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ # Render the pages content
29
+ def render_content
30
+ content = self.layout.content
31
+ self.parts each do |part|
32
+ content.gsub!(/(#{Regexp.escape("<!-- slightcms:part:#{part.name} -->")})/mi, part.render_content)
33
+ end
34
+ end
35
+
36
+ # Find a page by full path
37
+ def find_by_path(path)
38
+ find :first, :conditions => {:path => path, :published => true}, :include => [:layout, :parts]
39
+ end
40
+
41
+ private
42
+
43
+ # Create a unique slug for SEO purposes
44
+ def create_slug(record)
45
+ proposed_slug = record.title.downcase.gsub!(/[^a-z1-9]+/, '-')
46
+
47
+ existing = true
48
+ suffix = ""
49
+ i = 2
50
+
51
+ # Check if slug already exists
52
+ while existing != nil
53
+ existing = self.class.find :first, :conditions => {:slug => proposed_slug + suffix}
54
+ if existing
55
+ suffix = "-#{i}"
56
+ i += 1
57
+ else
58
+ self.slug = proposed_slug + suffix
59
+ end
60
+ end
61
+ end
62
+
63
+ # Create page's path
64
+ def create_path
65
+ self.path = parent.path + "/#{self.slug}"
66
+ end
67
+
68
+ # Generate the page's path and save the object
69
+ def create_path!
70
+ create_path
71
+ save
72
+ end
73
+
74
+ # Update the children's path
75
+ def update_children_path
76
+ children.each do |child|
77
+ create_path!
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,18 @@
1
+ class SlightcmsPagePart < ActiveRecord::Base
2
+
3
+ # Associations
4
+ belongs_to :page, :class_name => "SlightcmsPage"
5
+
6
+ # Validations
7
+ validates_presence_of :name
8
+ validates_uniqueness_of :name, :scope => :page_id
9
+ validates_presence_of :content
10
+
11
+ protected
12
+
13
+ # Render the part's content
14
+ def render_content
15
+ RedCloth.new(self.content).to_html
16
+ end
17
+
18
+ end
data/lib/slightcms.rb ADDED
@@ -0,0 +1,48 @@
1
+
2
+ module Slightcms
3
+
4
+ # :stopdoc:
5
+ VERSION = '0.0.4'
6
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
7
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
8
+ # :startdoc:
9
+
10
+ # Returns the version string for the library.
11
+ #
12
+ def self.version
13
+ VERSION
14
+ end
15
+
16
+ # Returns the library path for the module. If any arguments are given,
17
+ # they will be joined to the end of the libray path using
18
+ # <tt>File.join</tt>.
19
+ #
20
+ def self.libpath( *args )
21
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
22
+ end
23
+
24
+ # Returns the lpath for the module. If any arguments are given,
25
+ # they will be joined to the end of the path using
26
+ # <tt>File.join</tt>.
27
+ #
28
+ def self.path( *args )
29
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
30
+ end
31
+
32
+ # Utility method used to require all files ending in .rb that lie in the
33
+ # directory below this file that has the same name as the filename passed
34
+ # in. Optionally, a specific _directory_ name can be passed in such that
35
+ # the _filename_ does not have to be equivalent to the directory.
36
+ #
37
+ def self.require_all_libs_relative_to( fname, dir = nil )
38
+ dir ||= ::File.basename(fname, '.*')
39
+ search_me = ::File.expand_path(
40
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
41
+
42
+ Dir.glob(search_me).sort.each {|rb| require rb}
43
+ end
44
+
45
+ end # module Slightcms
46
+
47
+ Slightcms.require_all_libs_relative_to(__FILE__)
48
+ require "app/models/slightcms_layout"
data/slightcms.gemspec CHANGED
@@ -5,33 +5,48 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{slightcms}
8
- s.version = "0.0.2"
8
+ s.version = "0.0.4"
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"]
12
- s.date = %q{2010-01-06}
12
+ s.date = %q{2010-01-10}
13
+ s.default_executable = %q{slightcms}
13
14
  s.description = %q{}
14
15
  s.email = %q{matthias.nitsch@me.com}
16
+ s.executables = ["slightcms"]
15
17
  s.extra_rdoc_files = [
16
18
  "README.rdoc"
17
19
  ]
18
20
  s.files = [
19
- ".gitignore",
21
+ ".bnsignore",
22
+ ".gitignore",
23
+ "History.rdoc",
20
24
  "README.rdoc",
21
25
  "Rakefile",
22
26
  "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"
27
+ "bin/slightcms",
28
+ "generators/slightcms_setup/slightcms_setup_generator.rb",
29
+ "generators/slightcms_setup/templates/INSTALL",
30
+ "generators/slightcms_setup/templates/slightcms_setup_migration.rb",
31
+ "lib/app/models/slightcms_layout.rb",
32
+ "lib/app/models/slightcms_page.rb",
33
+ "lib/app/models/slightcms_page_part.rb",
34
+ "lib/slightcms.rb",
35
+ "slightcms.gemspec",
36
+ "spec/slightcms_spec.rb",
37
+ "spec/spec_helper.rb",
38
+ "test/test_slightcms.rb"
29
39
  ]
30
40
  s.homepage = %q{http://github.com/mnitsch/slightcms}
31
41
  s.rdoc_options = ["--charset=UTF-8"]
32
42
  s.require_paths = ["lib"]
33
43
  s.rubygems_version = %q{1.3.5}
34
44
  s.summary = %q{slightCMS is a small CMS, built for integration into existing rails applications}
45
+ s.test_files = [
46
+ "spec/slightcms_spec.rb",
47
+ "spec/spec_helper.rb",
48
+ "test/test_slightcms.rb"
49
+ ]
35
50
 
36
51
  if s.respond_to? :specification_version then
37
52
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,6 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe Slightcms do
5
+ end
6
+
@@ -0,0 +1,15 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. lib slightcms]))
4
+
5
+ Spec::Runner.configure do |config|
6
+ # == Mock Framework
7
+ #
8
+ # RSpec uses it's own mocking framework by default. If you prefer to
9
+ # use mocha, flexmock or RR, uncomment the appropriate line:
10
+ #
11
+ # config.mock_with :mocha
12
+ # config.mock_with :flexmock
13
+ # config.mock_with :rr
14
+ end
15
+
File without changes
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Nitsch
@@ -9,8 +9,8 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-06 00:00:00 +01:00
13
- default_executable:
12
+ date: 2010-01-10 00:00:00 +01:00
13
+ default_executable: slightcms
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -54,23 +54,31 @@ dependencies:
54
54
  version:
55
55
  description: ""
56
56
  email: matthias.nitsch@me.com
57
- executables: []
58
-
57
+ executables:
58
+ - slightcms
59
59
  extensions: []
60
60
 
61
61
  extra_rdoc_files:
62
62
  - README.rdoc
63
63
  files:
64
+ - .bnsignore
64
65
  - .gitignore
66
+ - History.rdoc
65
67
  - README.rdoc
66
68
  - Rakefile
67
69
  - VERSION
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
70
+ - bin/slightcms
71
+ - generators/slightcms_setup/slightcms_setup_generator.rb
72
+ - generators/slightcms_setup/templates/INSTALL
73
+ - generators/slightcms_setup/templates/slightcms_setup_migration.rb
74
+ - lib/app/models/slightcms_layout.rb
75
+ - lib/app/models/slightcms_page.rb
76
+ - lib/app/models/slightcms_page_part.rb
77
+ - lib/slightcms.rb
73
78
  - slightcms.gemspec
79
+ - spec/slightcms_spec.rb
80
+ - spec/spec_helper.rb
81
+ - test/test_slightcms.rb
74
82
  has_rdoc: true
75
83
  homepage: http://github.com/mnitsch/slightcms
76
84
  licenses: []
@@ -99,5 +107,7 @@ rubygems_version: 1.3.5
99
107
  signing_key:
100
108
  specification_version: 3
101
109
  summary: slightCMS is a small CMS, built for integration into existing rails applications
102
- test_files: []
103
-
110
+ test_files:
111
+ - spec/slightcms_spec.rb
112
+ - spec/spec_helper.rb
113
+ - test/test_slightcms.rb
data/init.rb DELETED
@@ -1 +0,0 @@
1
- require 'slightcms/slightcms_page'
@@ -1,70 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,20 +0,0 @@
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
@@ -1,20 +0,0 @@
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