xhive 1.6.2 → 1.6.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +40 -0
- data/app/presenters/xhive/page_presenter.rb +5 -1
- data/app/views/xhive/pages/show.html.erb +1 -1
- data/lib/xhive.rb +7 -5
- data/lib/xhive/active_record_extensions.rb +37 -0
- data/lib/xhive/engine.rb +1 -0
- data/lib/xhive/version.rb +1 -1
- metadata +5 -4
data/README.md
CHANGED
@@ -268,6 +268,46 @@ end
|
|
268
268
|
|
269
269
|
Using this feature you can let the designers implement the HTML/CSS to display the posts in your site without your intervention.
|
270
270
|
|
271
|
+
## Page mounting
|
272
|
+
|
273
|
+
You can also add pages to your ActiveRecord model using the *mount_page* statement:
|
274
|
+
|
275
|
+
```ruby
|
276
|
+
class Post < ActiveRecord::Base
|
277
|
+
mount_page :mini
|
278
|
+
mount_page :full
|
279
|
+
end
|
280
|
+
|
281
|
+
mini_page = Xhive::Page.create(:name => 'mini-post', :title => 'Minimized Post', :content => "<a href='/posts/{{post.id}}'>{{post.title}}</a>")
|
282
|
+
full_page = Xhive::Page.create(:name => 'post', :title => 'Post', :content => "<h1>{{post.title}}</h1><p>{{post.body}}</p>")
|
283
|
+
|
284
|
+
post = Post.create(:title => "My awesome post", :body => "This is an awesome post!")
|
285
|
+
post.mini = mini_page
|
286
|
+
post.full = full_page
|
287
|
+
```
|
288
|
+
|
289
|
+
Then you can display the pages in a view:
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
<% # Render minimized content %>
|
293
|
+
<%= post.mini_page_content %>
|
294
|
+
|
295
|
+
<% # Render full content %>
|
296
|
+
<%= post.full_page_content %>
|
297
|
+
```
|
298
|
+
|
299
|
+
You get:
|
300
|
+
|
301
|
+
```html
|
302
|
+
<a href='/posts/1'>My awesome post</a>
|
303
|
+
|
304
|
+
<h1>My awesome post</h1><p>This is an awesome post!</p>
|
305
|
+
```
|
306
|
+
|
307
|
+
The post object gets injected into the page render method so you can use all its attributes inside the page.
|
308
|
+
|
309
|
+
Caveat: the mount_page statement currently supports single-site use. Multi-site support is intented to be added in the near future.
|
310
|
+
|
271
311
|
## Policy based mapping
|
272
312
|
|
273
313
|
If you need more customization in the page mapping process, you can pass a policy class name as the last attribute.
|
@@ -46,7 +46,11 @@ module Xhive
|
|
46
46
|
def filter_images_urls(content)
|
47
47
|
images_path = base_images_path
|
48
48
|
# This only works if string is interpolated o_O
|
49
|
-
"#{content}".gsub(/src\=['"]?#{images_path}\/([^\'^\"]+)['"]?/) {|| "src='#{
|
49
|
+
"#{content}".gsub(/src\=['"]?#{images_path}\/([^\'^\"]+)['"]?/) {|| "src='#{image_url($1)}'"}
|
50
|
+
end
|
51
|
+
|
52
|
+
def image_url(image)
|
53
|
+
url_for('image', image).gsub(/http:|https:/,'')
|
50
54
|
end
|
51
55
|
|
52
56
|
def log_error(e)
|
@@ -1,2 +1,2 @@
|
|
1
|
-
<%= @page.presenter.render_content %>
|
1
|
+
<%= @page.presenter.render_content.html_safe %>
|
2
2
|
|
data/lib/xhive.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
require "xhive/engine"
|
2
|
-
|
3
|
-
module Xhive
|
4
|
-
end
|
5
|
-
|
6
1
|
require 'xhive/hashy'
|
7
2
|
require 'xhive/liquid_wrapper'
|
8
3
|
require 'xhive/mailer'
|
@@ -12,3 +7,10 @@ require 'xhive/router'
|
|
12
7
|
require 'xhive/base_tag'
|
13
8
|
require 'xhive/tag_factory'
|
14
9
|
require 'xhive/widgify'
|
10
|
+
require 'xhive/active_record_extensions'
|
11
|
+
|
12
|
+
require "xhive/engine"
|
13
|
+
|
14
|
+
module Xhive
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Xhive
|
2
|
+
module ActiveRecordExtensions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def mount_page(attr)
|
7
|
+
# Define getter
|
8
|
+
define_method(attr.to_s) do
|
9
|
+
# TODO: support multiple sites
|
10
|
+
site = Xhive::Site.first
|
11
|
+
begin
|
12
|
+
page = Xhive::Mapper.page_for(site, self.class.name.downcase, attr.to_s, id)
|
13
|
+
rescue ActiveRecord::RecordNotFound
|
14
|
+
page = nil
|
15
|
+
end
|
16
|
+
return page
|
17
|
+
end
|
18
|
+
|
19
|
+
# Define setter
|
20
|
+
define_method("#{attr}=") do |value|
|
21
|
+
fail RecordNotPersistedError, "Cannot assign a page to an unsaved #{self.class.name}" if new_record?
|
22
|
+
# TODO: support multiple sites
|
23
|
+
site = Xhive::Site.first
|
24
|
+
page = value.is_a?(Xhive::Page) ? value : site.pages.find(value)
|
25
|
+
Xhive::Mapper.map_resource(site, page, self.class.name.downcase, attr.to_s, id)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Define content
|
29
|
+
define_method("#{attr}_content") do
|
30
|
+
self.send(attr.to_sym).present_content(self.class.name.downcase.to_sym => self)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class RecordNotPersistedError < StandardError; end
|
36
|
+
end
|
37
|
+
end
|
data/lib/xhive/engine.rb
CHANGED
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.6.
|
4
|
+
version: 1.6.4
|
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:
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- db/migrate/20121101124925_create_xhive_images.rb
|
251
251
|
- db/migrate/20121127230527_add_policy_to_xhive_mappers.rb
|
252
252
|
- lib/tasks/xhive_tasks.rake
|
253
|
+
- lib/xhive/active_record_extensions.rb
|
253
254
|
- lib/xhive/base_tag.rb
|
254
255
|
- lib/xhive/controller.rb
|
255
256
|
- lib/xhive/engine.rb
|
@@ -284,7 +285,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
284
285
|
version: '0'
|
285
286
|
segments:
|
286
287
|
- 0
|
287
|
-
hash:
|
288
|
+
hash: -803175819629715449
|
288
289
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
289
290
|
none: false
|
290
291
|
requirements:
|
@@ -293,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
293
294
|
version: '0'
|
294
295
|
segments:
|
295
296
|
- 0
|
296
|
-
hash:
|
297
|
+
hash: -803175819629715449
|
297
298
|
requirements: []
|
298
299
|
rubyforge_project:
|
299
300
|
rubygems_version: 1.8.21
|