orange 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -203,11 +203,11 @@ module Orange
203
203
  # causing the fire. This is passed to each Proc registered.
204
204
  # @return [Boolean] returns false if nothing has been registered for the
205
205
  # event, otherwise true.
206
- def fire(event, packet)
206
+ def fire(event, packet, *args)
207
207
  return false unless @events[event]
208
208
  @events[event].compact!
209
209
  for callback in @events[event]
210
- callback.call(packet)
210
+ callback.call(packet, *args)
211
211
  end
212
212
  true
213
213
  end
@@ -141,6 +141,7 @@ module Orange
141
141
  before = beforeDelete(packet, m, opts)
142
142
  onDelete(packet, m, opts) if m && before
143
143
  afterDelete(packet, m, opts) if before
144
+ orange.fire(:model_resource_deleted, packet, {:resource_id => id, :resource => @my_orange_name})
144
145
  end
145
146
  packet.reroute(@my_orange_name, :orange) unless (packet.request.xhr? || no_reroute)
146
147
  end
@@ -22,6 +22,15 @@ module Orange
22
22
  true
23
23
  end
24
24
 
25
+ def link_for(packet, news)
26
+ match = news.link.match(/\[(\d+)\]/)
27
+ if match
28
+ orange[:sitemap, true].to_href(packet, match[1].to_i)
29
+ else
30
+ news.link
31
+ end
32
+ end
33
+
25
34
  def sitemap_row(packet, opts = {})
26
35
  do_view(packet, :sitemap_row, opts)
27
36
  end
@@ -2,11 +2,11 @@
2
2
  - for news in list
3
3
  .news_item
4
4
  %h2.news_title
5
- %a{:href => news.link} #{news.title}
5
+ %a{:href => (resource.link_for(packet, news))} #{news.title}
6
6
  .news_description
7
7
  = news.description
8
8
  %p
9
- %a{:href => news.link, :class => 'view_story'} View Story »
9
+ %a{:href => (resource.link_for(packet, news)), :class => 'view_story'} View Story »
10
10
  .news_nav
11
11
  - if page > 1
12
12
  %a.newer{:href => "#{archive_url}/page/#{page-1}"} Newer Posts
@@ -1,8 +1,8 @@
1
1
  - list.each do |news|
2
2
  .news_item
3
3
  %p.news_title
4
- %a{:href => news.link} #{news.title}
4
+ %a{:href => (resource.link_for(packet, news))} #{news.title}
5
5
  .news_description
6
6
  = news.description
7
7
  %p
8
- %a{:href => news.link, :class => 'view_story'} View Story »
8
+ %a{:href => (resource.link_for(packet, news)), :class => 'view_story'} View Story »
@@ -49,18 +49,19 @@ module Orange
49
49
  m.versions.new(params.merge(:version => max + 1))
50
50
  m.save
51
51
 
52
- r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name)
52
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id)
53
53
  # Add route if none.
54
54
  if (r.blank? && orange.loaded?(:sitemap))
55
+
55
56
  route_hash = {
56
- :orange_site_id => m.orange_site_id,
57
+ :orange_site_id => m.orange_site.id,
57
58
  :resource => @my_orange_name,
58
59
  :resource_id => m.id,
59
60
  :slug => orange[:sitemap].slug_for(m, params),
60
61
  :show_in_nav => false,
61
62
  :link_text => "{title}"
62
63
  }
63
- parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages")
64
+ parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id)
64
65
  route_hash[:parent] = parents.first unless parents.blank?
65
66
  orange[:sitemap].add_route_for(packet, route_hash)
66
67
  end
@@ -74,7 +75,7 @@ module Orange
74
75
  def onNew(packet, params = {})
75
76
  params[:published] = false
76
77
  m = model_class.new(params)
77
- m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
78
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
78
79
  # m.versions.new(params.merge(:version => 1))
79
80
  m
80
81
  end
@@ -82,30 +83,30 @@ module Orange
82
83
  # Saves updates to an object specified by packet['route.resource_id'], then reroutes to main
83
84
  # @param [Orange::Packet] packet the packet being routed
84
85
  def onSave(packet, m, params = {})
85
- r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name)
86
+ r = orange[:sitemap, true].routes_for(packet, :resource_id => m.id, :resource => @my_orange_name, :orange_site_id => m.orange_site.id)
86
87
  # Add route if none.
87
88
  if (r.blank? && orange.loaded?(:sitemap))
88
89
  route_hash = {
89
- :orange_site_id => m.orange_site_id,
90
+ :orange_site_id => m.orange_site.id,
90
91
  :resource => @my_orange_name,
91
92
  :resource_id => m.id,
92
93
  :slug => orange[:sitemap].slug_for(m, params),
93
94
  :show_in_nav => false,
94
95
  :link_text => "{title}"
95
96
  }
96
- parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages")
97
+ parents = orange[:sitemap].routes_for(packet, :resource => '', :resource_id => '', :slug => "pages", :orange_site_id => m.orange_site.id)
97
98
  route_hash[:parent] = parents.first unless parents.blank?
98
99
  orange[:sitemap].add_route_for(packet, route_hash)
99
100
  end
100
101
  if (params["published"] == "1")
101
102
  params["published"] = true
102
- m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
103
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
103
104
 
104
105
  m.update(params)
105
106
  orange[:pages].publish(packet, :no_reroute => true, :model => m)
106
107
  else
107
108
  params["published"] = false
108
- m.orange_site = packet['subsite', false] ? packet['subsite'] : packet['site'] unless m.orange_site
109
+ m.orange_site = (packet['subsite', false] ? packet['subsite'] : packet['site']) unless m.orange_site
109
110
  m.update(params)
110
111
  end
111
112
  end
@@ -10,14 +10,33 @@ module Orange
10
10
  orange[:radius, true].define_tag "link" do |tag|
11
11
  packet = tag.locals.packet
12
12
  slug = tag.expand
13
- route = orange[:sitemap].find_route(packet, {:slug => slug})
13
+ id = tag.attr['id'] if tag.attr['id']
14
+ route = orange[:sitemap].find_route(packet, {:id => id}) if id
15
+ route = orange[:sitemap].find_route(packet, {:slug => slug}) unless route
14
16
  route = orange[:sitemap].find_route(packet, {:link_text => slug}) unless route
15
17
 
16
- full_path = route ? route.full_path : "#not-found"
17
- link_text = route ? route.link_text : "(Broken link tag)"
18
- link_text = tag.attr["text"] if tag.attr["text"]
19
- "<a href='#{full_path}'>#{link_text}</a>"
18
+ orange[:sitemap].to_html(packet, route, tag.attr["text"])
20
19
  end
20
+ orange.register(:model_resource_deleted) do |packet, opts|
21
+ model_class.all(opts).destroy!
22
+ end
23
+ end
24
+
25
+ def to_href(packet, route)
26
+ unless route.is_a? model_class
27
+ route = model_class.get(route)
28
+ end
29
+ full_path = route ? route.full_path : "#not-found"
30
+ end
31
+
32
+ def to_html(packet, route, text = false)
33
+ unless route.is_a? model_class
34
+ route = model_class.get(route)
35
+ end
36
+ full_path = route ? route.full_path : "#not-found"
37
+ link_text = route ? link_text_for(route) : "(Broken link tag)"
38
+ link_text = text if text
39
+ "<a href='#{full_path}'>#{link_text}</a>"
21
40
  end
22
41
 
23
42
  def route_actions(packet, opts = {})
@@ -170,7 +189,7 @@ module Orange
170
189
  keys = {}
171
190
  keys[:resource] = opts[:resource] || packet['route.resource']
172
191
  keys[:resource_id] = opts[:resource_id] || packet['route.resource_id']
173
- keys[:orange_site_id] = opts[:orange_site_id] || packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id
192
+ keys[:orange_site_id] = opts[:orange_site_id] || (packet['subsite'].blank? ? packet['site'].id : packet['subsite'].id)
174
193
  keys[:slug] = opts[:slug]
175
194
  keys.delete_if{|k,v| v.blank? }
176
195
  model_class.all(keys)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 4
9
- version: 0.5.4
8
+ - 5
9
+ version: 0.5.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - David Haslem