radiant-relations-extension 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ = Relations
2
+
3
+ Radiant is so freaking awesome, but I made it better through this extension.
4
+
5
+ Created by Jan De Poorter. If I don't update this content with real details,
6
+ please contact me at jan@defv.be with annoying messages telling me to do it.
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 'rake/rdoctask'
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 relations extension.'
100
+ Rake::RDocTask.new(:rdoc) do |rdoc|
101
+ rdoc.rdoc_dir = 'rdoc'
102
+ rdoc.title = 'RelationsExtension'
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,16 @@
1
+ module RelationsHelper
2
+ def relation_options(selected = nil)
3
+ options = []
4
+ options << [t('support.select.prompt'), nil]
5
+ if @page && @page.field('relations_target_parent_id')
6
+ Page.find(@page.field('relations_target_parent_id').content).children.each do |p|
7
+ options << [p.title, p.id]
8
+ end
9
+ else
10
+ Page.all.each do |p|
11
+ options << [p.title, p.id]
12
+ end
13
+ end
14
+ options_for_select(options, selected)
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class RelationPagePart < PagePart
2
+ part_name "Relations"
3
+ before_save :update_related_pages
4
+
5
+ attr_accessor :related_page_ids
6
+
7
+ def related_page_ids=(ids)
8
+ changed_attributes[:related_page_ids] = @related_page_ids
9
+ @related_page_ids = ids
10
+ end
11
+
12
+ private
13
+ def update_related_pages
14
+ page.related_page_ids = related_page_ids.try(:compact)
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ .part.relations
2
+ - @page && @page.related_pages.each do |page|
3
+ .selector-row
4
+ .remove-row
5
+ = select_tag "page[parts_attributes][#{page_part_counter}][related_page_ids][]", relation_options(:selected => page.id)
6
+ .selector-row
7
+ .remove-row
8
+ = select_tag "page[parts_attributes][#{page_part_counter}][related_page_ids][]", relation_options
9
+ %p
10
+ %a{:href=>"#",:class=>'add-row'}
11
+ = t('.add_row')
@@ -0,0 +1,2 @@
1
+ - include_stylesheet 'admin/relations'
2
+ - include_javascript 'admin/relations'
@@ -0,0 +1,3 @@
1
+ Radiant.config do |config|
2
+ # config.define "setting.name", :default => 'value', :select_from => ['foo', 'bar']
3
+ end
@@ -0,0 +1,6 @@
1
+ ---
2
+ en:
3
+ admin:
4
+ page_parts:
5
+ relation_page_part:
6
+ add_row: Add new relation
@@ -0,0 +1,6 @@
1
+ ---
2
+ nl:
3
+ admin:
4
+ page_parts:
5
+ relation_page_part:
6
+ add_row: Relatie toevoegen
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # map.namespace :admin, :member => { :remove => :get } do |admin|
3
+ # admin.resources :relations
4
+ # end
5
+ end
data/cucumber.yml ADDED
@@ -0,0 +1 @@
1
+ default: --format progress features --tags ~@proposed,~@in_progress
@@ -0,0 +1,12 @@
1
+ class AddRelatedPages < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :related_pages, :id => false do |t|
4
+ t.belongs_to :page
5
+ t.belongs_to :related_page
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :related_pages
11
+ end
12
+ 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 :relations
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 "relations" admin page
10
+ #
11
+ # would direct the request to the path you provide in the value:
12
+ #
13
+ # admin_relations_path
14
+ #
15
+ PathMatchers = {} unless defined?(PathMatchers)
16
+ PathMatchers.merge!({
17
+ # /relations/i => 'admin_relations_path'
18
+ })
19
+
20
+ end
21
+
22
+ World(NavigationHelpers)
@@ -0,0 +1,3 @@
1
+ class RadiantRelationsExtension
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ module RelationsExtension::PageExtension
2
+ def self.included(base)
3
+ base.class_eval do
4
+ has_and_belongs_to_many :related_pages,
5
+ :class_name => 'Page',
6
+ :join_table => 'related_pages',
7
+ :foreign_key => 'page_id',
8
+ :association_foreign_key => 'related_page_id',
9
+ :after_add => :add_self_to_related,
10
+ :after_remove => :remove_self_from_related
11
+
12
+ after_create :add_self_to_all_related
13
+ end
14
+ end
15
+
16
+ protected
17
+ def add_self_to_related(related_page)
18
+ related_page.related_pages << self if (!related_page.related_pages.include?(self) && self.valid?)
19
+ end
20
+
21
+ def remove_self_from_related(related_page)
22
+ related_page.related_pages.delete(self) if related_page.related_pages.include?(self)
23
+ end
24
+
25
+ def add_self_to_all_related
26
+ related_pages.each do |rp|
27
+ add_self_to_related rp
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ module RelationsExtension::RelationsTags
2
+ include Radiant::Taggable
3
+
4
+ desc %{
5
+
6
+ }
7
+ tag 'related_pages' do |tag|
8
+ tag.expand
9
+ end
10
+ tag 'related_pages:each' do |tag|
11
+ related_pages = tag.locals.page.related_pages
12
+
13
+ related_pages.inject('') do |result, related_page|
14
+ tag.locals.page = related_page
15
+ result + tag.expand
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,55 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :relations do
4
+
5
+ desc "Runs the migration of the Relations extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ RelationsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ Rake::Task['db:schema:dump'].invoke
11
+ else
12
+ RelationsExtension.migrator.migrate
13
+ Rake::Task['db:schema:dump'].invoke
14
+ end
15
+ end
16
+
17
+ desc "Copies public assets of the Relations 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 RelationsExtension"
21
+ Dir[RelationsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
22
+ path = file.sub(RelationsExtension.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
+ unless RelationsExtension.root.starts_with? RAILS_ROOT # don't need to copy vendored tasks
28
+ puts "Copying rake tasks from RelationsExtension"
29
+ local_tasks_path = File.join(RAILS_ROOT, %w(lib tasks))
30
+ mkdir_p local_tasks_path, :verbose => false
31
+ Dir[File.join RelationsExtension.root, %w(lib tasks *.rake)].each do |file|
32
+ cp file, local_tasks_path, :verbose => false
33
+ end
34
+ end
35
+ end
36
+
37
+ desc "Syncs all available translations for this ext to the English ext master"
38
+ task :sync => :environment do
39
+ # The main translation root, basically where English is kept
40
+ language_root = RelationsExtension.root + "/config/locales"
41
+ words = TranslationSupport.get_translation_keys(language_root)
42
+
43
+ Dir["#{language_root}/*.yml"].each do |filename|
44
+ next if filename.match('_available_tags')
45
+ basename = File.basename(filename, '.yml')
46
+ puts "Syncing #{basename}"
47
+ (comments, other) = TranslationSupport.read_file(filename, basename)
48
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
49
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
50
+ TranslationSupport.write_file(filename, basename, comments, other)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ document.observe('click', function(e) {
2
+ var remove, link;
3
+
4
+ if (remove = e.findElement('.remove-row')) {
5
+ if ($$('.selector-row').length > 1)
6
+ remove.up('.selector-row').remove();
7
+ else
8
+ remove.up('.selector-row').select('select').first().value = '';
9
+ }
10
+
11
+ if (e.findElement('.add-row')) {
12
+ var new_row = $$('.selector-row').last().cloneNode(true);
13
+ $$('.selector-row').last().insert({after: new_row})
14
+
15
+ return false;
16
+ }
17
+ })
@@ -0,0 +1,32 @@
1
+ // Styles for relations
2
+ .relations
3
+ margin-top: 1.5em
4
+ margin-bottom: 1em
5
+ .selector-row
6
+ clear:both
7
+ background: #fff
8
+ overflow: hidden
9
+ padding: 1em
10
+ border: 1px solid #ddd
11
+ margin-top: -1px
12
+
13
+ .remove-row
14
+ float: right
15
+ width: 20px
16
+ height: 20px
17
+ cursor: pointer
18
+ background: #fff url(/images/admin/minus_disabled.png) no-repeat 50% 50%
19
+
20
+ &:hover
21
+ background: #fff url(/images/admin/minus.png) no-repeat 50% 50%
22
+
23
+ select
24
+ float: left
25
+ padding: 3px
26
+
27
+ p
28
+ padding-top: 0.5em
29
+ padding-bottom: 0.5em
30
+
31
+ a
32
+ color: #0066CC !important
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-relations-extension"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-relations-extension"
7
+ s.version = RadiantRelationsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jan De Poorter", "Benny Degezelle"]
10
+ s.email = ["jan@defv.be"]
11
+ s.homepage = "http://github.com/defv/radiant-relations-extension"
12
+ s.summary = %q{Relations for Radiant CMS}
13
+ s.description = %q{Makes Radiant better by adding relations!}
14
+
15
+ ignores = if File.exist?('.gitignore')
16
+ File.read('.gitignore').split("\n").inject([]) {|a,p| a + Dir[p] }
17
+ else
18
+ []
19
+ end
20
+ s.files = Dir['**/*'] - ignores
21
+ s.test_files = Dir['test/**/*','spec/**/*','features/**/*'] - ignores
22
+ # s.executables = Dir['bin/*'] - ignores
23
+ s.require_paths = ["lib"]
24
+
25
+ s.post_install_message = %{
26
+ Add this to your radiant project with:
27
+ config.gem 'radiant-relations-extension', :version => '~>#{RadiantRelationsExtension::VERSION}'
28
+ }
29
+ end
@@ -0,0 +1,26 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application_controller'
3
+ require 'radiant-relations-extension'
4
+
5
+ class RelationsExtension < Radiant::Extension
6
+ version RadiantRelationsExtension::VERSION
7
+ description "Adds relations to Radiant."
8
+ url "http://github.com/defv/radiant-relations-extension"
9
+
10
+ extension_config do |config|
11
+ # config.gem 'radiant-page_parts-extension'
12
+ # config.after_initialize do
13
+ # run_something
14
+ # end
15
+ end
16
+
17
+ # See your config/routes.rb file in this extension to define custom routes
18
+
19
+ def activate
20
+ admin.page.edit.add :main, 'relations_header_load'
21
+
22
+ Page.send(:include, RelationsExtension::PageExtension, RelationsExtension::RelationsTags)
23
+ Admin::PagesController.helper :relations
24
+ Admin::PagePartsController.helper :relations
25
+ end
26
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -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,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-relations-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jan De Poorter
14
+ - Benny Degezelle
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-07-29 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: Makes Radiant better by adding relations!
24
+ email:
25
+ - jan@defv.be
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - app/helpers/relations_helper.rb
34
+ - app/models/relation_page_part.rb
35
+ - app/views/admin/page_parts/_relation_page_part.html.haml
36
+ - app/views/admin/pages/_relations_header_load.html.haml
37
+ - config/initializers/radiant_config.rb
38
+ - config/locales/en.yml
39
+ - config/locales/nl.yml
40
+ - config/routes.rb
41
+ - cucumber.yml
42
+ - db/migrate/20110623112105_add_related_pages.rb
43
+ - features/support/env.rb
44
+ - features/support/paths.rb
45
+ - lib/radiant-relations-extension.rb
46
+ - lib/relations_extension/page_extension.rb
47
+ - lib/relations_extension/relations_tags.rb
48
+ - lib/tasks/relations_extension_tasks.rake
49
+ - public/javascripts/admin/relations.js
50
+ - public/stylesheets/sass/admin/relations.sass
51
+ - radiant-relations-extension-1.0.0.gem
52
+ - radiant-relations-extension.gemspec
53
+ - Rakefile
54
+ - README
55
+ - relations_extension.rb
56
+ - spec/spec.opts
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/defv/radiant-relations-extension
60
+ licenses: []
61
+
62
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-relations-extension', :version => '~>1.0.0'\n "
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.6.2
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Relations for Radiant CMS
92
+ test_files:
93
+ - spec/spec.opts
94
+ - spec/spec_helper.rb
95
+ - features/support/env.rb
96
+ - features/support/paths.rb