orange 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/orange-core/carton.rb +7 -8
- data/lib/orange-more.rb +4 -1
- data/lib/orange-more/administration/cartons/site.rb +6 -8
- data/lib/orange-more/administration/cartons/site_carton.rb +1 -1
- data/lib/orange-more/administration/cartons/user.rb +21 -11
- data/lib/orange-more/administration/middleware/access_control.rb +1 -1
- data/lib/orange-more/administration/middleware/site_load.rb +2 -2
- data/lib/orange-more/administration/resources/site_resource.rb +1 -1
- data/lib/orange-more/administration/resources/user_resource.rb +32 -1
- data/lib/orange-more/administration/views/users/create.haml +10 -0
- data/lib/orange-more/administration/views/users/edit.haml +15 -0
- data/lib/orange-more/blog/cartons/blog.rb +6 -8
- data/lib/orange-more/blog/cartons/blog_post.rb +50 -52
- data/lib/orange-more/blog/resources/blog_post_resource.rb +4 -4
- data/lib/orange-more/blog/resources/blog_resource.rb +14 -11
- data/lib/orange-more/news.rb +1 -0
- data/lib/orange-more/news/cartons/news.rb +12 -0
- data/lib/orange-more/news/plugin.rb +13 -0
- data/lib/orange-more/news/resources/news_resource.rb +73 -0
- data/lib/orange-more/news/views/news/archive.haml +14 -0
- data/lib/orange-more/news/views/news/edit.haml +7 -0
- data/lib/orange-more/news/views/news/latest.haml +8 -0
- data/lib/orange-more/news/views/news/sitemap_row.haml +14 -0
- data/lib/orange-more/pages/cartons/page_carton.rb +10 -11
- data/lib/orange-more/pages/cartons/page_version_carton.rb +9 -10
- data/lib/orange-more/pages/resources/page_resource.rb +1 -1
- data/lib/orange-more/sitemap/cartons/route.rb +34 -36
- data/lib/orange-more/sitemap/resources/sitemap_resource.rb +28 -12
- data/lib/orange-more/subsites.rb +1 -0
- data/lib/orange-more/subsites/cartons/subsite.rb +8 -0
- data/lib/orange-more/subsites/middleware/subsite_load.rb +28 -0
- data/lib/orange-more/subsites/plugin.rb +17 -0
- data/lib/orange-more/subsites/resources/subsite_resource.rb +46 -0
- data/lib/orange-more/subsites/views/subsites/index.haml +2 -0
- data/lib/orange-more/testimonials.rb +1 -0
- data/lib/orange-more/testimonials/cartons/testimonials_carton.rb +15 -0
- data/lib/orange-more/testimonials/plugin.rb +13 -0
- data/lib/orange-more/testimonials/resources/testimonials_resource.rb +26 -0
- data/lib/orange-more/testimonials/views/testimonials/testimonials.haml +4 -0
- metadata +23 -2
data/lib/orange-core/carton.rb
CHANGED
@@ -23,6 +23,9 @@ module Orange
|
|
23
23
|
# improve scaffolding capability.
|
24
24
|
class Carton
|
25
25
|
SCAFFOLD_OPTIONS = [:display_name, :levels] unless defined?(SCAFFOLD_OPTIONS)
|
26
|
+
extend ClassInheritableAttributes
|
27
|
+
cattr_accessor :scaffold_properties
|
28
|
+
|
26
29
|
# Declares a ModelResource subclass that scaffolds this carton
|
27
30
|
# The Subclass will have the name of the carton followed by "_Resource"
|
28
31
|
def self.as_resource
|
@@ -41,21 +44,17 @@ module Orange
|
|
41
44
|
def self.id
|
42
45
|
include DataMapper::Resource
|
43
46
|
property(:id, Serial)
|
44
|
-
|
47
|
+
self.scaffold_properties ||= []
|
45
48
|
init
|
46
49
|
end
|
47
50
|
|
48
|
-
def self.scaffold_properties
|
49
|
-
@scaffold_properties ||= []
|
50
|
-
end
|
51
|
-
|
52
51
|
# Stub init method
|
53
52
|
def self.init
|
54
53
|
end
|
55
54
|
|
56
55
|
# Return properties that should be shown for a given context
|
57
56
|
def self.form_props(context = :live)
|
58
|
-
scaffold_properties.select{|p| p[:levels].include?(context) }
|
57
|
+
self.scaffold_properties.select{|p| p[:levels].include?(context) }
|
59
58
|
end
|
60
59
|
|
61
60
|
# Helper to wrap properties into admin level
|
@@ -80,7 +79,7 @@ module Orange
|
|
80
79
|
end
|
81
80
|
|
82
81
|
def self.add_scaffold(name, type, dm_type, opts)
|
83
|
-
scaffold_properties << {:name => name, :type => type, :levels => @levels}.merge(opts) if @levels || opts.has_key?(:levels)
|
82
|
+
self.scaffold_properties << {:name => name, :type => type, :levels => @levels}.merge(opts) if @levels || opts.has_key?(:levels)
|
84
83
|
opts = opts.delete_if{|k,v| SCAFFOLD_OPTIONS.include?(k)} # DataMapper doesn't like arbitrary opts
|
85
84
|
self.property(name, dm_type, opts)
|
86
85
|
end
|
@@ -112,7 +111,7 @@ module Orange
|
|
112
111
|
# Define a helper for type database stuff
|
113
112
|
# Show in a context if wrapped in one of the helpers
|
114
113
|
def self.expose(name, opts = {})
|
115
|
-
scaffold_properties << {:name => name, :type => :text, :levels => @levels, :opts => opts} if @levels
|
114
|
+
self.scaffold_properties << {:name => name, :type => :text, :levels => @levels, :opts => opts} if @levels
|
116
115
|
end
|
117
116
|
|
118
117
|
# Define a helper for input type="text" type database stuff
|
data/lib/orange-more.rb
CHANGED
@@ -9,6 +9,9 @@ require File.join(libdir, 'orange-more', 'pages')
|
|
9
9
|
require File.join(libdir, 'orange-more', 'sitemap')
|
10
10
|
require File.join(libdir, 'orange-more', 'slices')
|
11
11
|
require File.join(libdir, 'orange-more', 'blog')
|
12
|
+
require File.join(libdir, 'orange-more', 'news')
|
12
13
|
require File.join(libdir, 'orange-more', 'disqus')
|
14
|
+
require File.join(libdir, 'orange-more', 'testimonials')
|
13
15
|
require File.join(libdir, 'orange-more', 'cloud')
|
14
|
-
require File.join(libdir, 'orange-more', 'debugger')
|
16
|
+
require File.join(libdir, 'orange-more', 'debugger')
|
17
|
+
require File.join(libdir, 'orange-more', 'subsites')
|
@@ -1,17 +1,27 @@
|
|
1
1
|
require 'orange-core/carton'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
class OrangeUser < Orange::Carton
|
4
|
+
id
|
5
|
+
admin do
|
6
|
+
title :name
|
7
|
+
text :open_id
|
8
|
+
end
|
9
|
+
|
10
|
+
has n, :orange_sites, :through => Resource
|
11
|
+
|
12
|
+
def allowed?(packet)
|
13
|
+
subsite_access = packet['subsite'].blank? ? false : self.orange_sites.first(:id => packet['subsite'].id)
|
14
|
+
site_access = self.orange_sites.first(:id => packet['site'].id)
|
15
|
+
if(site_access)
|
14
16
|
true
|
17
|
+
elsif !packet['subsite'].blank? && subsite_access
|
18
|
+
true
|
19
|
+
else
|
20
|
+
false
|
15
21
|
end
|
16
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class OrangeSite
|
26
|
+
has n, :orange_users, :through => Resource
|
17
27
|
end
|
@@ -48,7 +48,7 @@ module Orange::Middleware
|
|
48
48
|
def access_allowed?(packet)
|
49
49
|
return true unless @locked.include?(packet['route.context'])
|
50
50
|
if packet['user.id'] || packet['orange.globals']['main_user'] == false
|
51
|
-
if @single && (packet['user.id'] == packet['orange.globals']['main_user'])
|
51
|
+
if @single && (packet['user.id'] == packet['orange.globals']['main_user'] )
|
52
52
|
true
|
53
53
|
elsif @single
|
54
54
|
# Current id no good.
|
@@ -6,11 +6,11 @@ module Orange::Middleware
|
|
6
6
|
class SiteLoad < Base
|
7
7
|
def packet_call(packet)
|
8
8
|
url = packet['route.site_url']
|
9
|
-
site =
|
9
|
+
site = OrangeSite.first(:url.like => url)
|
10
10
|
if site
|
11
11
|
packet['site'] = site
|
12
12
|
else
|
13
|
-
s =
|
13
|
+
s = OrangeSite.new({:url => packet['route.site_url'],
|
14
14
|
:name => 'An Orange Site'})
|
15
15
|
s.save
|
16
16
|
packet['site'] = s
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Orange
|
2
2
|
class UserResource < Orange::ModelResource
|
3
|
-
use
|
3
|
+
use OrangeUser
|
4
4
|
call_me :users
|
5
5
|
def afterLoad
|
6
6
|
orange[:admin].add_link("Settings", :resource => @my_orange_name, :text => 'Users')
|
@@ -15,5 +15,36 @@ module Orange
|
|
15
15
|
def user_for(packet)
|
16
16
|
model_class.first(:open_id => packet['user.id'])
|
17
17
|
end
|
18
|
+
|
19
|
+
def new(packet, *opts)
|
20
|
+
if packet.request.post?
|
21
|
+
params = packet.request.params[@my_orange_name.to_s]
|
22
|
+
sites = params.delete 'sites'
|
23
|
+
m = model_class.new(params)
|
24
|
+
m.save
|
25
|
+
sites.each{|k,v| s = OrangeSite.first(:id => k); m.orange_sites << s if s} if sites
|
26
|
+
m.save
|
27
|
+
end
|
28
|
+
packet.reroute(@my_orange_name, :orange)
|
29
|
+
end
|
30
|
+
|
31
|
+
def save(packet, *opts)
|
32
|
+
if packet.request.post?
|
33
|
+
m = model_class.get(packet['route.resource_id'])
|
34
|
+
if m
|
35
|
+
params = packet.request.params[@my_orange_name.to_s]
|
36
|
+
sites = params.delete 'sites'
|
37
|
+
m.update(params)
|
38
|
+
m.orange_sites.destroy
|
39
|
+
sites.each{|k,v| s = OrangeSite.first(:id => k); m.orange_sites << s if s} if sites
|
40
|
+
m.save
|
41
|
+
end
|
42
|
+
end
|
43
|
+
packet.reroute(@my_orange_name, :orange)
|
44
|
+
end
|
45
|
+
|
46
|
+
def find_extras(packet, mode)
|
47
|
+
{:sites => OrangeSite.all}
|
48
|
+
end
|
18
49
|
end
|
19
50
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%form{:action => "#{packet.route_to(model_name, 'new')}", :method => 'post'}
|
2
|
+
- for prop in props
|
3
|
+
%p= view_attribute(prop, model_name, :label => true)
|
4
|
+
%fieldset
|
5
|
+
%h4 Permission to Edit:
|
6
|
+
- for site in sites
|
7
|
+
%p
|
8
|
+
#{site.name}
|
9
|
+
%input{:type => 'checkbox', :name => "#{model_name}[sites][#{site.id}]", :value => site.id}
|
10
|
+
%input{:type => 'submit', :value => 'Save New Item'}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- if model
|
2
|
+
- if resource.options[:sitemappable, false]
|
3
|
+
= orange[:sitemap, true].sitemap_links(packet, {:slug_me => orange[:sitemap, true].slug_for(model, props)})
|
4
|
+
%form{:action => packet.route_to(model_name, model[:id], 'save'), :method => 'post'}
|
5
|
+
- for prop in props
|
6
|
+
%p!= view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
|
7
|
+
%fieldset
|
8
|
+
%h4 Permission to Edit:
|
9
|
+
- for site in sites
|
10
|
+
%p
|
11
|
+
#{site.name}
|
12
|
+
%input{:type => 'checkbox', :name => "#{model_name}[sites][#{site.id}]", :value => site.id, :checked => (model.orange_sites.include?(site) ? 'checked' : nil)}
|
13
|
+
%input{:type => 'submit', :value => 'Save Changes'}
|
14
|
+
- else
|
15
|
+
%p Couldn't find the item you're looking for.
|
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'orange-more/administration/cartons/site_carton'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
title :title
|
7
|
-
end
|
8
|
-
has n, :posts, "Orange::BlogPost"
|
2
|
+
class OrangeBlog < Orange::SiteCarton
|
3
|
+
id
|
4
|
+
front do
|
5
|
+
title :title
|
9
6
|
end
|
10
|
-
|
7
|
+
has n, :posts, "OrangeBlogPost"
|
8
|
+
end
|
@@ -1,55 +1,53 @@
|
|
1
1
|
require 'dm-timestamps'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
all(:published => false)
|
53
|
-
end
|
2
|
+
class OrangeBlogPost < Orange::Carton
|
3
|
+
id
|
4
|
+
front do
|
5
|
+
title :title
|
6
|
+
fulltext :body
|
7
|
+
end
|
8
|
+
admin do
|
9
|
+
fulltext :summary
|
10
|
+
end
|
11
|
+
orange do
|
12
|
+
boolean :published, :default => false
|
13
|
+
text :slug
|
14
|
+
text :author
|
15
|
+
end
|
16
|
+
|
17
|
+
property :created_at, DateTime
|
18
|
+
property :published_at, DateTime
|
19
|
+
property :updated_at, DateTime
|
20
|
+
belongs_to :blog, "OrangeBlog"
|
21
|
+
|
22
|
+
def title=(t)
|
23
|
+
self.attribute_set('title', t)
|
24
|
+
self.attribute_set('slug', str.downcase.gsub(/[']+/, "").gsub(/[^a-z0-9]+/, "_"))
|
25
|
+
end
|
26
|
+
|
27
|
+
def publish
|
28
|
+
self.published_at = Time.now
|
29
|
+
self.published = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def publish!
|
33
|
+
self.published_at = Time.now
|
34
|
+
self.published = true
|
35
|
+
self.save
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.year_and_month(yr, mnth)
|
39
|
+
all(:published_at.gte => DateTime.new(yr, mnth, 1), :published_at.lt => DateTime.new(yr, mnth + 1, 1))
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.slug(slug)
|
43
|
+
first(:slug => slug)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.published
|
47
|
+
all(:published => true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.draft
|
51
|
+
all(:published => false)
|
54
52
|
end
|
55
53
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Orange
|
2
2
|
class BlogResource < Orange::ModelResource
|
3
|
-
use
|
3
|
+
use OrangeBlogPost
|
4
4
|
call_me :blog_posts
|
5
5
|
def afterLoad
|
6
6
|
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Blog')
|
@@ -26,7 +26,7 @@ module Orange
|
|
26
26
|
params[:published] = false
|
27
27
|
params[:author] = packet['user', false] ? packet['user'].name : "Author"
|
28
28
|
|
29
|
-
blog =
|
29
|
+
blog = OrangeBlog.first(:orange_site => (packet['subsite'].blank? ? packet['site'] : packet['subsite']))
|
30
30
|
blog.posts.new(params)
|
31
31
|
blog.save
|
32
32
|
end
|
@@ -41,7 +41,7 @@ module Orange
|
|
41
41
|
if m
|
42
42
|
params = packet.request.params[@my_orange_name.to_s]
|
43
43
|
m.update(params)
|
44
|
-
m.blog =
|
44
|
+
m.blog = OrangeBlog.first(:orange_site => (packet['subsite'].blank? ? packet['site'] : packet['subsite']))
|
45
45
|
m.save
|
46
46
|
end
|
47
47
|
end
|
@@ -49,7 +49,7 @@ module Orange
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def find_list(packet, mode, id =false)
|
52
|
-
blog = orange[:blog].blog_for_site(packet
|
52
|
+
blog = orange[:blog].blog_for_site(packet)
|
53
53
|
blog.posts
|
54
54
|
end
|
55
55
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Orange
|
2
2
|
class BlogPostResource < Orange::ModelResource
|
3
|
-
use
|
3
|
+
use OrangeBlog
|
4
4
|
call_me :blog
|
5
5
|
def afterLoad
|
6
6
|
orange[:admin, true].add_link("Settings", :resource => @my_orange_name, :text => 'Blog')
|
@@ -25,7 +25,7 @@ module Orange
|
|
25
25
|
|
26
26
|
def blog_post_view(packet, opts = {})
|
27
27
|
resource_path = packet['route.resource_path']
|
28
|
-
blog =
|
28
|
+
blog = blog_for_site(packet)
|
29
29
|
opts.merge!( :blog_url => blog_url_for(packet))
|
30
30
|
parts = resource_path.split('/')
|
31
31
|
unless parts.size < 4
|
@@ -39,15 +39,15 @@ module Orange
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def blog_url_for(packet)
|
42
|
-
blog =
|
43
|
-
blog_url = orange[:sitemap, true].url_for(packet, :orange_site_id => blog.orange_site_id, :resource => :blog, :resource_id => blog.id, :resource_action => :blog_view)
|
42
|
+
blog = blog_for_site(packet)
|
43
|
+
blog_url = orange[:sitemap, true].url_for(packet, :orange_site_id => blog.orange_site_id, :resource => :blog, :resource_id => blog.id, :resource_action => :blog_view, :include_subsite => true)
|
44
44
|
blog_url.gsub!(/\/$/, '')
|
45
45
|
end
|
46
46
|
|
47
47
|
def blog_offset_list_view(packet, opts = {})
|
48
48
|
opts.merge!(packet.extract_opts)
|
49
49
|
opts.merge!( :blog_url => blog_url_for(packet))
|
50
|
-
blog =
|
50
|
+
blog = blog_for_site(packet)
|
51
51
|
opts[:page] = opts[:page].to_i unless opts[:page].blank?
|
52
52
|
page = opts[:page].blank? ? 0 : opts[:page] - 1
|
53
53
|
opts[:list] = blog.posts.published.all(:order => :published_at.desc,
|
@@ -67,15 +67,18 @@ module Orange
|
|
67
67
|
do_list_view(packet, :blog_archive_view, opts)
|
68
68
|
end
|
69
69
|
|
70
|
-
def blog_for_site(packet, site_id)
|
71
|
-
|
70
|
+
def blog_for_site(packet, site_id = false)
|
71
|
+
site_id ||= (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id)
|
72
|
+
blog = OrangeBlog.first(:orange_site_id => site_id)
|
72
73
|
unless blog
|
73
|
-
blog =
|
74
|
+
blog = OrangeBlog.new
|
74
75
|
blog.title = 'An Orange Hosted Blog'
|
75
76
|
blog.orange_site = packet['site']
|
76
77
|
blog.save
|
78
|
+
end
|
79
|
+
unless OrangeRoute.first(:resource => 'blog', :orange_site_id => packet['site'].id)
|
77
80
|
orange[:sitemap, true].add_route_for(packet,
|
78
|
-
:orange_site_id =>
|
81
|
+
:orange_site_id => site_id,
|
79
82
|
:resource => :blog,
|
80
83
|
:resource_id => blog.id,
|
81
84
|
:resource_action => :blog_view,
|
@@ -87,11 +90,11 @@ module Orange
|
|
87
90
|
end
|
88
91
|
|
89
92
|
def find_list(packet, mode, id =false)
|
90
|
-
blog =
|
93
|
+
blog = blog_for_site(packet)
|
91
94
|
case mode
|
92
95
|
when :blog_list_view then blog.posts.published.all(:order => :published_at.desc, :limit => 5)
|
93
96
|
when :blog_archive_view then blog.posts.published
|
94
|
-
else
|
97
|
+
else OrangeBlog.all
|
95
98
|
end
|
96
99
|
end
|
97
100
|
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join('orange-more', 'news', 'plugin')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
|
3
|
+
|
4
|
+
module Orange::Plugins
|
5
|
+
class News < Base
|
6
|
+
views_dir File.join(File.dirname(__FILE__), 'views')
|
7
|
+
|
8
|
+
resource Orange::NewsResource.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Orange.plugin(Orange::Plugins::News.new)
|
13
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Orange
|
2
|
+
class NewsResource < Orange::ModelResource
|
3
|
+
use OrangeNews
|
4
|
+
call_me :news
|
5
|
+
def afterLoad
|
6
|
+
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'News')
|
7
|
+
|
8
|
+
orange.register(:stack_loaded) do
|
9
|
+
orange[:radius, true].context.define_tag "latest_news" do |tag|
|
10
|
+
orange[:news].latest(tag.locals.packet)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def new(packet, opts = {})
|
16
|
+
news = OrangeNews.first()
|
17
|
+
unless OrangeRoute.first(:resource => 'news', :orange_site_id => packet['site'].id)
|
18
|
+
orange[:sitemap, true].add_route_for(packet,
|
19
|
+
:orange_site_id => packet['site'].id,
|
20
|
+
:resource => :news,
|
21
|
+
:resource_action => :archive,
|
22
|
+
:slug => 'news-archive',
|
23
|
+
:link_text => 'Orange News Archive'
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
super(packet, opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def sitemap_row(packet, opts = {})
|
31
|
+
do_view(packet, :sitemap_row, opts)
|
32
|
+
end
|
33
|
+
|
34
|
+
def news_view(packet, opts = {})
|
35
|
+
resource_path = packet['route.resource_path']
|
36
|
+
if resource_path.blank?
|
37
|
+
archive_view(packet, opts)
|
38
|
+
elsif resource_path =~ /^\/page/
|
39
|
+
archive(packet, opts)
|
40
|
+
else
|
41
|
+
archive_view(packet, opts)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def latest(packet)
|
46
|
+
do_list_view(packet, :latest, {
|
47
|
+
:list => model_class.all(:order => :created_at.desc, :limit => 3)
|
48
|
+
})
|
49
|
+
end
|
50
|
+
|
51
|
+
def archive(packet, opts = {})
|
52
|
+
opts.merge!(packet.extract_opts)
|
53
|
+
opts.merge!( :archive_url => archive_url(packet))
|
54
|
+
opts[:page] = opts[:page].blank? ? 1 : opts[:page].to_i
|
55
|
+
page = opts[:page].blank? ? 0 : opts[:page] - 1
|
56
|
+
opts[:list] = model_class.all(:order => :created_at.desc,
|
57
|
+
:limit => 5,
|
58
|
+
:offset => (5*page)
|
59
|
+
)
|
60
|
+
opts[:pages] = (model_class.count / 5) + 1
|
61
|
+
do_list_view(packet, :archive, opts)
|
62
|
+
end
|
63
|
+
|
64
|
+
def archive_view(packet, opts = {})
|
65
|
+
archive(packet, opts.merge!({:page => 1}))
|
66
|
+
end
|
67
|
+
|
68
|
+
def archive_url(packet)
|
69
|
+
url = orange[:sitemap, true].url_for(packet, :resource => :news, :resource_action => :archive)
|
70
|
+
url.gsub!(/\/$/, '')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
.news_items
|
2
|
+
- list.each do |news|
|
3
|
+
.news_item
|
4
|
+
%h2.news_title
|
5
|
+
%a{:href => news.link} #{news.title}
|
6
|
+
.news_description
|
7
|
+
= news.description
|
8
|
+
%p
|
9
|
+
%a{:href => news.link, :class => 'view_story'} View Story »
|
10
|
+
.news_nav
|
11
|
+
- if page > 1
|
12
|
+
%a.newer{:href => "#{archive_url}/page/#{page-1}"} Newer Posts
|
13
|
+
- if page < pages
|
14
|
+
%a.older{:href => "#{archive_url}/page/#{page+1}"} Older Posts
|
@@ -0,0 +1,7 @@
|
|
1
|
+
- if model
|
2
|
+
%form{:action => route_to(model_name, model[:id], 'save'), :method => 'post'}
|
3
|
+
- for prop in props
|
4
|
+
%p~ view_attribute(prop, model_name, :label => true, :value => model.attribute_get(prop[:name]))
|
5
|
+
%input{:type => 'submit', :value => 'Save Changes'}
|
6
|
+
- else
|
7
|
+
%p Couldn't find the item you're looking for.
|
@@ -0,0 +1,14 @@
|
|
1
|
+
- if route
|
2
|
+
.sitemap_item{:class => "sitemap_level_#{route.level}"}
|
3
|
+
- if route.level > 0
|
4
|
+
= orange[:sitemap].route_actions(packet, :model => route)
|
5
|
+
%h4 #{route.link_text} <span>(#{route.full_path})</span>
|
6
|
+
.linked_to
|
7
|
+
%p
|
8
|
+
News Archive
|
9
|
+
%br
|
10
|
+
%a{:href => route_to(:news, 'create')} Add New News Post
|
11
|
+
.actions
|
12
|
+
= form_link('Delete', route_to(:sitemap, route.id, 'delete'), 'Are you sure you want to delete this?', {:method => 'delete'})
|
13
|
+
%a{:href => route_to(:sitemap, route.id, 'edit')} Edit
|
14
|
+
%br.clear
|
@@ -1,15 +1,14 @@
|
|
1
1
|
require 'dm-timestamps'
|
2
2
|
require 'orange-more/administration/cartons/site_carton'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
boolean :published, :default => false
|
11
|
-
|
12
|
-
property :updated_at, DateTime
|
13
|
-
has n, :versions, "Orange::PageVersion"
|
3
|
+
|
4
|
+
class OrangePage < Orange::SiteCarton
|
5
|
+
id
|
6
|
+
front do
|
7
|
+
title :title
|
8
|
+
fulltext :body
|
14
9
|
end
|
10
|
+
boolean :published, :default => false
|
11
|
+
|
12
|
+
property :updated_at, DateTime
|
13
|
+
has n, :versions, "OrangePageVersion"
|
15
14
|
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'dm-timestamps'
|
2
2
|
require 'orange-more/administration/cartons/site_carton'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
3
|
+
|
4
|
+
class OrangePageVersion < Orange::SiteCarton
|
5
|
+
id
|
6
|
+
title :title
|
7
|
+
fulltext :body
|
8
|
+
property :updated_at, DateTime
|
9
|
+
boolean :published
|
10
|
+
property :version, Integer, :default => 0
|
11
|
+
belongs_to :orange_page, "OrangePage"
|
13
12
|
end
|
@@ -1,43 +1,41 @@
|
|
1
1
|
require 'orange-more/administration/cartons/site_carton'
|
2
2
|
require 'dm-is-awesome_set'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
path = path + '/'
|
27
|
-
end
|
4
|
+
class OrangeRoute < Orange::SiteCarton
|
5
|
+
id
|
6
|
+
admin do
|
7
|
+
text :slug
|
8
|
+
text :link_text
|
9
|
+
boolean :show_in_nav, :default => false, :display_name => 'Show in Navigation?'
|
10
|
+
end
|
11
|
+
orange do
|
12
|
+
string :resource
|
13
|
+
string :resource_id
|
14
|
+
string :resource_action
|
15
|
+
boolean :accept_args, :default => true
|
16
|
+
end
|
17
|
+
include DataMapper::Transaction::Resource # Make sure Transactions are included (for awesome_set)
|
18
|
+
is :awesome_set, :scope => [:orange_site_id]
|
19
|
+
|
20
|
+
def full_path
|
21
|
+
self_and_ancestors.inject('') do |path, part|
|
22
|
+
if part.parent # Check if this is a child
|
23
|
+
path = path + part.slug + '/'
|
24
|
+
else # The root slug is just the initial '/'
|
25
|
+
path = path + '/'
|
28
26
|
end
|
29
27
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.home_for_site(site_id)
|
31
|
+
root(:orange_site_id => site_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def self.create_home_for_site(site_id)
|
36
|
+
home = self.new({:orange_site_id => site_id, :slug => '_index_', :accept_args => false, :link_text => 'Home'})
|
37
|
+
home.move(:root)
|
38
|
+
home.save
|
39
|
+
home
|
42
40
|
end
|
43
41
|
end
|
@@ -3,7 +3,7 @@ require 'orange-core/resources/model_resource'
|
|
3
3
|
module Orange
|
4
4
|
|
5
5
|
class SitemapResource < ModelResource
|
6
|
-
use
|
6
|
+
use OrangeRoute
|
7
7
|
call_me :sitemap
|
8
8
|
def afterLoad
|
9
9
|
orange[:admin, true].add_link('Content', :resource => @my_orange_name, :text => 'Sitemap')
|
@@ -23,10 +23,11 @@ module Orange
|
|
23
23
|
packet[:content] = (orange[resource].view packet)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
# Path should be an array of path parts
|
27
|
+
def find_route_info(packet, path)
|
27
28
|
parts = path.split('/')
|
28
29
|
pad = parts.shift
|
29
|
-
matched = home(packet)
|
30
|
+
matched = home(packet, :subsite => true)
|
30
31
|
extras = ''
|
31
32
|
while (!parts.empty?)
|
32
33
|
next_part = parts.shift
|
@@ -38,6 +39,11 @@ module Orange
|
|
38
39
|
parts = []
|
39
40
|
end
|
40
41
|
end
|
42
|
+
[extras, matched]
|
43
|
+
end
|
44
|
+
|
45
|
+
def route?(packet, path)
|
46
|
+
extras, matched = find_route_info(packet, path)
|
41
47
|
return false if(extras.length > 0 && !matched.accept_args)
|
42
48
|
packet['route.path'] = path
|
43
49
|
packet['route.route'] = matched
|
@@ -54,7 +60,7 @@ module Orange
|
|
54
60
|
def new(packet, *opts)
|
55
61
|
if packet.request.post?
|
56
62
|
params = packet.request.params[@my_orange_name.to_s]
|
57
|
-
params.merge!(:orange_site_id => packet['site'].id)
|
63
|
+
params.merge!(:orange_site_id => (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id))
|
58
64
|
a = model_class.new(params)
|
59
65
|
a.move(:into => home(packet))
|
60
66
|
end
|
@@ -94,7 +100,11 @@ module Orange
|
|
94
100
|
end
|
95
101
|
|
96
102
|
def home(packet, opts = {})
|
97
|
-
|
103
|
+
if(opts[:subsite])
|
104
|
+
site_id = opts[:orange_site_id] || packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id
|
105
|
+
else
|
106
|
+
site_id = opts[:orange_site_id] || packet['site'].id
|
107
|
+
end
|
98
108
|
model_class.home_for_site(site_id) || model_class.create_home_for_site(site_id)
|
99
109
|
end
|
100
110
|
|
@@ -102,17 +112,18 @@ module Orange
|
|
102
112
|
do_view(packet, :two_level, :model => home(packet))
|
103
113
|
end
|
104
114
|
|
105
|
-
def routes_for(packet)
|
115
|
+
def routes_for(packet, opts = {})
|
106
116
|
keys = {}
|
107
|
-
keys[:resource] =
|
108
|
-
keys[:resource_id] =
|
109
|
-
keys[:orange_site_id] = packet['site'].id
|
117
|
+
keys[:resource] = opts[:resource] || packet['route.resource']
|
118
|
+
keys[:resource_id] = opts[:resource_id] || packet['route.resource_id']
|
119
|
+
keys[:orange_site_id] = opts[:orange_site_id] || packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id
|
120
|
+
keys.delete_if{|k,v| v.blank? }
|
110
121
|
model_class.all(keys)
|
111
122
|
end
|
112
123
|
|
113
124
|
def add_link_for(packet)
|
114
125
|
linky = ['add_route']
|
115
|
-
linky << (packet['site'].blank? ? '0' : packet['site'].id)
|
126
|
+
linky << (packet['subsite'].blank? ? (packet['site'].blank? ? '0' : packet['site'].id) : packet['subsite'].id)
|
116
127
|
linky << (packet['route.resource'].blank? ? '0' : packet['route.resource'])
|
117
128
|
linky << (packet['route.resource_id'].blank? ? '0' : packet['route.resource_id'])
|
118
129
|
packet.route_to(:sitemap, linky.join('/') )
|
@@ -127,8 +138,13 @@ module Orange
|
|
127
138
|
end
|
128
139
|
|
129
140
|
def url_for(packet, opts = {})
|
141
|
+
include_subsite = opts.delete(:include_subsite) || false
|
130
142
|
m = model_class.first(opts)
|
131
|
-
|
143
|
+
if !packet['subsite'].blank? && include_subsite
|
144
|
+
return orange[:subsites].url_for(packet).gsub(/\/$/, '') + (m ? m.full_path : '#not_found')
|
145
|
+
else
|
146
|
+
return (m ? m.full_path : '#not_found')
|
147
|
+
end
|
132
148
|
end
|
133
149
|
|
134
150
|
def add_route(packet, opts = {})
|
@@ -156,7 +172,7 @@ module Orange
|
|
156
172
|
end
|
157
173
|
|
158
174
|
def find_list(packet, mode, *args)
|
159
|
-
home(packet).self_and_descendants
|
175
|
+
home(packet, :subsite => true).self_and_descendants
|
160
176
|
end
|
161
177
|
|
162
178
|
def table_row(packet, opts ={})
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join('orange-more', 'subsites', 'plugin')
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'orange-core/middleware/base'
|
2
|
+
module Orange::Middleware
|
3
|
+
# This will load information about the site to into the orange env
|
4
|
+
# - packet['site'] will be an instance of the site object
|
5
|
+
#
|
6
|
+
class SubsiteLoad < Base
|
7
|
+
def packet_call(packet)
|
8
|
+
if packet['site']
|
9
|
+
site = packet['site']
|
10
|
+
path = packet['route.path'] || packet.request.path_info
|
11
|
+
|
12
|
+
# Find the subsite in the sitemap table
|
13
|
+
extras, matched = orange[:sitemap].find_route_info(packet, path)
|
14
|
+
|
15
|
+
# If matched, update the loaded site and trim the path down a bit
|
16
|
+
if !matched.resource.blank? && matched.resource.to_sym == :subsites
|
17
|
+
if(m = site.subsites.first(:id => matched.resource_id))
|
18
|
+
packet['route.path'] = extras
|
19
|
+
packet['subsite'] = m
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
pass packet
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
|
3
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'middleware', '*.rb')).each {|f| require f }
|
4
|
+
|
5
|
+
module Orange::Plugins
|
6
|
+
class Subsites < Base
|
7
|
+
views_dir File.join(File.dirname(__FILE__), 'views')
|
8
|
+
|
9
|
+
resource Orange::SubsiteResource.new
|
10
|
+
|
11
|
+
prerouter Orange::Middleware::SubsiteLoad
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Orange.plugin(Orange::Plugins::Subsites.new)
|
17
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Orange
|
2
|
+
class SubsiteResource < Orange::ModelResource
|
3
|
+
use OrangeSubsite
|
4
|
+
call_me :subsites
|
5
|
+
def afterLoad
|
6
|
+
orange[:admin, true].add_link("Settings", :resource => @my_orange_name, :text => 'Subsites')
|
7
|
+
end
|
8
|
+
|
9
|
+
# Creates a new model object and saves it (if a post), then reroutes to the main page
|
10
|
+
# @param [Orange::Packet] packet the packet being routed
|
11
|
+
def new(packet, *opts)
|
12
|
+
if packet.request.post?
|
13
|
+
m = packet['site'].subsites.new(packet.request.params[@my_orange_name.to_s])
|
14
|
+
m.save
|
15
|
+
orange[:sitemap].add_route_for(packet,
|
16
|
+
:orange_site_id => packet['site'].id,
|
17
|
+
:resource => :subsites,
|
18
|
+
:resource_id => m.id,
|
19
|
+
:slug => 'subsite',
|
20
|
+
:link_text => 'Orange Subsite'
|
21
|
+
)
|
22
|
+
end
|
23
|
+
packet.reroute(@my_orange_name, :orange)
|
24
|
+
end
|
25
|
+
|
26
|
+
def url_for(packet)
|
27
|
+
orange[:sitemap].url_for(packet, {:resource => 'subsites', :resource_id => packet['subsite'].id})
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
class Mapper < Resource
|
34
|
+
def route_to(packet, resource, *args)
|
35
|
+
opts = args.extract_options!
|
36
|
+
packet = DefaultHash.new unless packet
|
37
|
+
context = opts[:context] || packet['route.context', nil]
|
38
|
+
site = packet['route.faked_site'] ? packet['route.site_url', nil] : nil
|
39
|
+
args.unshift(resource)
|
40
|
+
args.unshift(orange[:subsites].url_for(packet).gsub(/^\//, '').gsub(/\/$/, '')) if(packet['subsite'])
|
41
|
+
args.unshift(context)
|
42
|
+
args.unshift(site)
|
43
|
+
'/'+args.compact.join('/')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join('orange-more', 'testimonials', 'plugin')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'cartons', '*.rb')).each {|f| require f }
|
2
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'resources', '*.rb')).each {|f| require f }
|
3
|
+
|
4
|
+
module Orange::Plugins
|
5
|
+
class Testimonials < Base
|
6
|
+
views_dir File.join(File.dirname(__FILE__), 'views')
|
7
|
+
|
8
|
+
resource Orange::TestimonialsResource.new
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Orange.plugin(Orange::Plugins::Testimonials.new)
|
13
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Orange
|
2
|
+
class TestimonialsResource < Orange::ModelResource
|
3
|
+
use OrangeTestimonial
|
4
|
+
call_me :testimonials
|
5
|
+
def afterLoad
|
6
|
+
orange[:admin, true].add_link("Content", :resource => @my_orange_name, :text => 'Testimonials')
|
7
|
+
orange.register(:stack_loaded) do
|
8
|
+
orange[:radius].context.define_tag "testimonials" do |tag|
|
9
|
+
if tag.attr["tag"] && model_class.all.count >0
|
10
|
+
m = model_class.with_tag(tag.attr["tag"]).first(:offset => rand(model_class.with_tag(tag.attr["tag"]).count)) #selects testimonial based on tag
|
11
|
+
elsif model_class.all.count > 0
|
12
|
+
m = model_class.first(:offset => rand(model_class.all.count)) #selects a random testimonial
|
13
|
+
end
|
14
|
+
unless m.nil?
|
15
|
+
orange[:testimonials].testimonial(tag.locals.packet, {:model => m })
|
16
|
+
else
|
17
|
+
""
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def testimonial(packet, opts = {})
|
23
|
+
do_view(packet, :testimonials, opts)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Haslem
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-03-05 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -116,6 +116,8 @@ files:
|
|
116
116
|
- lib/orange-more/administration/resources/user_resource.rb
|
117
117
|
- lib/orange-more/administration/templates/admin.haml
|
118
118
|
- lib/orange-more/administration/views/openid_login.haml
|
119
|
+
- lib/orange-more/administration/views/users/create.haml
|
120
|
+
- lib/orange-more/administration/views/users/edit.haml
|
119
121
|
- lib/orange-more/assets.rb
|
120
122
|
- lib/orange-more/assets/cartons/asset_carton.rb
|
121
123
|
- lib/orange-more/assets/plugin.rb
|
@@ -144,6 +146,14 @@ files:
|
|
144
146
|
- lib/orange-more/disqus/plugin.rb
|
145
147
|
- lib/orange-more/disqus/resources/disqus_resource.rb
|
146
148
|
- lib/orange-more/disqus/views/disqus/comment_thread.haml
|
149
|
+
- lib/orange-more/news.rb
|
150
|
+
- lib/orange-more/news/cartons/news.rb
|
151
|
+
- lib/orange-more/news/plugin.rb
|
152
|
+
- lib/orange-more/news/resources/news_resource.rb
|
153
|
+
- lib/orange-more/news/views/news/archive.haml
|
154
|
+
- lib/orange-more/news/views/news/edit.haml
|
155
|
+
- lib/orange-more/news/views/news/latest.haml
|
156
|
+
- lib/orange-more/news/views/news/sitemap_row.haml
|
147
157
|
- lib/orange-more/pages.rb
|
148
158
|
- lib/orange-more/pages/cartons/page_carton.rb
|
149
159
|
- lib/orange-more/pages/cartons/page_version_carton.rb
|
@@ -174,6 +184,17 @@ files:
|
|
174
184
|
- lib/orange-more/slices/plugin.rb
|
175
185
|
- lib/orange-more/slices/resources/radius.rb
|
176
186
|
- lib/orange-more/slices/resources/slices.rb
|
187
|
+
- lib/orange-more/subsites.rb
|
188
|
+
- lib/orange-more/subsites/cartons/subsite.rb
|
189
|
+
- lib/orange-more/subsites/middleware/subsite_load.rb
|
190
|
+
- lib/orange-more/subsites/plugin.rb
|
191
|
+
- lib/orange-more/subsites/resources/subsite_resource.rb
|
192
|
+
- lib/orange-more/subsites/views/subsites/index.haml
|
193
|
+
- lib/orange-more/testimonials.rb
|
194
|
+
- lib/orange-more/testimonials/cartons/testimonials_carton.rb
|
195
|
+
- lib/orange-more/testimonials/plugin.rb
|
196
|
+
- lib/orange-more/testimonials/resources/testimonials_resource.rb
|
197
|
+
- lib/orange-more/testimonials/views/testimonials/testimonials.haml
|
177
198
|
- lib/orange.rb
|
178
199
|
- README.markdown
|
179
200
|
has_rdoc: true
|