radiant-locked_page_parts-extension 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,5 @@
1
+ = Locked Page Parts
2
+
3
+ An extension that allows developers to "lock" certain page parts. These parts are disabled for every user who is not a developer.
4
+
5
+ Warning: this is a soft lock, anyone with some Javascript knowledge can reverse the process with Firebug, this is meant as a safety-net for non-tech-savy users.
data/Rakefile ADDED
@@ -0,0 +1,139 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-locked_page_parts-extension"
5
+ gem.summary = %Q{Locked Page Parts extension for Radiant CMS}
6
+ gem.description = %Q{Allows you to hide certain page parts from normal users}
7
+ gem.email = "benny@gorilla-webdesign.be"
8
+ gem.homepage = "https://github.com/jomz/radiant_locked_page_parts"
9
+ gem.authors = ["Benny Degezelle"]
10
+ gem.add_dependency 'radiant', ">=0.9.1"
11
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
12
+ end
13
+ rescue LoadError
14
+ puts "Jeweler (or a dependency) not available. This is only required if you plan to package copy_move as a gem."
15
+ end
16
+
17
+ # I think this is the one that should be moved to the extension Rakefile template
18
+
19
+ # In rails 1.2, plugins aren't available in the path until they're loaded.
20
+ # Check to see if the rspec plugin is installed first and require
21
+ # it if it is. If not, use the gem version.
22
+
23
+ # Determine where the RSpec plugin is by loading the boot
24
+ unless defined? RADIANT_ROOT
25
+ ENV["RAILS_ENV"] = "test"
26
+ case
27
+ when ENV["RADIANT_ENV_FILE"]
28
+ require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
29
+ when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
30
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
31
+ else
32
+ require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
33
+ end
34
+ end
35
+
36
+ require 'rake'
37
+ require 'rake/rdoctask'
38
+ require 'rake/testtask'
39
+
40
+ rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
41
+ $LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
42
+ require 'spec/rake/spectask'
43
+ require 'cucumber'
44
+ require 'cucumber/rake/task'
45
+
46
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
47
+ Object.send(:remove_const, :RADIANT_ROOT)
48
+
49
+ extension_root = File.expand_path(File.dirname(__FILE__))
50
+
51
+ task :default => :spec
52
+ task :stats => "spec:statsetup"
53
+
54
+ desc "Run all specs in spec directory"
55
+ Spec::Rake::SpecTask.new(:spec) do |t|
56
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
57
+ t.spec_files = FileList['spec/**/*_spec.rb']
58
+ end
59
+
60
+ task :features => 'spec:integration'
61
+
62
+ namespace :spec do
63
+ desc "Run all specs in spec directory with RCov"
64
+ Spec::Rake::SpecTask.new(:rcov) do |t|
65
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
66
+ t.spec_files = FileList['spec/**/*_spec.rb']
67
+ t.rcov = true
68
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
69
+ end
70
+
71
+ desc "Print Specdoc for all specs"
72
+ Spec::Rake::SpecTask.new(:doc) do |t|
73
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
74
+ t.spec_files = FileList['spec/**/*_spec.rb']
75
+ end
76
+
77
+ [:models, :controllers, :views, :helpers].each do |sub|
78
+ desc "Run the specs under spec/#{sub}"
79
+ Spec::Rake::SpecTask.new(sub) do |t|
80
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
81
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
82
+ end
83
+ end
84
+
85
+ desc "Run the Cucumber features"
86
+ Cucumber::Rake::Task.new(:integration) do |t|
87
+ t.fork = true
88
+ t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
89
+ # t.feature_pattern = "#{extension_root}/features/**/*.feature"
90
+ t.profile = "default"
91
+ end
92
+
93
+ # Setup specs for stats
94
+ task :statsetup do
95
+ require 'code_statistics'
96
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
97
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
98
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
99
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
100
+ ::CodeStatistics::TEST_TYPES << "Model specs"
101
+ ::CodeStatistics::TEST_TYPES << "View specs"
102
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
103
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
104
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
105
+ end
106
+
107
+ namespace :db do
108
+ namespace :fixtures do
109
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
110
+ task :load => :environment do
111
+ require 'active_record/fixtures'
112
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
113
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
114
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+
121
+ desc 'Generate documentation for the locked_page_parts extension.'
122
+ Rake::RDocTask.new(:rdoc) do |rdoc|
123
+ rdoc.rdoc_dir = 'rdoc'
124
+ rdoc.title = 'LockedPagePartsExtension'
125
+ rdoc.options << '--line-numbers' << '--inline-source'
126
+ rdoc.rdoc_files.include('README')
127
+ rdoc.rdoc_files.include('lib/**/*.rb')
128
+ end
129
+
130
+ # For extensions that are in transition
131
+ desc 'Test the locked_page_parts extension.'
132
+ Rake::TestTask.new(:test) do |t|
133
+ t.libs << 'lib'
134
+ t.pattern = 'test/**/*_test.rb'
135
+ t.verbose = true
136
+ end
137
+
138
+ # Load any custom rakefiles for extension
139
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,5 @@
1
+ - if current_user.admin?
2
+ %span.lock_page_part
3
+ ~ check_box_tag "page[parts_attributes][#{params[:index].to_i}][locked]", '1', page_part.locked?
4
+ %label{:for => "page_parts_attributes_#{params[:index].to_i}_locked"}
5
+ Locked
@@ -0,0 +1,14 @@
1
+ - page_part_counter = @page.parts.index(page_part)
2
+ - if current_user.admin?
3
+ %span.lock_page_part
4
+ ~ check_box_tag "page[parts_attributes][#{page_part_counter}][locked]", '1', page_part.locked?
5
+ %label{:for => "page_parts_attributes_#{page_part_counter}_locked"}
6
+ Locked
7
+ - elsif page_part.locked?
8
+ :javascript
9
+ (function($){
10
+ document.observe('dom:loaded', function() {
11
+ var tab = $('.tab:eq(#{page_part_counter})')
12
+ tab.replaceWith("<span class='tab disabled'>" + tab.text() + "</span>")
13
+ })
14
+ })(jQuery)
@@ -0,0 +1,14 @@
1
+ <% content_for :page_css do %>
2
+ .part{
3
+ position:relative;
4
+ }
5
+ .part .lock_page_part{
6
+ position:absolute;
7
+ right:0;
8
+ top:0;
9
+ }
10
+
11
+ #content #tabs span.tab.disabled {
12
+ background-color: #DDD
13
+ }
14
+ <% end %>
@@ -0,0 +1,9 @@
1
+ class AddLockedToPageParts < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :page_parts, :locked, :boolean
4
+ end
5
+
6
+ def self.down
7
+ remove_column :page_parts, :locked
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module PagePartsControllerExtensions
2
+
3
+ def lock
4
+ current_object.update_attribute(:locked, true)
5
+ redirect_to :back
6
+ end
7
+
8
+ def unlock
9
+ current_object.update_attribute(:locked, false)
10
+ redirect_to :back
11
+ end
12
+
13
+ end
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :locked_page_parts do
4
+
5
+ desc "Runs the migration of the Locked Page Parts extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ LockedPagePartsExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ LockedPagePartsExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the Locked Page 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 LockedPagePartsExtension"
19
+ Dir[LockedPagePartsExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
20
+ path = file.sub(LockedPagePartsExtension.root, '')
21
+ directory = File.dirname(path)
22
+ mkdir_p RAILS_ROOT + directory, :verbose => false
23
+ cp file, RAILS_ROOT + path, :verbose => false
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # Uncomment this if you reference any of your controllers in activate
2
+ # require_dependency 'application_controller'
3
+
4
+ class LockedPagePartsExtension < Radiant::Extension
5
+ version "0.1.1"
6
+ description "Allows you to hide certain page parts from normal users"
7
+ url "https://github.com/jomz/radiant_locked_page_parts"
8
+
9
+ define_routes do |map|
10
+ map.namespace :admin do |admin|
11
+ admin.resources :page_parts, :member => { :lock => :post, :unlock => :post }
12
+ end
13
+ end
14
+
15
+ def activate
16
+ # extend parts controller with lock and unlock methods;
17
+ Admin::PagePartsController.class_eval do
18
+ include PagePartsControllerExtensions
19
+ end
20
+
21
+ admin.page.edit.add :part_controls, 'lock_page_part'
22
+ admin.page.edit.add :main, 'locked_page_style'
23
+ end
24
+
25
+ def deactivate
26
+ # admin.tabs.remove "Locked Page Parts"
27
+ end
28
+
29
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-locked_page_parts-extension
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Benny Degezelle
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-16 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: radiant
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 57
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 1
34
+ version: 0.9.1
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Allows you to hide certain page parts from normal users
38
+ email: benny@gorilla-webdesign.be
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - README
45
+ files:
46
+ - README
47
+ - Rakefile
48
+ - VERSION
49
+ - app/views/admin/page_parts/_lock_page_part.html.haml
50
+ - app/views/admin/pages/_lock_page_part.haml
51
+ - app/views/admin/pages/_locked_page_style.erb
52
+ - db/migrate/20091210124548_add_locked_to_page_parts.rb
53
+ - lib/page_parts_controller_extensions.rb
54
+ - lib/tasks/locked_page_parts_extension_tasks.rake
55
+ - locked_page_parts_extension.rb
56
+ has_rdoc: true
57
+ homepage: https://github.com/jomz/radiant_locked_page_parts
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Locked Page Parts extension for Radiant CMS
90
+ test_files: []
91
+