radiant-find_by_id_tag-extension 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# Find By Id Tag
|
2
2
|
|
3
|
-
|
3
|
+
This extension allows you to use r:find with an 'id' attribute instead of the usual 'path' attribute. This way the r:find tag will stay intact even if the path of the target page changes.
|
4
|
+
An 'ids' attribute was also added to r:aggregate to use instead of 'paths'.
|
5
|
+
|
6
|
+
Important benefit is that this is also much faster than finding a page by path;
|
7
|
+
|
8
|
+
>> Benchmark.measure { Page.find(2546) }
|
9
|
+
=> 0.000000 0.000000 0.000000 ( 0.003986)
|
10
|
+
|
11
|
+
>> Benchmark.measure { Page.find_by_path('/farm-forestry-model/species/eucalypts/growing-eucalypts-for-timber---videos-and-information/videos/') }
|
12
|
+
=> 0.020000 0.010000 0.030000 ( 0.027044)
|
13
|
+
|
4
14
|
|
5
15
|
Created by Benny Degezelle for nzffa.org.nz
|
@@ -1,28 +1,50 @@
|
|
1
1
|
module FindById::TagExtension
|
2
2
|
include Radiant::Taggable
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
*Usage:*
|
4
|
+
desc %{
|
5
|
+
Inside this tag all page related tags refer to the page found at the @path@ attribute.
|
6
|
+
@path@s may be relative or absolute paths.
|
7
|
+
If an @id@ attribute is passed, the path attribute will be ignored
|
8
|
+
*Usage:*
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
<pre><code><r:find path="value_to_find">...</r:find></code></pre>
|
11
|
+
}
|
12
|
+
tag 'find' do |tag|
|
13
|
+
required_attr(tag,'path','url','id')
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
15
|
+
if id = tag.attr.delete('id')
|
16
|
+
found = Page.find(id.to_i)
|
17
|
+
else
|
18
|
+
path = tag.attr['path'] || tag.attr['url']
|
19
|
+
found = Page.find_by_path(absolute_path_for(tag.locals.page.path, path))
|
20
|
+
end
|
21
|
+
if page_found?(found)
|
22
|
+
tag.locals.page = found
|
23
|
+
tag.expand
|
26
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc %{
|
28
|
+
Aggregates the children of multiple paths using the @paths@ or @ids@ attribute.
|
29
|
+
Useful for combining many different sections/categories into a single
|
30
|
+
feed or listing.
|
31
|
+
|
32
|
+
*Usage*:
|
33
|
+
|
34
|
+
<pre><code><r:aggregate paths="/section1; /section2; /section3"> ... </r:aggregate>
|
35
|
+
<r:aggregate ids="4; 6; 7"> ... </r:aggregate></code></pre>
|
36
|
+
}
|
37
|
+
tag "aggregate" do |tag|
|
38
|
+
required_attr(tag, 'paths', 'urls', 'ids')
|
39
|
+
if ids = tag.attr.delete('ids')
|
40
|
+
tag.locals.parent_ids = ids.split(';').map(&:strip).reject(&:blank?)
|
41
|
+
else
|
42
|
+
paths = (tag.attr['paths']||tag.attr["urls"]).split(";").map(&:strip).reject(&:blank?).map { |u| clean_path u }
|
43
|
+
parent_ids = paths.map {|u| Page.find_by_path(u) }.map(&:id)
|
44
|
+
tag.locals.parent_ids = parent_ids
|
45
|
+
end
|
46
|
+
tag.expand
|
47
|
+
end
|
48
|
+
|
27
49
|
|
28
50
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RadiantFindByIdTagExtension
|
2
|
-
VERSION = "1.
|
2
|
+
VERSION = "1.1.0"
|
3
3
|
SUMMARY = "Find By Id Tag for Radiant CMS"
|
4
|
-
DESCRIPTION = "Adds id attribute to r:find"
|
4
|
+
DESCRIPTION = "Adds support for an 'id' attribute to r:find"
|
5
5
|
URL = "http://github.com/jomz/radiant-find_by_id_tag-extension"
|
6
6
|
AUTHORS = ["Benny Degezelle"]
|
7
7
|
EMAIL = ["hi@monkeypatch.be"]
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: radiant-find_by_id_tag-extension
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: Adds id attribute to r:find
|
14
|
+
description: Adds support for an 'id' attribute to r:find
|
15
15
|
email:
|
16
16
|
- hi@monkeypatch.be
|
17
17
|
executables: []
|
@@ -23,6 +23,7 @@ files:
|
|
23
23
|
- lib/find_by_id/tag_extension.rb
|
24
24
|
- lib/radiant-find_by_id_tag-extension.rb
|
25
25
|
- lib/tasks/find_by_id_tag_extension_tasks.rake
|
26
|
+
- radiant-find_by_id_tag-extension-1.0.0.gem
|
26
27
|
- radiant-find_by_id_tag-extension.gemspec
|
27
28
|
- Rakefile
|
28
29
|
- README.md
|