radiant-clipped_asset_roles-extension 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +33 -0
- data/Rakefile +109 -0
- data/app/models/asset_role.rb +3 -0
- data/app/views/admin/page_attachments/_attachment.html.haml +36 -0
- data/clipped_asset_roles_extension.rb +22 -0
- data/config/initializers/radiant_config.rb +3 -0
- data/config/locales/en.yml +4 -0
- data/config/locales/nl.yml +4 -0
- data/config/routes.rb +5 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20120623110516_create_asset_roles.rb +18 -0
- data/features/support/env.rb +11 -0
- data/features/support/paths.rb +22 -0
- data/lib/clipped_asset_roles/asset_tag_extensions.rb +84 -0
- data/lib/clipped_asset_roles/page_attachment_extensions.rb +8 -0
- data/lib/clipped_asset_roles/page_extensions.rb +41 -0
- data/lib/clipped_asset_roles/pages_controller_extensions.rb +33 -0
- data/lib/radiant-clipped_asset_roles-extension.rb +8 -0
- data/lib/tasks/clipped_asset_roles_extension_tasks.rake +47 -0
- data/public/stylesheets/admin/asset_roles.sass +4 -0
- data/radiant-clipped_asset_roles-extension.gemspec +29 -0
- data/spec/datasets/asset_roles_dataset.rb +38 -0
- data/spec/models/asset_role_spec.rb +16 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +36 -0
- metadata +93 -0
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Clipped Asset Roles
|
2
|
+
|
3
|
+
Allows you to specify 'asset roles', so you can add meaning to a relation between a page and an asset. For example a page can have 5 images attached, and 4 of those have a role of 'portfolio image'. With radius you can then render just those 4 images into a gallery.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
[Radiant Clipped extension](https://github.com/radiant/radiant-clipped-extension/) is required. This was built against clipped 1.0.16, but I'm quite sure older versions should work as well. I required ~> 1.0.10 but that was actually guesswork.. do let me know if you find clipped versions where this breaks.
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
Set the asset roles for your site in Radiant::Config["clipped\_asset\_roles.roles"] with format "role1:one,role2:many". The default config defines 'page icon' and 'portfolio' roles that you will probably want to replace with your own.
|
12
|
+
|
13
|
+
You can customize the roles available to a certain page by adding a page field 'asset\_roles' or 'children\_asset\_roles' using the same role:association_type format.
|
14
|
+
The latter will overwrite the roles for all direct children of the page on which it is defined.
|
15
|
+
|
16
|
+
Finally, you can define 'extra\_asset\_roles' or 'extra\_children\_asset\_roles' which will add the roles to the ones defined in Radiant::Config.
|
17
|
+
Configuration through a parent page will be overwritten by configuration on the child page if applicable.
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
An asset role belongs\_to a page\_attachment, not an asset. On the page edit view, in the 'image bucket', you can select roles for attached assets.
|
22
|
+
|
23
|
+
Then, you could use this radius code to select the page_icon e.g. for the current page:
|
24
|
+
|
25
|
+
<r:assets:first roles="page_icon"><r:asset:image /></r:assets:first>
|
26
|
+
|
27
|
+
or do things like:
|
28
|
+
|
29
|
+
<ul class="gallery"><r:assets:each roles="portfolio" order="desc" by="position">
|
30
|
+
<li><r:asset:image size="thumbnail"/></li>
|
31
|
+
</ul></r:assets:each>
|
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.
|
data/Rakefile
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Determine where the RSpec plugin is by loading the boot
|
2
|
+
unless defined? RADIANT_ROOT
|
3
|
+
ENV["RAILS_ENV"] = "test"
|
4
|
+
case
|
5
|
+
when ENV["RADIANT_ENV_FILE"]
|
6
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
7
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
8
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
9
|
+
else
|
10
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'rake'
|
15
|
+
require 'rdoc/task'
|
16
|
+
require 'rake/testtask'
|
17
|
+
|
18
|
+
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
19
|
+
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
20
|
+
require 'spec/rake/spectask'
|
21
|
+
require 'cucumber'
|
22
|
+
require 'cucumber/rake/task'
|
23
|
+
|
24
|
+
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
25
|
+
Object.send(:remove_const, :RADIANT_ROOT)
|
26
|
+
|
27
|
+
extension_root = File.expand_path(File.dirname(__FILE__))
|
28
|
+
|
29
|
+
task :default => [:spec, :features]
|
30
|
+
task :stats => "spec:statsetup"
|
31
|
+
|
32
|
+
desc "Run all specs in spec directory"
|
33
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
34
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
35
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
task :features => 'spec:integration'
|
39
|
+
|
40
|
+
namespace :spec do
|
41
|
+
desc "Run all specs in spec directory with RCov"
|
42
|
+
Spec::Rake::SpecTask.new(:rcov) do |t|
|
43
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
44
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
45
|
+
t.rcov = true
|
46
|
+
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Print Specdoc for all specs"
|
50
|
+
Spec::Rake::SpecTask.new(:doc) do |t|
|
51
|
+
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
52
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
[:models, :controllers, :views, :helpers].each do |sub|
|
56
|
+
desc "Run the specs under spec/#{sub}"
|
57
|
+
Spec::Rake::SpecTask.new(sub) do |t|
|
58
|
+
t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
|
59
|
+
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Run the Cucumber features"
|
64
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
65
|
+
t.fork = true
|
66
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
67
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
68
|
+
t.profile = "default"
|
69
|
+
end
|
70
|
+
|
71
|
+
# Setup specs for stats
|
72
|
+
task :statsetup do
|
73
|
+
require 'code_statistics'
|
74
|
+
::STATS_DIRECTORIES << %w(Model\ specs spec/models)
|
75
|
+
::STATS_DIRECTORIES << %w(View\ specs spec/views)
|
76
|
+
::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
|
77
|
+
::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
|
78
|
+
::CodeStatistics::TEST_TYPES << "Model specs"
|
79
|
+
::CodeStatistics::TEST_TYPES << "View specs"
|
80
|
+
::CodeStatistics::TEST_TYPES << "Controller specs"
|
81
|
+
::CodeStatistics::TEST_TYPES << "Helper specs"
|
82
|
+
::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
|
83
|
+
end
|
84
|
+
|
85
|
+
namespace :db do
|
86
|
+
namespace :fixtures do
|
87
|
+
desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
|
88
|
+
task :load => :environment do
|
89
|
+
require 'active_record/fixtures'
|
90
|
+
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
|
91
|
+
(ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
|
92
|
+
Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# desc 'Generate documentation for the clipped_asset_roles extension.'
|
100
|
+
# RDoc:Task.new(:rdoc) do |rdoc|
|
101
|
+
# rdoc.rdoc_dir = 'rdoc'
|
102
|
+
# rdoc.title = 'ClippedAssetRolesExtension'
|
103
|
+
# rdoc.options << '--line-numbers' << '--inline-source'
|
104
|
+
# rdoc.rdoc_files.include('README')
|
105
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
106
|
+
# end
|
107
|
+
|
108
|
+
# Load any custom rakefiles for extension
|
109
|
+
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
@@ -0,0 +1,36 @@
|
|
1
|
+
- include_stylesheet 'admin/asset_roles'
|
2
|
+
- attachment ||= @page_attachment
|
3
|
+
|
4
|
+
- page = attachment.page
|
5
|
+
- asset = attachment.asset
|
6
|
+
- asset_type = asset.image? ? "image" : "link"
|
7
|
+
- css_class = "#{asset_type} asset"
|
8
|
+
- css_class += ' unsaved' if attachment.new_record?
|
9
|
+
|
10
|
+
%li{:class => css_class, :id => "attachment_#{asset.uuid}"}
|
11
|
+
.front
|
12
|
+
.thumbnail= image_tag asset.thumbnail(:thumbnail)
|
13
|
+
.back
|
14
|
+
.title= asset.title
|
15
|
+
%ul.actions
|
16
|
+
%li
|
17
|
+
= asset_insertion_link(asset)
|
18
|
+
%li
|
19
|
+
= link_to t('clipped_extension.detach'), '#', :class => 'detach_asset'
|
20
|
+
- fields_for :page, @page do |f|
|
21
|
+
- f.fields_for :page_attachments, attachment, :child_index => asset.uuid do |paf|
|
22
|
+
- if attachment.new_record?
|
23
|
+
= paf.hidden_field :asset_id, :class => 'attacher'
|
24
|
+
- else
|
25
|
+
= paf.hidden_field :_destroy, :class => 'destroyer'
|
26
|
+
= paf.hidden_field :position, :class => 'pos'
|
27
|
+
%ul.asset_roles{:style => 'margin-top: 120px'}
|
28
|
+
- page.available_roles.each do |role|
|
29
|
+
- name, kind = role.split(':')
|
30
|
+
%li
|
31
|
+
- if kind == 'one'
|
32
|
+
= radio_button_tag "asset_role_#{name}", attachment.id, attachment.asset_roles.select{|r| r.role == name}.any?, :id => "asset_role_#{name}_#{attachment.id}"
|
33
|
+
= label_tag "asset_role_#{name}_#{attachment.id}", name.humanize
|
34
|
+
- else
|
35
|
+
= check_box_tag "asset_role_#{name}[#{attachment.id}]", 1, attachment.asset_roles.select{|r| r.role == name}.any?
|
36
|
+
= label_tag "asset_role_#{name}_#{attachment.id}", name.humanize
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Uncomment this if you reference any of your controllers in activate
|
2
|
+
# require_dependency "application_controller"
|
3
|
+
require "radiant-clipped_asset_roles-extension"
|
4
|
+
|
5
|
+
class ClippedAssetRolesExtension < Radiant::Extension
|
6
|
+
version RadiantClippedAssetRolesExtension::VERSION
|
7
|
+
description RadiantClippedAssetRolesExtension::DESCRIPTION
|
8
|
+
url RadiantClippedAssetRolesExtension::URL
|
9
|
+
|
10
|
+
# See your config/routes.rb file in this extension to define custom routes
|
11
|
+
|
12
|
+
extension_config do |config|
|
13
|
+
# config is the Radiant.configuration object
|
14
|
+
end
|
15
|
+
|
16
|
+
def activate
|
17
|
+
PageAttachment.send :include, ClippedAssetRoles::PageAttachmentExtensions
|
18
|
+
Admin::PagesController.send :include, ClippedAssetRoles::PagesControllerExtensions
|
19
|
+
Page.send :include, ClippedAssetRoles::PageExtensions
|
20
|
+
Page.send :include, ClippedAssetRoles::AssetTagExtensions
|
21
|
+
end
|
22
|
+
end
|
data/config/routes.rb
ADDED
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --format progress features --tags ~@proposed,~@in_progress
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateAssetRoles < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :asset_roles do |t|
|
4
|
+
t.integer :page_attachment_id
|
5
|
+
t.string :role
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :asset_roles, %w{page_attachment_id role}, :name => "attachment_with_role"
|
11
|
+
add_index :asset_roles, 'page_attachment_id', :name => "roles_for_attachment"
|
12
|
+
add_index :asset_roles, 'role', :name => "attachments_with_role"
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :asset_roles
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
# Extension root
|
4
|
+
extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
|
5
|
+
require extension_env+'.rb'
|
6
|
+
|
7
|
+
Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step unless step =~ /datasets_loader\.rb$/}
|
8
|
+
|
9
|
+
Cucumber::Rails::World.class_eval do
|
10
|
+
dataset :clipped_asset_roles
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module NavigationHelpers
|
2
|
+
|
3
|
+
# Extend the standard PathMatchers with your own paths
|
4
|
+
# to be used in your features.
|
5
|
+
#
|
6
|
+
# The keys and values here may be used in your standard web steps
|
7
|
+
# Using:
|
8
|
+
#
|
9
|
+
# When I go to the "clipped_asset_roles" admin page
|
10
|
+
#
|
11
|
+
# would direct the request to the path you provide in the value:
|
12
|
+
#
|
13
|
+
# admin_clipped_asset_roles_path
|
14
|
+
#
|
15
|
+
PathMatchers = {} unless defined?(PathMatchers)
|
16
|
+
PathMatchers.merge!({
|
17
|
+
# /clipped_asset_roles/i => 'admin_clipped_asset_roles_path'
|
18
|
+
})
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
World(NavigationHelpers)
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module ClippedAssetRoles::AssetTagExtensions
|
2
|
+
include Radiant::Taggable
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval {
|
6
|
+
alias_method_chain :assets_find_options, :roles
|
7
|
+
alias_method_chain :find_asset, :roles
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
desc %{
|
12
|
+
Cycles through all assets attached to the current page.
|
13
|
+
This tag does not require the name atttribute, nor do any of its children.
|
14
|
+
Use the @limit@ and @offset@ attribute to render a specific number of assets.
|
15
|
+
Use @by@ and @order@ attributes to control the order of assets.
|
16
|
+
Use @extensions@ and/or @roles@ attribute to specify which assets to be rendered.
|
17
|
+
|
18
|
+
*Usage:*
|
19
|
+
<pre><code><r:assets:each [limit=0] [offset=0] [order="asc|desc"] [by="position|title|..."] [extensions="png|pdf|doc"] [roles="page_icon|portfolio"]>...</r:assets:each></code></pre>
|
20
|
+
}
|
21
|
+
tag 'assets' do |tag|
|
22
|
+
tag.expand
|
23
|
+
end
|
24
|
+
|
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
|
+
desc %{
|
40
|
+
Renders the contained elements only if the current contextual page has one or
|
41
|
+
more assets. The @min_count@ attribute specifies the minimum number of required
|
42
|
+
assets. You can also filter by extensions with the @extensions@ or @roles@ attribute.
|
43
|
+
|
44
|
+
*Usage:*
|
45
|
+
<pre><code><r:if_assets [min_count="n"]>...</r:if_assets></code></pre>
|
46
|
+
}
|
47
|
+
tag 'if_assets' do |tag|
|
48
|
+
count = tag.attr['min_count'] && tag.attr['min_count'].to_i || 1
|
49
|
+
assets = tag.locals.page.assets.count(:conditions => assets_find_options(tag)[:conditions])
|
50
|
+
tag.expand if assets >= count
|
51
|
+
end
|
52
|
+
|
53
|
+
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.")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def assets_find_options_with_roles(tag)
|
66
|
+
options = assets_find_options_without_roles(tag)
|
67
|
+
roles = tag.attr['roles'].to_s.split('|')
|
68
|
+
if roles.any?
|
69
|
+
if options[:conditions]
|
70
|
+
options[:conditions].concat [ roles.map { |role| "asset_roles.role = ?" }.join(' OR '),
|
71
|
+
*roles.map { |role| role } ]
|
72
|
+
else
|
73
|
+
options[:conditions] = [ roles.map { |role| "asset_roles.role = ?" }.join(' OR '),
|
74
|
+
*roles.map { |role| role } ]
|
75
|
+
end
|
76
|
+
# raise options.to_s
|
77
|
+
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
|
+
end
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module ClippedAssetRoles
|
2
|
+
module PageExtensions
|
3
|
+
def attachments_with_role(role)
|
4
|
+
page_attachments.select do |attachment|
|
5
|
+
attachment.asset_roles.select{|asset_role| asset_role.role == role}.any?
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def available_roles
|
10
|
+
return overwritten_roles if overwritten_roles
|
11
|
+
return overwritten_roles_through_parent if overwritten_roles_through_parent
|
12
|
+
return configured_roles.concat(extra_roles) if extra_roles
|
13
|
+
return configured_roles.concat(extra_roles_through_parent) if extra_roles_through_parent
|
14
|
+
configured_roles
|
15
|
+
end
|
16
|
+
|
17
|
+
def configured_roles
|
18
|
+
Radiant::Config['clipped_asset_roles.roles'].to_s.split(',')
|
19
|
+
end
|
20
|
+
|
21
|
+
def extra_roles
|
22
|
+
return false unless config = field(:extra_asset_roles)
|
23
|
+
config.content.to_s.split(',')
|
24
|
+
end
|
25
|
+
|
26
|
+
def overwritten_roles
|
27
|
+
return false unless config = field(:asset_roles)
|
28
|
+
config.content.to_s.split(',')
|
29
|
+
end
|
30
|
+
|
31
|
+
def extra_roles_through_parent
|
32
|
+
return false unless parent && config = parent.field(:extra_children_asset_roles)
|
33
|
+
config.content.to_s.split(',')
|
34
|
+
end
|
35
|
+
|
36
|
+
def overwritten_roles_through_parent
|
37
|
+
return false unless parent && config = parent.field(:children_asset_roles)
|
38
|
+
config.content.to_s.split(',')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ClippedAssetRoles
|
2
|
+
module PagesControllerExtensions
|
3
|
+
|
4
|
+
def self.included(klazz)
|
5
|
+
klazz.class_eval {
|
6
|
+
after_filter :update_asset_roles_from_params, :only => [:create, :update, :destroy]
|
7
|
+
}
|
8
|
+
end
|
9
|
+
# alias_method_chain :create, :asset_roles
|
10
|
+
# alias_method_chain :update, :asset_roles
|
11
|
+
# alias_method_chain :destroy, :asset_roles
|
12
|
+
|
13
|
+
def update_asset_roles_from_params
|
14
|
+
params.select{|k,v| k =~ /asset_role_/}.each do |k,v|
|
15
|
+
role_name = k[/asset_role_(.*)/, 1]
|
16
|
+
|
17
|
+
@page.attachments_with_role(role_name).each do |att|
|
18
|
+
att.asset_roles.select{|r| r.role == role_name}.first.destroy
|
19
|
+
end
|
20
|
+
|
21
|
+
if v.class != String
|
22
|
+
v.each do |asset_id, on|
|
23
|
+
AssetRole.create(:page_attachment_id => asset_id, :role => role_name)
|
24
|
+
end
|
25
|
+
else
|
26
|
+
AssetRole.create(:page_attachment_id => v, :role => role_name)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module RadiantClippedAssetRolesExtension
|
2
|
+
VERSION = "1.0.0"
|
3
|
+
SUMMARY = "Clipped Asset Roles for Radiant CMS"
|
4
|
+
DESCRIPTION = "Adds new scoping levels for assets, e.g. a 'portfolio' role for images."
|
5
|
+
URL = "https://github.com/jomz/radiant-clipped_asset_roles-extension"
|
6
|
+
AUTHORS = ["Benny Degezelle"]
|
7
|
+
EMAIL = ["benny@gorilla-webdesign.be"]
|
8
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
namespace :radiant do
|
2
|
+
namespace :extensions do
|
3
|
+
namespace :clipped_asset_roles do
|
4
|
+
|
5
|
+
desc "Runs the migration of the Clipped Asset Roles extension"
|
6
|
+
task :migrate => :environment do
|
7
|
+
require 'radiant/extension_migrator'
|
8
|
+
if ENV["VERSION"]
|
9
|
+
ClippedAssetRolesExtension.migrator.migrate(ENV["VERSION"].to_i)
|
10
|
+
Rake::Task['db:schema:dump'].invoke
|
11
|
+
else
|
12
|
+
ClippedAssetRolesExtension.migrator.migrate
|
13
|
+
Rake::Task['db:schema:dump'].invoke
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "Copies public assets of the Clipped Asset Roles to the instance public/ directory."
|
18
|
+
task :update => :environment do
|
19
|
+
is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
|
20
|
+
puts "Copying assets from ClippedAssetRolesExtension"
|
21
|
+
Dir[ClippedAssetRolesExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
|
22
|
+
path = file.sub(ClippedAssetRolesExtension.root, '')
|
23
|
+
directory = File.dirname(path)
|
24
|
+
mkdir_p RAILS_ROOT + directory, :verbose => false
|
25
|
+
cp file, RAILS_ROOT + path, :verbose => false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Syncs all available translations for this ext to the English ext master"
|
30
|
+
task :sync => :environment do
|
31
|
+
# The main translation root, basically where English is kept
|
32
|
+
language_root = ClippedAssetRolesExtension.root + "/config/locales"
|
33
|
+
words = TranslationSupport.get_translation_keys(language_root)
|
34
|
+
|
35
|
+
Dir["#{language_root}/*.yml"].each do |filename|
|
36
|
+
next if filename.match('_available_tags')
|
37
|
+
basename = File.basename(filename, '.yml')
|
38
|
+
puts "Syncing #{basename}"
|
39
|
+
(comments, other) = TranslationSupport.read_file(filename, basename)
|
40
|
+
words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
|
41
|
+
other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
|
42
|
+
TranslationSupport.write_file(filename, basename, comments, other)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "radiant-clipped_asset_roles-extension"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "radiant-clipped_asset_roles-extension"
|
7
|
+
s.version = RadiantClippedAssetRolesExtension::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = RadiantClippedAssetRolesExtension::AUTHORS
|
10
|
+
s.email = RadiantClippedAssetRolesExtension::EMAIL
|
11
|
+
s.homepage = RadiantClippedAssetRolesExtension::URL
|
12
|
+
s.summary = RadiantClippedAssetRolesExtension::SUMMARY
|
13
|
+
s.description = RadiantClippedAssetRolesExtension::DESCRIPTION
|
14
|
+
|
15
|
+
# Define gem dependencies here.
|
16
|
+
# Don't include a dependency on radiant itself: it causes problems when radiant is in vendor/radiant.
|
17
|
+
# s.add_dependency "something", "~> 1.0.0"
|
18
|
+
s.add_dependency "radiant-clipped-extension", "~> 1.0.16"
|
19
|
+
|
20
|
+
ignores = if File.exist?('.gitignore')
|
21
|
+
File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
|
22
|
+
else
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
s.files = Dir['**/*'] - ignores
|
26
|
+
s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
|
27
|
+
# s.executables = Dir['bin/*'] - ignores
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class AssetRolesDataset < Dataset::Base
|
2
|
+
uses :assets
|
3
|
+
|
4
|
+
def load
|
5
|
+
create_page "pictured", :slug => 'pictured' do
|
6
|
+
create_asset "test1", :caption => "testing", :position => 1
|
7
|
+
create_asset "test2", :caption => "also testing", :position => 2
|
8
|
+
end
|
9
|
+
create_record :asset_role, :test1_role, {
|
10
|
+
:page_attachment_id => page_attachment_id(:pictured_attachment),
|
11
|
+
:asset_role => 'portfolio'
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# helpers do
|
17
|
+
# def create_asset(name, attributes={})
|
18
|
+
# pos = attributes.delete(:position)
|
19
|
+
# create_record :asset, name.symbolize, {
|
20
|
+
# :title => name,
|
21
|
+
# :asset_file_name => 'asset.jpg',
|
22
|
+
# :asset_content_type => 'image/jpeg',
|
23
|
+
# :asset_file_size => '46248',
|
24
|
+
# :original_height => 200,
|
25
|
+
# :original_width => 400,
|
26
|
+
# :uuid => UUIDTools::UUID.timestamp_create.to_s
|
27
|
+
# }.merge(attributes)
|
28
|
+
# if @current_page_id
|
29
|
+
# create_record :page_attachment, "#{name}_attachment".symbolize, {
|
30
|
+
# :page_id => @current_page_id,
|
31
|
+
# :asset_id => asset_id(name.symbolize),
|
32
|
+
# :position => pos
|
33
|
+
# }
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe AssetRole do
|
4
|
+
dataset :pages, :assets, :asset_roles
|
5
|
+
|
6
|
+
let(:page) { pages(:pictured) }
|
7
|
+
let(:asset) { assets(:test1) }
|
8
|
+
|
9
|
+
context "rendering assets tags with roles attribute" do
|
10
|
+
it "assets:each roles='portfolio'" do
|
11
|
+
page.should render('<r:assets:each role="portfolio"><r:asset:id />,</r:assets:each>').as( "#{asset_id(:test1)}}," )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
unless defined? RADIANT_ROOT
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
case
|
4
|
+
when ENV["RADIANT_ENV_FILE"]
|
5
|
+
require ENV["RADIANT_ENV_FILE"]
|
6
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
7
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
|
8
|
+
else
|
9
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
require "#{RADIANT_ROOT}/spec/spec_helper"
|
13
|
+
|
14
|
+
Dataset::Resolver.default << (File.dirname(__FILE__) + "/datasets")
|
15
|
+
|
16
|
+
if File.directory?(File.dirname(__FILE__) + "/matchers")
|
17
|
+
Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
|
18
|
+
end
|
19
|
+
|
20
|
+
Spec::Runner.configure do |config|
|
21
|
+
# config.use_transactional_fixtures = true
|
22
|
+
# config.use_instantiated_fixtures = false
|
23
|
+
# config.fixture_path = RAILS_ROOT + '/spec/fixtures'
|
24
|
+
|
25
|
+
# You can declare fixtures for each behaviour like this:
|
26
|
+
# describe "...." do
|
27
|
+
# fixtures :table_a, :table_b
|
28
|
+
#
|
29
|
+
# Alternatively, if you prefer to declare them only once, you can
|
30
|
+
# do so here, like so ...
|
31
|
+
#
|
32
|
+
# config.global_fixtures = :table_a, :table_b
|
33
|
+
#
|
34
|
+
# If you declare global fixtures, be aware that they will be declared
|
35
|
+
# for all of your examples, even those that don't use them.
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: radiant-clipped_asset_roles-extension
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benny Degezelle
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: radiant-clipped-extension
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.16
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.16
|
30
|
+
description: Adds new scoping levels for assets, e.g. a 'portfolio' role for images.
|
31
|
+
email:
|
32
|
+
- benny@gorilla-webdesign.be
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- app/models/asset_role.rb
|
38
|
+
- app/views/admin/page_attachments/_attachment.html.haml
|
39
|
+
- clipped_asset_roles_extension.rb
|
40
|
+
- config/initializers/radiant_config.rb
|
41
|
+
- config/locales/en.yml
|
42
|
+
- config/locales/nl.yml
|
43
|
+
- config/routes.rb
|
44
|
+
- cucumber.yml
|
45
|
+
- db/migrate/20120623110516_create_asset_roles.rb
|
46
|
+
- features/support/env.rb
|
47
|
+
- features/support/paths.rb
|
48
|
+
- lib/clipped_asset_roles/asset_tag_extensions.rb
|
49
|
+
- lib/clipped_asset_roles/page_attachment_extensions.rb
|
50
|
+
- lib/clipped_asset_roles/page_extensions.rb
|
51
|
+
- lib/clipped_asset_roles/pages_controller_extensions.rb
|
52
|
+
- lib/radiant-clipped_asset_roles-extension.rb
|
53
|
+
- lib/tasks/clipped_asset_roles_extension_tasks.rake
|
54
|
+
- public/stylesheets/admin/asset_roles.sass
|
55
|
+
- radiant-clipped_asset_roles-extension-1.0.0.gem
|
56
|
+
- radiant-clipped_asset_roles-extension.gemspec
|
57
|
+
- Rakefile
|
58
|
+
- README.md
|
59
|
+
- spec/datasets/asset_roles_dataset.rb
|
60
|
+
- spec/models/asset_role_spec.rb
|
61
|
+
- spec/spec.opts
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
homepage: https://github.com/jomz/radiant-clipped_asset_roles-extension
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.26
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: Clipped Asset Roles for Radiant CMS
|
87
|
+
test_files:
|
88
|
+
- spec/datasets/asset_roles_dataset.rb
|
89
|
+
- spec/models/asset_role_spec.rb
|
90
|
+
- spec/spec.opts
|
91
|
+
- spec/spec_helper.rb
|
92
|
+
- features/support/env.rb
|
93
|
+
- features/support/paths.rb
|