radiant-layouts-extension 0.9.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.
@@ -0,0 +1,21 @@
1
+ module ShareLayouts::RadiantLayouts
2
+
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def radiant_layout(name=nil, options={}, &block)
9
+ raise ArgumentError, "A layout name or block is required!" unless name || block
10
+ write_inheritable_attribute 'radiant_layout', name || block
11
+ before_filter :set_radiant_layout
12
+ layout 'radiant', options
13
+ end
14
+ end
15
+
16
+ def set_radiant_layout
17
+ @radiant_layout = self.class.read_inheritable_attribute 'radiant_layout'
18
+ @radiant_layout = @radiant_layout.call(self) if @radiant_layout.is_a? Proc
19
+ end
20
+
21
+ end
@@ -0,0 +1,34 @@
1
+ namespace :radiant do
2
+ namespace :extensions do
3
+ namespace :layouts do
4
+
5
+ desc "Runs the migration of the Shop Products extension and its dependancies"
6
+ task :migrate => :environment do
7
+ puts "radiant:layouts:migrate - Nohing to do"
8
+ end
9
+
10
+ desc "Copies public assets of the Shop Products to the instance public/ directory."
11
+ task :update => :environment do
12
+ puts "radiant:layouts:update - Nohing to do"
13
+ end
14
+
15
+ desc "Syncs all available translations for this ext to the English ext master"
16
+ task :sync => :environment do
17
+ # The main translation root, basically where English is kept
18
+ language_root = LayoutsExtension.root + "/config/locales"
19
+ words = TranslationSupport.get_translation_keys(language_root)
20
+
21
+ Dir["#{language_root}/*.yml"].each do |filename|
22
+ next if filename.match('_available_tags')
23
+ basename = File.basename(filename, '.yml')
24
+ puts "Syncing #{basename}"
25
+ (comments, other) = TranslationSupport.read_file(filename, basename)
26
+ words.each { |k,v| other[k] ||= words[k] } # Initializing hash variable as empty if it does not exist
27
+ other.delete_if { |k,v| !words[k] } # Remove if not defined in en.yml
28
+ TranslationSupport.write_file(filename, basename, comments, other)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,94 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{radiant-layouts-extension}
8
+ s.version = "0.9.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dirk Kelly"]
12
+ s.date = %q{2010-08-30}
13
+ s.description = %q{Provides extensions to standard layouts, including nesting of layouts within each other and sharing radiant layouts with rails controllers}
14
+ s.email = %q{dk@squaretalent.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "app/models/rails_page.rb",
25
+ "app/views/layouts/radiant.html.haml",
26
+ "layouts_extension.rb",
27
+ "lib/nested_layouts.rb",
28
+ "lib/nested_layouts/tags.rb",
29
+ "lib/share_layouts.rb",
30
+ "lib/share_layouts/helper.rb",
31
+ "lib/share_layouts/radiant_layouts.rb",
32
+ "lib/tasks/layouts_extension_tasks.rake",
33
+ "radiant-layouts-extension.gemspec",
34
+ "spec/controllers/nested_layouts_spec.rb",
35
+ "spec/controllers/share_layouts_spec.rb",
36
+ "spec/datasets/nested_layouts_dataset.rb",
37
+ "spec/datasets/share_layouts_dataset.rb",
38
+ "spec/helpers/share_layouts_helper_spec.rb",
39
+ "spec/lib/nested_layouts/tags_spec.rb",
40
+ "spec/lib/share_layouts_extension_spec.rb",
41
+ "spec/models/rails_page_spec.rb",
42
+ "spec/rcov.opts",
43
+ "spec/spec.opts",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/squaretalent/radiant-layouts-extension}
47
+ s.rdoc_options = ["--charset=UTF-8"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = %q{1.3.7}
50
+ s.summary = %q{Provides extensions to standard layouts, including nesting and sharing}
51
+ s.test_files = [
52
+ "spec/controllers/nested_layouts_spec.rb",
53
+ "spec/controllers/share_layouts_spec.rb",
54
+ "spec/datasets/nested_layouts_dataset.rb",
55
+ "spec/datasets/share_layouts_dataset.rb",
56
+ "spec/helpers/share_layouts_helper_spec.rb",
57
+ "spec/lib/nested_layouts/tags_spec.rb",
58
+ "spec/lib/share_layouts_extension_spec.rb",
59
+ "spec/models/rails_page_spec.rb",
60
+ "spec/spec_helper.rb"
61
+ ]
62
+
63
+ if s.respond_to? :specification_version then
64
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
65
+ s.specification_version = 3
66
+
67
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
68
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
69
+ s.add_development_dependency(%q<rspec-rails>, [">= 1.3.2"])
70
+ s.add_development_dependency(%q<cucumber>, [">= 0.8.5"])
71
+ s.add_development_dependency(%q<cucumber-rails>, [">= 0.3.2"])
72
+ s.add_development_dependency(%q<database_cleaner>, [">= 0.4.3"])
73
+ s.add_development_dependency(%q<ruby-debug>, [">= 0.10.3"])
74
+ s.add_development_dependency(%q<webrat>, [">= 0.10.3"])
75
+ else
76
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
77
+ s.add_dependency(%q<rspec-rails>, [">= 1.3.2"])
78
+ s.add_dependency(%q<cucumber>, [">= 0.8.5"])
79
+ s.add_dependency(%q<cucumber-rails>, [">= 0.3.2"])
80
+ s.add_dependency(%q<database_cleaner>, [">= 0.4.3"])
81
+ s.add_dependency(%q<ruby-debug>, [">= 0.10.3"])
82
+ s.add_dependency(%q<webrat>, [">= 0.10.3"])
83
+ end
84
+ else
85
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
86
+ s.add_dependency(%q<rspec-rails>, [">= 1.3.2"])
87
+ s.add_dependency(%q<cucumber>, [">= 0.8.5"])
88
+ s.add_dependency(%q<cucumber-rails>, [">= 0.3.2"])
89
+ s.add_dependency(%q<database_cleaner>, [">= 0.4.3"])
90
+ s.add_dependency(%q<ruby-debug>, [">= 0.10.3"])
91
+ s.add_dependency(%q<webrat>, [">= 0.10.3"])
92
+ end
93
+ end
94
+
@@ -0,0 +1,45 @@
1
+ require 'spec/spec_helper'
2
+
3
+ class ControllerWithRadiantLayout < ApplicationController
4
+ radiant_layout 'main'
5
+ end
6
+
7
+ class ControllerWithRadiantLayoutBlock < ApplicationController
8
+ radiant_layout {|c| c.action_name == "index" ? "main" : "utf8"}
9
+ end
10
+
11
+ describe ControllerWithRadiantLayout do
12
+ dataset :layouts
13
+
14
+ before(:each) do
15
+ #layouts(:radiant)
16
+ layouts(:main)
17
+ end
18
+
19
+ it "should have radiant layout attribute" do
20
+ ControllerWithRadiantLayout.read_inheritable_attribute('radiant_layout').should == 'main'
21
+ # This doesn't seem to work anymore, but calling "active_layout" on an instance still correctly returns "layouts/radiant.rhtml"
22
+ #ControllerWithRadiantLayout.read_inheritable_attribute('layout').should == 'radiant'
23
+ end
24
+
25
+ it "should return 'radiant' when read_inheritable_attribute('layout') is called"
26
+
27
+ end
28
+
29
+ describe ControllerWithRadiantLayoutBlock do
30
+ dataset :layouts
31
+
32
+ before(:each) do
33
+ layouts(:main)
34
+ end
35
+
36
+ it "should have radiant layout block" do
37
+ ControllerWithRadiantLayoutBlock.read_inheritable_attribute('radiant_layout').should be_kind_of(Proc)
38
+ # This doesn't seem to work anymore, but calling "active_layout" on an instance still correctly returns "layouts/radiant.rhtml"
39
+ #ControllerWithRadiantLayoutBlock.read_inheritable_attribute('layout').should == 'radiant'
40
+ end
41
+
42
+ it "should return 'radiant' when read_inheritable_attribute('layout') is called"
43
+
44
+ end
45
+
@@ -0,0 +1,119 @@
1
+ require 'spec/spec_helper'
2
+
3
+ module TestShareLayoutsTags
4
+ include Radiant::Taggable
5
+
6
+ desc 'some tag'
7
+ tag 'test_has_request' do |tag|
8
+ tag.locals.page.request.class
9
+ end
10
+
11
+ desc 'some tag'
12
+ tag 'test_has_response' do |tag|
13
+ tag.locals.page.response.class
14
+ end
15
+
16
+ end
17
+
18
+ Page.send(:include, TestShareLayoutsTags)
19
+
20
+ class ShareController < ApplicationController
21
+ radiant_layout 'Default'
22
+
23
+ no_login_required
24
+
25
+ def normal_erb_in_radiant_layout
26
+ @name = 'Chester McTester'
27
+ render :inline => 'Hello there, <%= @name %>', :layout => true
28
+ end
29
+
30
+ def normal_erb_with_no_layout
31
+ @name = 'Chester McTester'
32
+ render :inline => 'Hello there, <%= @name %>', :layout => false
33
+ end
34
+
35
+ def normal_erb_with_different_radiant_layout
36
+ @radiant_layout = 'Different'
37
+
38
+ @name = 'Chester McTester'
39
+ render :inline => 'Hello there, <%= @name %>', :layout => true
40
+ end
41
+
42
+ def normal_erb_with_different_erb_layout
43
+ @name = 'Chester McTester'
44
+ render :inline => 'Hello there, <%= @name %>', :layout => 'application'
45
+ end
46
+
47
+ def with_request_layout
48
+ @radiant_layout = 'Test Request'
49
+
50
+ render :inline => '', :layout => true
51
+ end
52
+
53
+ def with_response_layout
54
+ @radiant_layout = 'Test Response'
55
+
56
+ render :inline => '', :layout => true
57
+ end
58
+ end
59
+
60
+ describe ShareController do
61
+ dataset :layouts
62
+
63
+ before(:each) do
64
+ @controller = ShareController.new
65
+ @request = ActionController::TestRequest.new
66
+ @response = ActionController::TestResponse.new
67
+
68
+ @erb_content = "Hello there, Chester McTester"
69
+
70
+ layout = "Content: <r:content />"
71
+ Layout.create!(:name => 'Default', :content => layout)
72
+
73
+ layout = "Different: <r:content />"
74
+ Layout.create!(:name => 'Different', :content => layout)
75
+
76
+ layout = "Request: <r:test_has_request />\nContent: <r:content />"
77
+ Layout.create!(:name => 'Test Request', :content => layout)
78
+
79
+ layout = "Response: <r:test_has_response />\nContent: <r:content />"
80
+ Layout.create!(:name => 'Test Response', :content => layout)
81
+ end
82
+
83
+ it "should render normal erb in radiant layout" do
84
+ get :normal_erb_in_radiant_layout
85
+ response.should be_success
86
+ @response.body.strip.should == "Content: #{@erb_content}"
87
+ end
88
+
89
+ it "should normal_erb_with_no_layout" do
90
+ get :normal_erb_with_no_layout
91
+ response.should be_success
92
+ @response.body.strip.should == @erb_content
93
+ end
94
+
95
+ it "should normal_erb_with_different_radiant_layout" do
96
+ get :normal_erb_with_different_radiant_layout
97
+ response.should be_success
98
+ @response.body.strip.should == "Different: #{@erb_content}"
99
+ end
100
+
101
+ it "should normal_erb_with_different_erb_layout" do
102
+ get :normal_erb_with_different_erb_layout
103
+ response.should be_success
104
+ @response.body.should =~ /#{@erb_content}/
105
+ end
106
+
107
+ it "should should_assign_request" do
108
+ get :with_request_layout
109
+ response.should be_success
110
+ @response.body.should =~ /Request: .*Request$/
111
+ end
112
+
113
+ it "should should_assign_response" do
114
+ get :with_response_layout
115
+ response.should be_success
116
+ @response.body.should =~ /Response: .*Response$/
117
+ end
118
+
119
+ end
@@ -0,0 +1,38 @@
1
+ class NestedLayoutsDataset < Dataset::Base
2
+ def load
3
+ create_record :layout, :parent,
4
+ :name => 'parent',
5
+ :content => <<-CONTENT
6
+ <html>
7
+ <body class="<r:layout />">
8
+ <r:content_for_layout />
9
+ </body>
10
+ </html>
11
+ CONTENT
12
+
13
+ create_record :layout, :child,
14
+ :name => 'child',
15
+ :content => <<-CONTENT
16
+ <r:inside_layout name='parent'>
17
+ <h1>child</h1>
18
+ </r:inside_layout>
19
+ CONTENT
20
+
21
+ create_record :page, :parent_layout,
22
+ :title => 'child layout',
23
+ :layout_id => layouts(:parent).id,
24
+ :breadcrumb => 'Homepage',
25
+ :slug => '/',
26
+ :status_id => 100,
27
+ :published_at => '2008-01-01 08:00:00'
28
+
29
+ create_record :page, :child_layout,
30
+ :title => 'child layout',
31
+ :layout_id => layouts(:child).id,
32
+ :breadcrumb => 'Homepage',
33
+ :slug => '/',
34
+ :status_id => 100,
35
+ :published_at => '2008-01-01 08:00:00'
36
+
37
+ end
38
+ end
@@ -0,0 +1,38 @@
1
+ class ShareLayoutsDataset < Dataset::Base
2
+ def load
3
+ create_record :page, :homepage, :id => 1,
4
+ :title => 'Homepage',
5
+ :breadcrumb => 'Homepage',
6
+ :slug => '/',
7
+ :status_id => 100,
8
+ :published_at => '2008-01-01 08:00:00'
9
+
10
+ create_record :page, :rails_page,
11
+ :id => 2,
12
+ :title => 'App page',
13
+ :breadcrumb => 'App page',
14
+ :slug => 'app',
15
+ :class_name => 'RailsPage',
16
+ :status_id => 100,
17
+ :parent_id => 1,
18
+ :published_at => '2008-01-01 08:00:00'
19
+
20
+ create_record :page, :rails_page_child,
21
+ :id => 3,
22
+ :title => 'Child',
23
+ :breadcrumb => 'Child',
24
+ :slug => 'child-page',
25
+ :status_id => 100,
26
+ :parent_id => 2,
27
+ :published_at => '2008-01-01 08:00:00'
28
+
29
+ create_record :page, :other,
30
+ :id => 4,
31
+ :title => 'Other',
32
+ :breadcrumb => 'Other',
33
+ :slug => 'other',
34
+ :status_id => 100,
35
+ :parent_id => 1,
36
+ :published_at => '2008-01-01 08:00:00'
37
+ end
38
+ end
@@ -0,0 +1,168 @@
1
+ require 'spec/spec_helper'
2
+
3
+ describe ShareLayouts::Helper do
4
+ include ShareLayouts::Helper
5
+ dataset :layouts, :pages, :share_layouts
6
+ test_helper :page
7
+ attr_accessor :request, :response
8
+
9
+ MAIN_RESULT = <<-TEXT
10
+ <html>
11
+ <head>
12
+ <title>My Title</title>
13
+ </head>
14
+ <body>
15
+ something
16
+ </body>
17
+ </html>
18
+ TEXT
19
+
20
+ before(:each) do
21
+ @page = RailsPage.new(page_params(:class_name => "RailsPage"))
22
+ @content_for_layout = "something"
23
+ @radiant_layout = layouts(:main).name
24
+ @request = OpenStruct.new(:path => "/some/page/")
25
+ end
26
+
27
+ it "should extract_content_captures_as_hash" do
28
+ extract_captures.should == {:body => "something"}
29
+ @content_for_sidebar = "sidebar"
30
+ extract_captures.should == {:body => "something", :sidebar => "sidebar"}
31
+ end
32
+
33
+ # testing assignment of layout
34
+ it "should assign_layout_of_page" do
35
+ assign_attributes!(@page)
36
+ @page.layout.should == layouts(:main)
37
+ end
38
+
39
+ it "should assign_layout_of_page_when_missing" do
40
+ previous_layout = @page.layout
41
+ @radiant_layout = ''
42
+ assign_attributes!(@page)
43
+ previous_layout.should == @page.layout
44
+ end
45
+
46
+ # testing assignment of page.title
47
+ it "should assign_page_title_from_instance_var" do
48
+ @title = "My title"
49
+ assign_attributes!(@page)
50
+ @page.title.should == "My title"
51
+ end
52
+
53
+ it "should assign_page_title_from_capture" do
54
+ @content_for_title = "My title"
55
+ assign_attributes!(@page)
56
+ @page.title.should == "My title"
57
+ end
58
+
59
+ it "should assign_title_from_existing_page_title_when_not_specified" do
60
+ assign_attributes!(@page)
61
+ @page.title.should =~ /Page \d+$/ # was 'New Page' before. I assume this changed in Radiant 0.8
62
+ end
63
+
64
+ it "should assign_empty_title_if_missing" do
65
+ @page.title = nil
66
+ @title.should be_nil
67
+ @content_for_title.should be_nil
68
+ @page.title.should be_nil
69
+ assign_attributes!(@page)
70
+ @page.title.should == ''
71
+ end
72
+
73
+ #testing assignment of page.breadcrumb
74
+ it "should assign_page_breadcrumb_from_instance_var" do
75
+ @breadcrumb = "My breadcrumb"
76
+ assign_attributes!(@page)
77
+ @page.breadcrumb.should == "My breadcrumb"
78
+ end
79
+
80
+ it "should assign_page_breadcrumb_from_capture" do
81
+ @content_for_breadcrumb = "My breadcrumb"
82
+ assign_attributes!(@page)
83
+ @page.breadcrumb.should == "My breadcrumb"
84
+ end
85
+
86
+ it "should assign_breadcrumb_from_existing_breadcrumb_when_not_specified" do
87
+ @page.breadcrumb = "existing breadcrumb"
88
+ assign_attributes!(@page)
89
+ @page.breadcrumb.should == 'existing breadcrumb'
90
+ end
91
+
92
+ it "should assign_breadcrumb_from_title_if_missing" do
93
+ @page.title = "Title into BC"
94
+ @page.breadcrumb = nil
95
+ @breadcrumb.should be_nil
96
+ @content_for_breadcrumb.should be_nil
97
+ @page.breadcrumb.should be_nil
98
+ assign_attributes!(@page)
99
+ @page.breadcrumb.should == 'Title into BC'
100
+ end
101
+
102
+ it "should assign_empty_breadcrumb_if_title_missing_too" do
103
+ @page.title = nil
104
+ @title.should be_nil
105
+ @content_for_title.should be_nil
106
+ @page.title.should be_nil
107
+ @page.breadcrumb = nil
108
+ @breadcrumb.should be_nil
109
+ @content_for_breadcrumb.should be_nil
110
+ @page.breadcrumb.should be_nil
111
+ assign_attributes!(@page)
112
+ @page.breadcrumb.should == ''
113
+ end
114
+
115
+ # testing assignment of page.breadcrumbs
116
+ it "should assign_breadcrumbs_from_instance_var" do
117
+ @breadcrumbs = "bc"
118
+ assign_attributes!(@page)
119
+ @page.breadcrumbs.should == 'bc'
120
+ end
121
+
122
+ it "should assign_breadcrumbs_from_capture" do
123
+ @content_for_breadcrumbs = "bc"
124
+ assign_attributes!(@page)
125
+ @page.breadcrumbs.should == 'bc'
126
+ end
127
+
128
+ it "should leave_breadcrumbs_nil_if_missing" do
129
+ @page.breadcrumbs = nil
130
+ @breadcrumbs.should be_nil
131
+ @content_for_breadcrumbs.should be_nil
132
+ @page.breadcrumbs.should be_nil
133
+ assign_attributes!(@page)
134
+ @page.breadcrumbs.should be_nil
135
+ end
136
+
137
+ # testing assigment of page.url
138
+ it "should assign_url_from_request_path" do
139
+ assign_attributes!(@page)
140
+ @page.url.should == '/some/page/'
141
+ end
142
+
143
+ # testing assigment of page.slug
144
+ it "should assign_slug_from_request_path" do
145
+ assign_attributes!(@page)
146
+ @page.slug.should == 'page'
147
+ end
148
+
149
+ # testing assignment of page.published_at
150
+ it "should assign_published_at" do
151
+ assign_attributes!(@page)
152
+ @page.published_at.should_not be_nil
153
+ end
154
+
155
+ it "should render_page" do
156
+ @title = "My Title"
157
+ radiant_layout.strip.should == MAIN_RESULT.strip
158
+ end
159
+
160
+ it "should find_page" do
161
+ @request.path = "/app/something/"
162
+ find_page.should == pages(:rails_page)
163
+ find_page.should be_a_kind_of(RailsPage)
164
+ @request.path = "/some-other/url/"
165
+ find_page.should_not == pages(:rails_page)
166
+ find_page.should be_a_kind_of(RailsPage)
167
+ end
168
+ end