xhive 1.0.8.pre → 1.0.9.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/app/helpers/xhive/application_helper.rb +1 -1
- data/app/models/xhive/mapper.rb +19 -5
- data/lib/xhive/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -201,13 +201,13 @@ stylesheet = Xhive::Stylesheet.create(:name => 'Posts',
|
|
201
201
|
Create a new mapper record for the posts resources
|
202
202
|
|
203
203
|
```
|
204
|
-
mapper = Xhive::Mapper.
|
204
|
+
mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'index')
|
205
205
|
```
|
206
206
|
|
207
|
-
|
207
|
+
If you want to map the page to a specific post
|
208
208
|
|
209
209
|
```
|
210
|
-
mapper = Xhive::Mapper.
|
210
|
+
mapper = Xhive::Mapper.map_resource(site, posts_page, 'posts', 'index', post.id)
|
211
211
|
```
|
212
212
|
|
213
213
|
From your posts controller, render the posts page
|
@@ -9,7 +9,7 @@ module Xhive
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def render_page_with(key = nil, options={})
|
12
|
-
page =
|
12
|
+
page = Xhive::Mapper.page_for(current_site, controller_path, action_name, key)
|
13
13
|
render :inline => page.presenter.render_content(options), :layout => true
|
14
14
|
rescue
|
15
15
|
render
|
data/app/models/xhive/mapper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Xhive
|
2
2
|
class Mapper < ActiveRecord::Base
|
3
|
-
attr_accessible :action, :page_id, :site_id, :resource
|
3
|
+
attr_accessible :action, :page_id, :site_id, :resource, :key
|
4
4
|
|
5
5
|
belongs_to :site
|
6
6
|
belongs_to :page
|
@@ -10,12 +10,26 @@ module Xhive
|
|
10
10
|
validates :site, :presence => true
|
11
11
|
validates :page, :presence => true
|
12
12
|
|
13
|
-
def self.page_for(resource, action, key = nil)
|
14
|
-
mapper =
|
15
|
-
|
16
|
-
page = mapper.first.try(:page)
|
13
|
+
def self.page_for(site, resource, action, key = nil)
|
14
|
+
mapper = find_map(site, resource, action, key)
|
15
|
+
page = mapper.try(:page)
|
17
16
|
fail ActiveRecord::RecordNotFound unless page.present?
|
18
17
|
page
|
19
18
|
end
|
19
|
+
|
20
|
+
def self.map_resource(site, page, resource, action, key = nil)
|
21
|
+
mapper = find_map(site, resource, action, key)
|
22
|
+
mapper = new(:site_id => site.id, :resource => resource, :action => action, :key => key) unless mapper.present?
|
23
|
+
mapper.page = page
|
24
|
+
mapper.save
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.find_map(site, resource, action, key)
|
30
|
+
mapper = where(:site_id => site.id).where(:resource => resource).where(:action => action)
|
31
|
+
mapper = mapper.where(:key => key) if key.present?
|
32
|
+
mapper.first
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
data/lib/xhive/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xhive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9.pre
|
5
5
|
prerelease: 6
|
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-11-
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -277,7 +277,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
277
277
|
version: '0'
|
278
278
|
segments:
|
279
279
|
- 0
|
280
|
-
hash: -
|
280
|
+
hash: -1538157182709527364
|
281
281
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
282
282
|
none: false
|
283
283
|
requirements:
|