radiant-page_preview-extension 0.1.1

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,13 @@
1
+ = Page Preview
2
+
3
+ An extension to preview editing a page in it's enclosing layout to give the author an idea of what the output will be like.
4
+
5
+ == Installation
6
+
7
+ git clone git://github.com/tricycle/radiant-page-preview-extension.git vendor/extensions/page_preview
8
+ rake radiant:extensions:page_preview:update
9
+
10
+ == Todo
11
+
12
+ 1. Allow previewing of existing pages when changing page types
13
+
@@ -0,0 +1,136 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ gem.name = "radiant-page_preview-extension"
5
+ gem.summary = %Q{Preview extension for Radiant CMS}
6
+ gem.description = %Q{Enables previewing pages from the edit screen}
7
+ gem.email = "benny@gorilla-webdesign.be"
8
+ gem.homepage = "https://github.com/tricycle/radiant-page-preview-extension"
9
+ gem.authors = ["Adam Sven Johnson", "Glenn Francis Murray", "Kunal Shah", "Matthew Fallshaw"]
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 'spec/translator'
44
+
45
+ # Cleanup the RADIANT_ROOT constant so specs will load the environment
46
+ Object.send(:remove_const, :RADIANT_ROOT)
47
+
48
+ extension_root = File.expand_path(File.dirname(__FILE__))
49
+
50
+ task :default => :spec
51
+ task :stats => "spec:statsetup"
52
+
53
+ desc "Run all specs in spec directory"
54
+ Spec::Rake::SpecTask.new(:spec) do |t|
55
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
56
+ t.spec_files = FileList['spec/**/*_spec.rb']
57
+ end
58
+
59
+ namespace :spec do
60
+ desc "Run all specs in spec directory with RCov"
61
+ Spec::Rake::SpecTask.new(:rcov) do |t|
62
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
63
+ t.spec_files = FileList['spec/**/*_spec.rb']
64
+ t.rcov = true
65
+ t.rcov_opts = ['--exclude', 'spec', '--rails']
66
+ end
67
+
68
+ desc "Print Specdoc for all specs"
69
+ Spec::Rake::SpecTask.new(:doc) do |t|
70
+ t.spec_opts = ["--format", "specdoc", "--dry-run"]
71
+ t.spec_files = FileList['spec/**/*_spec.rb']
72
+ end
73
+
74
+ [:models, :controllers, :views, :helpers].each do |sub|
75
+ desc "Run the specs under spec/#{sub}"
76
+ Spec::Rake::SpecTask.new(sub) do |t|
77
+ t.spec_opts = ['--options', "\"#{extension_root}/spec/spec.opts\""]
78
+ t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
79
+ end
80
+ end
81
+
82
+ # Hopefully no one has written their extensions in pre-0.9 style
83
+ # desc "Translate specs from pre-0.9 to 0.9 style"
84
+ # task :translate do
85
+ # translator = ::Spec::Translator.new
86
+ # dir = RAILS_ROOT + '/spec'
87
+ # translator.translate(dir, dir)
88
+ # end
89
+
90
+ # Setup specs for stats
91
+ task :statsetup do
92
+ require 'code_statistics'
93
+ ::STATS_DIRECTORIES << %w(Model\ specs spec/models)
94
+ ::STATS_DIRECTORIES << %w(View\ specs spec/views)
95
+ ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers)
96
+ ::STATS_DIRECTORIES << %w(Helper\ specs spec/views)
97
+ ::CodeStatistics::TEST_TYPES << "Model specs"
98
+ ::CodeStatistics::TEST_TYPES << "View specs"
99
+ ::CodeStatistics::TEST_TYPES << "Controller specs"
100
+ ::CodeStatistics::TEST_TYPES << "Helper specs"
101
+ ::STATS_DIRECTORIES.delete_if {|a| a[0] =~ /test/}
102
+ end
103
+
104
+ namespace :db do
105
+ namespace :fixtures do
106
+ desc "Load fixtures (from spec/fixtures) into the current environment's database. Load specific fixtures using FIXTURES=x,y"
107
+ task :load => :environment do
108
+ require 'active_record/fixtures'
109
+ ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
110
+ (ENV['FIXTURES'] ? ENV['FIXTURES'].split(/,/) : Dir.glob(File.join(RAILS_ROOT, 'spec', 'fixtures', '*.{yml,csv}'))).each do |fixture_file|
111
+ Fixtures.create_fixtures('spec/fixtures', File.basename(fixture_file, '.*'))
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ desc 'Generate documentation for the page_preview extension.'
119
+ Rake::RDocTask.new(:rdoc) do |rdoc|
120
+ rdoc.rdoc_dir = 'rdoc'
121
+ rdoc.title = 'PagePreviewExtension'
122
+ rdoc.options << '--line-numbers' << '--inline-source'
123
+ rdoc.rdoc_files.include('README')
124
+ rdoc.rdoc_files.include('lib/**/*.rb')
125
+ end
126
+
127
+ # For extensions that are in transition
128
+ desc 'Test the page_preview extension.'
129
+ Rake::TestTask.new(:test) do |t|
130
+ t.libs << 'lib'
131
+ t.pattern = 'test/**/*_test.rb'
132
+ t.verbose = true
133
+ end
134
+
135
+ # Load any custom rakefiles for extension
136
+ Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,39 @@
1
+ class ClassChangedException < Exception; end
2
+
3
+ class PreviewController < ApplicationController
4
+ layout false
5
+ def show
6
+ Page.transaction do # Extra safe don't save anything voodoo
7
+ PagePart.transaction do
8
+ def request.request_method; :get; end
9
+ construct_page.process(request,response)
10
+ @performed_render = true
11
+ raise "Don't you dare save any changes"
12
+ end
13
+ end
14
+ rescue => exception
15
+ render :text => exception.message unless @performed_render
16
+ end
17
+
18
+ private
19
+ def page_class
20
+ classname = params[:page][:class_name].classify
21
+ if Page.descendants.collect(&:name).include?(classname)
22
+ classname.constantize
23
+ else
24
+ Page
25
+ end
26
+ end
27
+
28
+ def construct_page
29
+ if request.referer =~ %r{/admin/pages/(\d+)/edit}
30
+ page = Page.find($1).becomes(page_class)
31
+ page.update_attributes(params[:page])
32
+ else
33
+ page = page_class.new(params[:page])
34
+ page.published_at = page.updated_at = page.created_at = Time.now
35
+ page.parent = Page.find($1) if request.referer =~ %r{/admin/pages/(\d+)/children/new}
36
+ end
37
+ return page
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module PagePreviewHelper
2
+ def save_model_and_continue_editing_button(model)
3
+ super.to_s + submit_tag(I18n.t('page_preview.preview'), :class => 'button', :id => 'show-preview')
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ - include_javascript 'admin/page_preview'
2
+ %iframe{:id => 'page-preview', :name => 'page-preview', :src => '/loading-iframe.html', :frameborder => 0, :style => 'width:100%;height:40em;display:none;border:1px solid black;'}
3
+ You don't support iframes. No preview for you.
@@ -0,0 +1,3 @@
1
+ en:
2
+ page_preview:
3
+ preview: Preview
@@ -0,0 +1,3 @@
1
+ nl:
2
+ page_preview:
3
+ preview: Voorbeeld bekijken
@@ -0,0 +1,3 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ map.connect 'admin/preview', :controller => 'preview', :action => 'show'
3
+ end
@@ -0,0 +1,28 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :page_preview do
4
+
5
+ desc "Runs the migration of the Page Preview extension"
6
+ task :migrate => :environment do
7
+ require 'radiant/extension_migrator'
8
+ if ENV["VERSION"]
9
+ PagePreviewExtension.migrator.migrate(ENV["VERSION"].to_i)
10
+ else
11
+ PagePreviewExtension.migrator.migrate
12
+ end
13
+ end
14
+
15
+ desc "Copies public assets of the Page Preview to the instance public/ directory."
16
+ task :update => :environment do
17
+ is_svn_or_dir = proc {|path| path =~ /\.svn/ || File.directory?(path) }
18
+ Dir[PagePreviewExtension.root + "/public/**/*"].reject(&is_svn_or_dir).each do |file|
19
+ path = file.sub(PagePreviewExtension.root, '')
20
+ directory = File.dirname(path)
21
+ puts "Copying #{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,10 @@
1
+ class PagePreviewExtension < Radiant::Extension
2
+ version "1.1"
3
+ description "Enables previewing pages from the edit screen"
4
+ url "http://github.com/tricycle/raidant-page-preview-extension"
5
+
6
+ def activate
7
+ admin.page.edit.add :form_bottom, 'preview/preview_iframe', :after => 'edit_buttons'
8
+ Admin::PagesController.helper PagePreviewHelper
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ document.observe('dom:loaded', function() {
2
+ $('show-preview').observe('click', function(e) {
3
+ e.preventDefault()
4
+
5
+ var form = this.form,
6
+ oldTarget = form.target,
7
+ oldAction = form.action
8
+
9
+ try {
10
+ var iframe = $('page-preview').show()
11
+ location.hash = this.id
12
+ form.target = iframe.id
13
+ form.action = '/admin/preview'
14
+ form.submit()
15
+ } finally {
16
+ form.target = oldTarget
17
+ form.action = oldAction
18
+ }
19
+ })
20
+ })
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <head>
3
+ <meta http-Equiv="Cache-Control" Content="no-cache">
4
+ <meta http-Equiv="Pragma" Content="no-cache">
5
+ <meta http-Equiv="Expires" Content="0">
6
+ <title>Loading...</title>
7
+ </head>
8
+ <body>
9
+ <p>Loading Preview...</p>
10
+ </body>
11
+ </html>
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ class TestPage < Page
4
+ end
5
+
6
+ describe PreviewController do
7
+ dataset :users, :home_page
8
+ before(:each) do
9
+ controller.stub! :verify_authenticity_token
10
+ login_as :admin
11
+ end
12
+
13
+ describe 'show' do
14
+ it 'should construct the page and process it' do
15
+ controller.should_receive(:construct_page).and_return(mock('page', :process => true))
16
+ post :show
17
+ end
18
+
19
+ # It doesn't make sense to preview a :post, as we can't specify the parameters
20
+ # We're using :post to overcome the :get 65Kb limitation, but still want to
21
+ # Page.process method to think it is a :get action (for logic like request.post?)
22
+ it 'should override the request such that it is a get' do
23
+ post :show
24
+ request.method.should == :get
25
+ end
26
+
27
+ it 'should test that it does not modify page'
28
+ it 'should test that it renders exceptions'
29
+ end
30
+
31
+ describe 'construct page' do
32
+ before(:all) do
33
+ PreviewController.class_eval { public :construct_page }
34
+ Page.find_by_slug("/").parts.clear
35
+ end
36
+ before(:each) do
37
+ part_parameters = HashWithIndifferentAccess.new('1' => {:name=> 'new part'})
38
+ page_parameters = HashWithIndifferentAccess.new(:class_name => 'Page', :parts_attributes => part_parameters)
39
+ query_parameters = HashWithIndifferentAccess.new(:page => page_parameters)
40
+
41
+ controller.stub!(:params).and_return(query_parameters)
42
+ controller.stub!(:request).and_return(request)
43
+ end
44
+ describe 'any page', :shared => true do
45
+ it 'should contain parts created' do
46
+ page = controller.construct_page
47
+
48
+ page.parts.should_not be_empty
49
+ page.parts.first.name.should == 'new part'
50
+ end
51
+ it 'should not retain parts marked for deletion' do
52
+ controller.params[:page][:parts_attributes] = {'1' => {:name=> 'new part', :_delete => true}}
53
+
54
+ controller.construct_page.parts.should be_empty
55
+ end
56
+ end
57
+
58
+ describe 'new child' do
59
+ before do
60
+ Page.stub!(:find).and_return @page
61
+ request.stub!(:referer).and_return('/admin/pages/1/children/new')
62
+ end
63
+ it_should_behave_like "any page"
64
+ it 'should not save any changes' do
65
+ page_count = Page.count
66
+ controller.construct_page
67
+ Page.count.should == page_count
68
+ end
69
+ it 'should get the referrer' do
70
+ request.should_receive(:referer).at_least(:once)
71
+ controller.construct_page
72
+ end
73
+ it 'should retrieve the class_name from the params' do
74
+ controller.params[:page].should_receive(:[]).with(:class_name).and_return 'page'
75
+ controller.construct_page
76
+ end
77
+ it 'should create a new page' do
78
+ controller.params[:page].stub!(:[]).with(:class_name).and_return 'test_page'
79
+ controller.construct_page.class.should == TestPage
80
+ end
81
+ it 'should set get the parent from the referer' do
82
+ request.stub!(:referer).and_return('/admin/pages/100/children/new')
83
+ Page.should_receive(:find).with('100')
84
+ controller.construct_page
85
+ end
86
+ it 'should assign the parent from the referer to the page' do
87
+ parent = mock_model(Page)
88
+ Page.stub!(:find).and_return parent
89
+ controller.construct_page.parent.should == parent
90
+ end
91
+ end
92
+ describe 'edit existing page' do
93
+ before do
94
+ request.stub!(:referer).and_return('/admin/pages/1/edit')
95
+ controller.params[:page][:class_name] = "Page"
96
+ @page = Page.find(:first)
97
+ Page.stub!(:find).and_return @page
98
+ end
99
+ it_should_behave_like "any page"
100
+ it 'should not save any changes' #TODO: Test this somehow
101
+ it 'should have the original pages children' do
102
+ #TODO: Make this text more explicitly test children
103
+ controller.construct_page.children.should == @page.children
104
+ end
105
+ it 'should have the original pages parent' do
106
+ #TODO: Make this text more explicitly test parent
107
+ controller.construct_page.parent.should == @page.parent
108
+ end
109
+ it 'should change page class if it has changed' do
110
+ controller.params[:page][:class_name] = "TestPage"
111
+ controller.construct_page.class.should == TestPage
112
+ end
113
+ it 'should have params attributes, not the existing page attributes' do
114
+ @page.title = 'foo'
115
+ controller.params[:page][:title] = 'bar'
116
+ controller.construct_page.title.should == 'bar'
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,37 @@
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
+ if File.directory?(File.dirname(__FILE__) + "/scenarios")
15
+ Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
16
+ end
17
+ if File.directory?(File.dirname(__FILE__) + "/matchers")
18
+ Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
19
+ end
20
+
21
+ Spec::Runner.configure do |config|
22
+ # config.use_transactional_fixtures = true
23
+ # config.use_instantiated_fixtures = false
24
+ # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
25
+
26
+ # You can declare fixtures for each behaviour like this:
27
+ # describe "...." do
28
+ # fixtures :table_a, :table_b
29
+ #
30
+ # Alternatively, if you prefer to declare them only once, you can
31
+ # do so here, like so ...
32
+ #
33
+ # config.global_fixtures = :table_a, :table_b
34
+ #
35
+ # If you declare global fixtures, be aware that they will be declared
36
+ # for all of your examples, even those that don't use them.
37
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: radiant-page_preview-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
+ - Adam Sven Johnson
14
+ - Glenn Francis Murray
15
+ - Kunal Shah
16
+ - Matthew Fallshaw
17
+ autorequire:
18
+ bindir: bin
19
+ cert_chain: []
20
+
21
+ date: 2011-03-16 00:00:00 +01:00
22
+ default_executable:
23
+ dependencies:
24
+ - !ruby/object:Gem::Dependency
25
+ name: radiant
26
+ prerelease: false
27
+ requirement: &id001 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ hash: 57
33
+ segments:
34
+ - 0
35
+ - 9
36
+ - 1
37
+ version: 0.9.1
38
+ type: :runtime
39
+ version_requirements: *id001
40
+ description: Enables previewing pages from the edit screen
41
+ email: benny@gorilla-webdesign.be
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files:
47
+ - README
48
+ files:
49
+ - README
50
+ - Rakefile
51
+ - VERSION
52
+ - app/controllers/preview_controller.rb
53
+ - app/helpers/page_preview_helper.rb
54
+ - app/views/preview/_preview_iframe.haml
55
+ - config/locales/en.yml
56
+ - config/locales/nl.yml
57
+ - config/routes.rb
58
+ - lib/tasks/page_preview_extension_tasks.rake
59
+ - page_preview_extension.rb
60
+ - public/javascripts/admin/page_preview.js
61
+ - public/loading-iframe.html
62
+ - spec/controllers/preview_controller_spec.rb
63
+ - spec/spec.opts
64
+ - spec/spec_helper.rb
65
+ has_rdoc: true
66
+ homepage: https://github.com/tricycle/radiant-page-preview-extension
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options: []
71
+
72
+ require_paths:
73
+ - lib
74
+ required_ruby_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
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ requirements: []
93
+
94
+ rubyforge_project:
95
+ rubygems_version: 1.3.7
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Preview extension for Radiant CMS
99
+ test_files:
100
+ - spec/controllers/preview_controller_spec.rb
101
+ - spec/spec_helper.rb