fullstack-cms 0.1.9 → 0.1.11

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/TODO.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Fullstack CMS roadmap
2
2
 
3
- ## Page parts with schema
4
-
5
- # ordinamento degli input in base all'ordine dei field
6
-
7
-
3
+ - add scope (controller?) to pages
4
+ - add resource class to pages
5
+ - add fetch_resource to pages
6
+ -> Sitemap template with url for
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.11
data/app/models/page.rb CHANGED
@@ -6,11 +6,14 @@ class Page < ActiveRecord::Base
6
6
 
7
7
  field :name
8
8
  field :uid
9
+ field :scope
9
10
  index :uid, :unique => true
10
11
 
11
12
  field :path
12
13
  field :resource_type
13
14
 
15
+ timestamps
16
+
14
17
  def home?
15
18
  path == "/"
16
19
  end
@@ -23,6 +26,39 @@ class Page < ActiveRecord::Base
23
26
  name
24
27
  end
25
28
 
29
+ def resource_class
30
+ if self.resourceful?
31
+ @resource_class ||= resource_type.to_s.camelize.constantize
32
+ end
33
+ end
34
+
35
+ # eg.
36
+ # # params => { :q => "abc", :a => 5, :slug => "first_post"}
37
+ # # page.path => "/blog/:slug"
38
+ # post = page.fetch(params)
39
+ # == Post.where(:slug => "first_post").first
40
+
41
+ def fetch_resource(params = {})
42
+ if self.resourceful?
43
+ meaningful_params = params.stringify_keys.select {|k, v|
44
+ path_params.include?(k)
45
+ }
46
+ resource_class.where(meaningful_params).first
47
+ end
48
+ end
49
+
50
+ def path_params
51
+ self.path.scan(/:([A-z_][A-z0-9_]*)/).flatten
52
+ end
53
+
54
+ def resource_params(object)
55
+ params = {}
56
+ path_params.each { |param|
57
+ params[param.to_sym] = object.send(param)
58
+ }
59
+ params
60
+ end
61
+
26
62
  has_many :page_parts
27
63
  accepts_nested_attributes_for :page_parts, :allow_destroy => true
28
64
 
@@ -1,5 +1,45 @@
1
1
  module Pageable
2
2
  extend ActiveSupport::Concern
3
+
4
+ def page_to_sitemap_entries(controller, page)
5
+
6
+ path = nil
7
+ options = {}
8
+ entries = []
9
+
10
+ if page.resourceful?
11
+ page.resource_class.find_each do |object|
12
+ path = Rails.application.routes.url_helpers.url_for({ :only_path => true, :controller => controller, :action => page.name }.merge(page.resource_params(object)))
13
+ options[:updated_at] = object.updated_at if object.respond_to?(:updated_at)
14
+ entries << {:path => path, :options => options}
15
+ end
16
+ else
17
+ path = Rails.application.routes.url_helpers.url_for( :only_path => true, :controller => controller, :action => page.name)
18
+ entries << {:path => path, :options => {}}
19
+ end
20
+
21
+ entries
22
+
23
+ end
24
+ module_function :page_to_sitemap_entries
25
+
26
+ def controller_sitemap_entries(controller)
27
+ entries = []
28
+ Pageable.controller_pages(controller).map do |name, page|
29
+ entries += page_to_sitemap_entries(controller, page)
30
+ end
31
+ entries
32
+ end
33
+ module_function :controller_sitemap_entries
34
+
35
+ #
36
+ # Pageable.controller_pages("site/site")
37
+ #
38
+ def controller_pages(controller)
39
+ controller_class = "#{controller}_controller".camelize.constantize
40
+ controller_class.pages if controller_class.respond_to?(:pages)
41
+ end
42
+ module_function :controller_pages
3
43
 
4
44
  included do
5
45
  before_filter :load_current_page
@@ -8,6 +48,8 @@ module Pageable
8
48
  module ClassMethods
9
49
  def page(name, path, options = {}, &block)
10
50
 
51
+ page_definition_options = options.clone
52
+
11
53
  this_controller_name = "#{self.name.underscore}".gsub("_controller", "")
12
54
  uid = "#{this_controller_name}##{name}"
13
55
  parent_uid = if parent_opt = options.delete(:parent)
@@ -44,20 +86,22 @@ module Pageable
44
86
  end
45
87
 
46
88
  map(name, path, options = {}, &block)
47
- @pages ||= []
48
- @pages << "#{name}"
89
+ @pages ||= ActiveSupport::HashWithIndifferentAccess.new
90
+ @pages[name] = page
49
91
  end
50
-
92
+
93
+ def page_names
94
+ @page_names ||= @pages.map {|name, page| page.name}
95
+ end
96
+
51
97
  def pages
52
- @pages || []
98
+ @pages ||= ActiveSupport::HashWithIndifferentAccess.new
53
99
  end
100
+
54
101
  end
55
102
 
56
103
  def load_current_page
57
- if self.class.pages.include?(action_name)
58
- this_controller_name = "#{self.class.name.underscore}".gsub("_controller", "")
59
- @current_page = Page.find_by_uid("#{this_controller_name}##{action_name}")
60
- end
104
+ @current_page.reload if @current_page = self.class.pages[action_name]
61
105
  end
62
106
 
63
107
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fullstack-cms"
8
- s.version = "0.1.9"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mcasimir"]
12
- s.date = "2012-08-20"
12
+ s.date = "2012-08-22"
13
13
  s.description = "CMS system built on fullstack"
14
14
  s.email = "maurizio.cas@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -23,7 +23,6 @@ Gem::Specification.new do |s|
23
23
  "TODO.md",
24
24
  "VERSION",
25
25
  "app/controllers/admin/menus_controller.rb",
26
- "app/controllers/admin/page_parts_controller.rb",
27
26
  "app/controllers/admin/pages_controller.rb",
28
27
  "app/controllers/admin/photos_controller.rb",
29
28
  "app/controllers/admin/settings_controller.rb",
@@ -97,6 +96,7 @@ Gem::Specification.new do |s|
97
96
  "lib/generators/fullstack/cms/templates/rails/config/initializers/devise_controller.rb",
98
97
  "lib/generators/fullstack/cms/templates/rails/config/initializers/devise_mailer.rb",
99
98
  "lib/generators/fullstack/cms/templates/rails/config/initializers/fullstack.rb",
99
+ "lib/generators/fullstack/cms/templates/rails/config/initializers/sitemap.rb",
100
100
  "lib/generators/fullstack/cms/templates/rails/config/schedule.rb",
101
101
  "lib/generators/fullstack/cms/templates/rails/config/sitemap.rb.tt",
102
102
  "lib/generators/fullstack/cms/templates/rails/config/styles.yml",
@@ -0,0 +1,10 @@
1
+ if Rails.env.development?
2
+
3
+ # Set save path to a git-ignored destination for development environment
4
+ # comment these lines to use the default `Rails.root/public` instead
5
+
6
+ Sitemap.configure do |config|
7
+ config.save_path = Rails.root.join("tmp")
8
+ end
9
+
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fullstack-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-20 00:00:00.000000000 Z
12
+ date: 2012-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fullstack
@@ -201,7 +201,6 @@ files:
201
201
  - TODO.md
202
202
  - VERSION
203
203
  - app/controllers/admin/menus_controller.rb
204
- - app/controllers/admin/page_parts_controller.rb
205
204
  - app/controllers/admin/pages_controller.rb
206
205
  - app/controllers/admin/photos_controller.rb
207
206
  - app/controllers/admin/settings_controller.rb
@@ -275,6 +274,7 @@ files:
275
274
  - lib/generators/fullstack/cms/templates/rails/config/initializers/devise_controller.rb
276
275
  - lib/generators/fullstack/cms/templates/rails/config/initializers/devise_mailer.rb
277
276
  - lib/generators/fullstack/cms/templates/rails/config/initializers/fullstack.rb
277
+ - lib/generators/fullstack/cms/templates/rails/config/initializers/sitemap.rb
278
278
  - lib/generators/fullstack/cms/templates/rails/config/schedule.rb
279
279
  - lib/generators/fullstack/cms/templates/rails/config/sitemap.rb.tt
280
280
  - lib/generators/fullstack/cms/templates/rails/config/styles.yml
@@ -306,7 +306,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
306
  version: '0'
307
307
  segments:
308
308
  - 0
309
- hash: 3344686283421868299
309
+ hash: -4299439762194972164
310
310
  required_rubygems_version: !ruby/object:Gem::Requirement
311
311
  none: false
312
312
  requirements:
@@ -1,16 +0,0 @@
1
- class Admin::PagePartsController < Admin::BaseController
2
- respond_to :html, :js
3
-
4
- def update
5
- @page_part = Page.find(params[:page_id]).page_parts.find(params[:id])
6
- @page_part.attributes = params[:page_part]
7
- @page_part.save
8
- respond_with(@page_part)
9
- end
10
-
11
- def destroy
12
- @page_part = Page.find(params[:page_id]).page_parts.find(params[:id])
13
- @page_part.destroy
14
- respond_with(@page_part)
15
- end
16
- end