radiant-predefined_parts-extension 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ = Predefined Parts Extension
2
+
3
+ This extension overrides the default add-part popup to give the user a dropdown list of predefined parts, as well as allow him to add their own.
4
+
5
+ == Installation
6
+
7
+ To install this plugin get the source from github in your `vendor/extensions`. Then run the update `rake` task:
8
+ rake radiant:extensions:predefined_parts:update
9
+
10
+ Which will copy all required files to your public directory.
@@ -0,0 +1,120 @@
1
+ # I think this is the one that should be moved to the extension Rakefile template
2
+
3
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
4
+ # Check to see if the rspec plugin is installed first and require
5
+ # it if it is. If not, use the gem version.
6
+
7
+ # Determine where the RSpec plugin is by loading the boot
8
+ unless defined? RADIANT_ROOT
9
+ ENV["RAILS_ENV"] = "test"
10
+ case
11
+ when ENV["RADIANT_ENV_FILE"]
12
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
13
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
14
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
15
+ else
16
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
17
+ end
18
+ end
19
+
20
+ require 'rake'
21
+ require 'rake/rdoctask'
22
+ require 'rake/testtask'
23
+
24
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
25
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
26
+ require 'spec/rake/spectask'
27
+ # require 'spec/translator'
28
+
29
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
30
+ Object.send(:remove_const, :RADIANT_ROOT)
31
+
32
+ extension_root = File.expand_path(File.dirname(__FILE__))
33
+
34
+ task :default => :spec
35
+ task :stats => "spec:statsetup"
36
+
37
+ desc "Run all specs in spec directory"
38
+ Spec::Rake::SpecTask.new(:spec) do |t|
39
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
40
+ t.spec_files = FileList['spec/**/*_spec.rb']
41
+ end
42
+
43
+ namespace :spec do
44
+ desc "Run all specs in spec directory with RCov"
45
+ Spec::Rake::SpecTask.new(:rcov) do |t|
46
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
47
+ t.spec_files = FileList['spec/**/*_spec.rb']
48
+ t.rcov = true
49
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
50
+ end
51
+
52
+ desc "Print Specdoc for all specs"
53
+ Spec::Rake::SpecTask.new(:doc) do |t|
54
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
55
+ t.spec_files = FileList['spec/**/*_spec.rb']
56
+ end
57
+
58
+ [:models, :controllers, :views, :helpers].each do |sub|
59
+ desc "Run the specs under spec/#{sub}"
60
+ Spec::Rake::SpecTask.new(sub) do |t|
61
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
62
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
63
+ end
64
+ end
65
+
66
+ # Hopefully no one has written their extensions in pre-0.9 style
67
+ # desc "Translate specs from pre-0.9 to 0.9 style"
68
+ # task :translate do
69
+ # translator = ::Spec::Translator.new
70
+ # dir = RAILS_ROOT + '/spec'
71
+ # translator.translate(dir, dir)
72
+ # end
73
+
74
+ # Setup specs for stats
75
+ task :statsetup do
76
+ require 'code_statistics'
77
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
78
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
79
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
80
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
81
+ ::CodeStatistics::TEST_TYPES << "Model specs"
82
+ ::CodeStatistics::TEST_TYPES << "View specs"
83
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
84
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
85
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
86
+ end
87
+
88
+ namespace :db do
89
+ namespace :fixtures do
90
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
91
+ task :load => :environment do
92
+ require 'active_record/fixtures'
93
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
94
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
95
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+
102
+ desc 'Generate documentation for the predefined_parts extension.'
103
+ Rake::RDocTask.new(:rdoc) do |rdoc|
104
+ rdoc.rdoc_dir = 'rdoc'
105
+ rdoc.title = 'PredefinedPartsExtension'
106
+ rdoc.options << '--line-numbers' << '--inline-source'
107
+ rdoc.rdoc_files.include('README')
108
+ rdoc.rdoc_files.include('lib/**/*.rb')
109
+ end
110
+
111
+ # For extensions that are in transition
112
+ desc 'Test the predefined_parts extension.'
113
+ Rake::TestTask.new(:test) do |t|
114
+ t.libs << 'lib'
115
+ t.pattern = 'test/**/*_test.rb'
116
+ t.verbose = true
117
+ end
118
+
119
+ # Load any custom rakefiles for extension
120
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
@@ -0,0 +1,52 @@
1
+ <%
2
+ include_javascript 'admin/controls'
3
+ include_javascript 'admin/combobox'
4
+ %>
5
+
6
+ <% content_for :page_scripts do %>
7
+ document.observe('dom:loaded', function() {
8
+ if (popup = $('add_part_popup')) {
9
+ var predefined_parts = <%= Radiant::Config['predefined_parts.parts'].to_s.inspect %>.split(/\s*,\s*/)
10
+ var field_container = popup.select('p').first();
11
+ field_container.writeAttribute('id', 'parts_field');
12
+ field_container.insert({after: "<div id='parts_results'></div>"})
13
+
14
+ new ComboBox('parts_field', 'parts_results', predefined_parts)
15
+ }
16
+ })
17
+ <% end %>
18
+
19
+ <% content_for :page_css do %>
20
+ #parts_results ul {
21
+ margin: 0;
22
+ padding: 0;
23
+ list-style-type: none;
24
+ border: 1px solid #666;
25
+ }
26
+
27
+ #parts_results li {
28
+ list-style-type: none;
29
+ margin: 0;
30
+ padding: 0 4px;
31
+ background-color: white;
32
+ }
33
+
34
+ * html #parts_results ul {
35
+ position: relative;
36
+ height: 1%;
37
+ }
38
+
39
+
40
+ #parts_results li.selected {
41
+ color: #fff;
42
+ background: #004376;
43
+ }
44
+
45
+ #parts_field input {
46
+ width: 200px;
47
+ }
48
+
49
+ #popups .popup {
50
+ z-index: 5000;
51
+ }
52
+ <% end %>
@@ -0,0 +1,2 @@
1
+ module RadiantPredefinedPartsExtension
2
+ end
@@ -0,0 +1,3 @@
1
+ module RadiantPredefinedPartsExtension
2
+ VERSION = '1.1.0'
3
+ end
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :predefined_parts do
4
+
5
+ desc "Runs the migration of the Predefined Parts extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ PredefinedPartsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ PredefinedPartsExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the Predefined Parts to the instance public/ directory."
16
+ task :update => :environment do
17
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
18
+ puts "Copying assets from PredefinedPartsExtension"
19
+ Dir[PredefinedPartsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
20
+ path = file.sub(PredefinedPartsExtension.root, '')
21
+ directory = File.dirname(path)
22
+ mkdir_p RAILS_ROOT + directory
23
+ cp file, RAILS_ROOT + path
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,13 @@
1
+ require 'radiant-predefined_parts-extension/version'
2
+ class PredefinedPartsExtension < Radiant::Extension
3
+ version RadiantPredefinedPartsExtension::VERSION
4
+ description "Have a list of predefined parts to select from"
5
+ url "http://github.com/jomz/radiant-predefined-parts-extension"
6
+
7
+ def activate
8
+ Radiant::Config['predefined_parts.parts'] ||= 'body, content-sec, video' if Radiant::Config.table_exists?
9
+
10
+ admin.page.edit.add :main, 'predefined_parts_includes', :before => 'edit_header'
11
+ end
12
+
13
+ end
@@ -0,0 +1,97 @@
1
+ var ComboBox = Class.create();
2
+
3
+ ComboBox.Autocompleter = Autocompleter.Local;
4
+
5
+ ComboBox.Autocompleter.prototype.onBlur = function(event) {
6
+ if (Element.getStyle(this.update, 'display') == 'none') { return; }
7
+ setTimeout(this.hide.bind(this), 250);
8
+ this.hasFocus = false;
9
+ this.active = false;
10
+ }
11
+
12
+
13
+ ComboBox.prototype = {
14
+ initialize: function(textElement, resultsElement, array, options) {
15
+ this.textElement = $(textElement);
16
+
17
+ // the first text box inside the container
18
+ this.textBox = $A( this.textElement.getElementsByTagName('INPUT') ).findAll( function(input) {
19
+ return (input.getAttribute('type') == 'text');
20
+ })[0];
21
+
22
+ this.results = $(resultsElement);
23
+ this.textBox.paddingRight = '20px';
24
+ this.textElement.style.width = (this.textBox.offsetWidth) + 'px';
25
+ this.textElement.style.position = 'relative';
26
+
27
+ // we dynamically insert a SPAN that will serve as the drop-down 'arrow'
28
+ this.arrow = new Element('span');
29
+ Object.extend(this.arrow.style, {
30
+ cursor: 'default',
31
+ color: '#000',
32
+ width: '20px',
33
+ position: 'absolute',
34
+ top: '0',
35
+ right: '0px',
36
+ textAlign: 'center',
37
+ fontSize: 'small',
38
+ height: (this.textElement.offsetHeight - 1) + 'px'
39
+ });
40
+
41
+ if (document.all) {
42
+ this.arrow.setStyle({ padding: '2px 0 0 3px', width: '18px', height: '17px'});
43
+
44
+ }
45
+ this.arrow.innerHTML = '<img src="/images/admin/arrow_down.gif" style="margin-top: 9px"/>';
46
+ this.textElement.appendChild(this.arrow);
47
+ this.array = array;
48
+
49
+ this.results.style.display = 'none';
50
+
51
+ this.events = {
52
+ showChoices: this.showChoices.bindAsEventListener(this),
53
+ hideChoices: this.hideChoices.bindAsEventListener(this),
54
+ click: this.click.bindAsEventListener(this),
55
+ keyDown: this.keyDown.bindAsEventListener(this)
56
+ }
57
+
58
+ this.autocompleter = new ComboBox.Autocompleter(this.textBox, this.results, this.array, options);
59
+
60
+ Event.observe(this.arrow, 'click', this.events.click);
61
+ Event.observe(this.textBox, 'keydown', this.events.keyDown);
62
+ },
63
+
64
+ getAllChoices: function(e) {
65
+ var choices = this.array.collect( function(choice) { return '<li>' + choice + '</li>'; } );
66
+ var html = '<ul>' + choices.join('') + '</ul>';
67
+ this.autocompleter.updateChoices(html);
68
+ },
69
+
70
+ keyDown: function(e) {
71
+ if (e.keyCode == Event.KEY_DOWN && this.choicesVisible() ) {
72
+ this.showChoices();
73
+ }
74
+ },
75
+
76
+ // returns boolean indicating whether the choices are displayed
77
+ choicesVisible: function() { return (Element.getStyle(this.autocompleter.update, 'display') == 'none'); },
78
+
79
+ click: function() {
80
+ if (this.choicesVisible() ) {
81
+ this.showChoices();
82
+ } else {
83
+ this.hideChoices();
84
+ }
85
+ },
86
+
87
+ showChoices: function() {
88
+ this.textBox.focus();
89
+ this.autocompleter.changed = false;
90
+ this.autocompleter.hasFocus = true;
91
+ this.getAllChoices();
92
+ },
93
+
94
+ hideChoices: function() {
95
+ this.autocompleter.onBlur();
96
+ }
97
+ }
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "radiant-predefined_parts-extension/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "radiant-predefined_parts-extension"
7
+ s.version = RadiantPredefinedPartsExtension::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benny Degezelle"]
10
+ s.email = ["benny@gorilla-webdesign.be"]
11
+ s.homepage = "http://github.com/jomz/radiant-predefined_parts-extension"
12
+ s.summary = %q{Predefined Parts for Radiant CMS}
13
+ s.description = %q{Suggests a configurable list of page part names when adding a page part}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.post_install_message = %{
21
+ Add this to your radiant project with:
22
+ config.gem 'radiant-predefined_parts-extension', :version => '#{RadiantPredefinedPartsExtension::VERSION}'
23
+ }
24
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-predefined_parts-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Benny Degezelle
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-12 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Suggests a configurable list of page part names when adding a page part
23
+ email:
24
+ - benny@gorilla-webdesign.be
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - README.rdoc
33
+ - Rakefile
34
+ - app/views/admin/pages/_predefined_parts_includes.html.erb
35
+ - lib/radiant-predefined_parts-extension.rb
36
+ - lib/radiant-predefined_parts-extension/version.rb
37
+ - lib/tasks/predefined_parts_extension_tasks.rake
38
+ - predefined_parts_extension.rb
39
+ - public/images/admin/arrow_down.gif
40
+ - public/javascripts/admin/combobox.js
41
+ - radiant-predefined_parts-extension.gemspec
42
+ has_rdoc: true
43
+ homepage: http://github.com/jomz/radiant-predefined_parts-extension
44
+ licenses: []
45
+
46
+ post_install_message: "\n Add this to your radiant project with:\n config.gem 'radiant-predefined_parts-extension', :version => '1.1.0'\n "
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project:
72
+ rubygems_version: 1.3.7
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Predefined Parts for Radiant CMS
76
+ test_files: []
77
+