radiant-clipped_asset_roles-extension 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,12 +22,13 @@ An asset role belongs\_to a page\_attachment, not an asset. On the page edit vie
22
22
 
23
23
  Then, you could use this radius code to select the page_icon e.g. for the current page:
24
24
 
25
- <r:assets:first roles="page_icon"><r:asset:image /></r:assets:first>
25
+ <r:asset:image roles="page_icon" />
26
26
 
27
27
  or do things like:
28
28
 
29
- <ul class="gallery"><r:assets:each roles="portfolio" order="desc" by="position">
29
+ <ul class="gallery"><r:assets:each roles="portfolio|cover" order="desc" by="position">
30
30
  <li><r:asset:image size="thumbnail"/></li>
31
31
  </ul></r:assets:each>
32
32
 
33
- So, r:assets:each, r:assets:first and r:assets:last, r:if\_assets and r:unless_assets all take a 'roles' attribute now.
33
+ So, r:assets:each, r:asset, r:if\_assets and r:unless_assets all take a 'roles' attribute now.
34
+ If more than one role is provided in the context of r:asset, the first matched asset will be returned.
@@ -1,6 +1,8 @@
1
1
  module ClippedAssetRoles::AssetTagExtensions
2
2
  include Radiant::Taggable
3
3
 
4
+ class TagError < StandardError; end
5
+
4
6
  def self.included(base)
5
7
  base.class_eval {
6
8
  alias_method_chain :assets_find_options, :roles
@@ -22,20 +24,6 @@ module ClippedAssetRoles::AssetTagExtensions
22
24
  tag.expand
23
25
  end
24
26
 
25
- desc %{
26
- References the first asset attached to the current page.
27
-
28
- *Usage:*
29
- <pre><code><r:assets:first>...</r:assets:first></code></pre>
30
- }
31
- tag 'assets:first' do |tag|
32
- if role = options.delete('role') && tag.locals.asset = tag.locals.page.attachments_with_role(role).first
33
- tag.expand
34
- elsif tag.locals.asset = tag.locals.page.assets.first
35
- tag.expand
36
- end
37
- end
38
-
39
27
  desc %{
40
28
  Renders the contained elements only if the current contextual page has one or
41
29
  more assets. The @min_count@ attribute specifies the minimum number of required
@@ -51,15 +39,16 @@ module ClippedAssetRoles::AssetTagExtensions
51
39
  end
52
40
 
53
41
  def find_asset_with_roles(tag, options)
54
- begin
55
- find_asset_without_roles
56
- rescue TagError
57
- if role = options.delete('role')
58
- tag.locals.asset = tag.locals.page.attachments_with_role(role).first
59
- else
60
- raise(TagError, "Asset not found.")
42
+ if tag.locals.asset.nil? and roles = options.delete('roles')
43
+ roles.split('|').each do |role|
44
+ tag.locals.asset = tag.locals.page.attachments_with_role(role).first.try(:asset)
45
+ return tag.locals.asset unless tag.locals.asset.nil?
61
46
  end
47
+ raise(TagError, "Asset not found.") unless tag.locals.asset
48
+ else
49
+ find_asset_without_roles(tag, options)
62
50
  end
51
+ tag.locals.asset
63
52
  end
64
53
 
65
54
  def assets_find_options_with_roles(tag)
@@ -73,9 +62,8 @@ module ClippedAssetRoles::AssetTagExtensions
73
62
  options[:conditions] = [ roles.map { |role| "asset_roles.role = ?" }.join(' OR '),
74
63
  *roles.map { |role| role } ]
75
64
  end
76
- # raise options.to_s
65
+
77
66
  options[:joins] = "INNER JOIN `page_attachments` pa ON `assets`.id = pa.asset_id INNER JOIN `asset_roles` ON (`asset_roles`.page_attachment_id = pa.id)"
78
- # options[:joins] = [:page_attachments, :asset_roles]
79
67
  end
80
68
  options
81
69
  end
@@ -1,5 +1,5 @@
1
1
  module RadiantClippedAssetRolesExtension
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  SUMMARY = "Clipped Asset Roles for Radiant CMS"
4
4
  DESCRIPTION = "Adds new scoping levels for assets, e.g. a 'portfolio' role for images."
5
5
  URL = "https://github.com/jomz/radiant-clipped_asset_roles-extension"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiant-clipped_asset_roles-extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: radiant-clipped-extension
@@ -52,6 +52,7 @@ files:
52
52
  - lib/radiant-clipped_asset_roles-extension.rb
53
53
  - lib/tasks/clipped_asset_roles_extension_tasks.rake
54
54
  - public/stylesheets/admin/asset_roles.sass
55
+ - radiant-clipped_asset_roles-extension-1.0.1.gem
55
56
  - radiant-clipped_asset_roles-extension.gemspec
56
57
  - Rakefile
57
58
  - README.md