radiant-layouts-extension 0.9.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +75 -4
- data/README.md +48 -1
- data/Rakefile +56 -15
- data/VERSION +1 -1
- data/app/models/haml_filter.rb +5 -0
- data/app/views/layouts/radiant.html.haml +1 -1
- data/config/routes.rb +5 -0
- data/layouts_extension.rb +13 -5
- data/lib/haml_layouts/models/layout.rb +34 -0
- data/lib/haml_layouts/models/page.rb +31 -0
- data/lib/nested_layouts/tags/core.rb +141 -0
- data/lib/share_layouts/controllers/action_controller.rb +25 -0
- data/lib/share_layouts/helpers/action_view.rb +50 -0
- data/lib/tasks/layouts_extension_tasks.rake +27 -6
- data/radiant-layouts-extension.gemspec +37 -26
- data/spec/controllers/{share_layouts_spec.rb → share_controller_spec.rb} +0 -0
- data/spec/datasets/layouts_layouts.rb +36 -0
- data/spec/datasets/layouts_pages.rb +43 -0
- data/spec/lib/haml_layouts/haml_layouts_extension_spec.rb +22 -0
- data/spec/lib/haml_layouts/models/layout_spec.rb +36 -0
- data/spec/lib/haml_layouts/models/page_spec.rb +40 -0
- data/spec/lib/nested_layouts/nested_layouts_extension_spec.rb +16 -0
- data/spec/lib/nested_layouts/{tags_spec.rb → tags/core_spec.rb} +41 -17
- data/spec/{controllers/nested_layouts_spec.rb → lib/share_layouts/controllers/action_controller_spec.rb} +0 -1
- data/spec/{helpers/share_layouts_helper_spec.rb → lib/share_layouts/helpers/action_view_spec.rb} +32 -29
- data/spec/lib/share_layouts/share_layouts_extension_spec.rb +22 -0
- data/spec/models/haml_filter_spec.rb +0 -0
- data/spec/models/rails_page_spec.rb +9 -9
- data/spec/spec.opts +2 -3
- metadata +43 -28
- data/lib/nested_layouts.rb +0 -2
- data/lib/nested_layouts/tags.rb +0 -127
- data/lib/share_layouts.rb +0 -2
- data/lib/share_layouts/helper.rb +0 -39
- data/lib/share_layouts/radiant_layouts.rb +0 -21
- data/spec/datasets/nested_layouts_dataset.rb +0 -38
- data/spec/datasets/share_layouts_dataset.rb +0 -38
- data/spec/lib/share_layouts_extension_spec.rb +0 -25
- data/spec/rcov.opts +0 -2
data/MIT-LICENSE
CHANGED
@@ -1,9 +1,16 @@
|
|
1
|
-
|
1
|
+
# Layouts Extension
|
2
2
|
|
3
|
-
|
4
|
-
lib/nested_layouts.rb
|
5
|
-
lib/nested_layouts/tags.rb
|
3
|
+
Is a collaboration of many parties that solves some common shortcomings with standard Radiant layouts
|
6
4
|
|
5
|
+
http://github.com/squaretalent/radiant-layouts-extension/
|
6
|
+
|
7
|
+
## Nested Layouts
|
8
|
+
|
9
|
+
lib/nested_layouts/core.rb
|
10
|
+
|
11
|
+
spec/lib/nested_layouts/nested_layouts_extension_spec.rb
|
12
|
+
spec/lib/nested_layouts/tags/core_spec.rb
|
13
|
+
|
7
14
|
== MIT License
|
8
15
|
|
9
16
|
Copyright (c) 2008 Michael O. Klett.
|
@@ -18,6 +25,70 @@ furnished to do so, subject to the following conditions:
|
|
18
25
|
The above copyright notice and this permission notice shall be included in all
|
19
26
|
copies or substantial portions of the Software.
|
20
27
|
|
28
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
29
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
30
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
31
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
32
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
33
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
34
|
+
SOFTWARE.
|
35
|
+
|
36
|
+
## Shared Layouts
|
37
|
+
|
38
|
+
lib/share_layouts/controllers/action_controller.rb
|
39
|
+
lib/share_layouts/helpers/action_view.rb
|
40
|
+
app/models/rails_page/action_view.rb
|
41
|
+
|
42
|
+
spec/controllers/share_controller_spec.rb
|
43
|
+
spec/lib/share_layouts/share_layouts_extension_spec.rb
|
44
|
+
spec/lib/share_layouts/controllers/action_controller_spec.rb
|
45
|
+
spec/lib/share_layouts/helpers/action_view_spec.rb
|
46
|
+
|
47
|
+
== MIT Licence
|
48
|
+
|
49
|
+
Copyright (c) 2010 Radiant - Jim Gay, William Ross
|
50
|
+
|
51
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
52
|
+
of this software and associated documentation files (the "Software"), to deal
|
53
|
+
in the Software without restriction, including without limitation the rights
|
54
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
55
|
+
copies of the Software, and to permit persons to whom the Software is
|
56
|
+
furnished to do so, subject to the following conditions:
|
57
|
+
|
58
|
+
The above copyright notice and this permission notice shall be included in all
|
59
|
+
copies or substantial portions of the Software.
|
60
|
+
|
61
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
62
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
63
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
64
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
65
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
66
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
67
|
+
SOFTWARE.
|
68
|
+
|
69
|
+
## HAML Layouts
|
70
|
+
|
71
|
+
lib/haml_layouts/models/layout.rb
|
72
|
+
lib/haml_layouts/models/page.rb
|
73
|
+
|
74
|
+
spec/lib/haml_layouts/haml_layouts_extension_spec.rb
|
75
|
+
spec/lib/haml_layouts/models/layout_spec.rb
|
76
|
+
spec/lib/haml_layouts/models/layout_spec.rb
|
77
|
+
|
78
|
+
== MIT Licence
|
79
|
+
|
80
|
+
Copyright (c) 2010 The Frontier Group Pty. Ltd - Dirk Kelly, Tony Issakov
|
81
|
+
|
82
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
83
|
+
of this software and associated documentation files (the "Software"), to deal
|
84
|
+
in the Software without restriction, including without limitation the rights
|
85
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
86
|
+
copies of the Software, and to permit persons to whom the Software is
|
87
|
+
furnished to do so, subject to the following conditions:
|
88
|
+
|
89
|
+
The above copyright notice and this permission notice shall be included in all
|
90
|
+
copies or substantial portions of the Software.
|
91
|
+
|
21
92
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
93
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
94
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
data/README.md
CHANGED
@@ -78,4 +78,51 @@ This would render the following if Page Layout was called
|
|
78
78
|
### Acknowledgments
|
79
79
|
|
80
80
|
* Merged into radiant-layouts-extension, Dirk Kelly, August 2010
|
81
|
-
* Original Source: http://github.com/moklett/radiant-nested-layouts-extension
|
81
|
+
* Original Source: http://github.com/moklett/radiant-nested-layouts-extension
|
82
|
+
|
83
|
+
## Haml Layouts
|
84
|
+
|
85
|
+
[http://haml-lang.com/](http://haml-lang.com/)
|
86
|
+
|
87
|
+
### Introduction
|
88
|
+
|
89
|
+
Write your layouts and radius tags in haml, with support for nested layouts
|
90
|
+
|
91
|
+
// Parent Layout
|
92
|
+
%div{:id=>"parent"}
|
93
|
+
%r:content_for_layout
|
94
|
+
|
95
|
+
// Child Layout
|
96
|
+
%r:inside_layout{:name=>"Parent"}
|
97
|
+
%h2
|
98
|
+
%:title
|
99
|
+
|
100
|
+
Note: Within Layouts you must set the content type to `haml` or the Layout name to end in `.haml`
|
101
|
+
|
102
|
+
Integrates the work of [SaturnFlyer](http://github.com/saturnflyer) creating a haml_filter on pages and snippets. Additional task involved
|
103
|
+
changing the order which objects with this type are renders. The content is turned into html before the
|
104
|
+
radius tags are passed.
|
105
|
+
|
106
|
+
### Caveats
|
107
|
+
|
108
|
+
You can't yet put a radiant tag inside an attribute of a haml element. ie:
|
109
|
+
|
110
|
+
%div.product{:id=>"<r:id />"} // Will not work
|
111
|
+
|
112
|
+
%div.product{:id=>"%r:id"} // Will not work
|
113
|
+
|
114
|
+
%div.product{:id=><r:id />} // Will not work
|
115
|
+
|
116
|
+
In the mean time use a plain filter whilst we come up with something awesome
|
117
|
+
|
118
|
+
%body
|
119
|
+
#primary
|
120
|
+
:plain
|
121
|
+
<div id="<r:id />" class="product">
|
122
|
+
<r:snippet name='product' />
|
123
|
+
|
124
|
+
### Acknowledgments
|
125
|
+
|
126
|
+
* [SaturnFlyer](http://github.com/saturnflyer) [@SaturnFlyer](http://twitter.com/saturnflyer) (Jim Gay) | Original idea http://github.com/saturnflyer/radiant-haml_filter-extension
|
127
|
+
* [Tissak](http://github.com/tissak) [@Tissak](http://twitter.com/tissak) (Tony Issakov) | Insisted that this was possible, and then wrote up an implementation in 10 minutes
|
128
|
+
* [DirkKelly](http://github.com/dirkkelly) [@DirkKelly](http://twitter.com/dirkkelly) (Dirk Kelly) | Merged into radiant-layouts-extension and hooked page parse_object to support snippets and content haml radius tags
|
data/Rakefile
CHANGED
@@ -25,11 +25,11 @@ begin
|
|
25
25
|
require 'jeweler'
|
26
26
|
Jeweler::Tasks.new do |gem|
|
27
27
|
gem.name = "radiant-layouts-extension"
|
28
|
-
gem.summary = %Q{
|
29
|
-
gem.description = %Q{
|
30
|
-
gem.email = "dk@
|
28
|
+
gem.summary = %Q{Extends Radiant Layouts to support nesting, sharing with Rails Controllers and rendering HAML}
|
29
|
+
gem.description = %Q{Extends Radiant Layouts to support nesting, sharing with Rails Controllers and rendering HAML}
|
30
|
+
gem.email = "dk@dirkkelly.com"
|
31
31
|
gem.homepage = "http://github.com/squaretalent/radiant-layouts-extension"
|
32
|
-
gem.authors = ["Dirk Kelly"]
|
32
|
+
gem.authors = ["Michael Klett", "Jim Gay", "William Ross", "Tony Issakov", "Dirk Kelly"]
|
33
33
|
gem.add_development_dependency 'rspec', '>= 1.3.0'
|
34
34
|
gem.add_development_dependency 'rspec-rails', '>= 1.3.2'
|
35
35
|
gem.add_development_dependency 'cucumber', '>= 0.8.5'
|
@@ -40,13 +40,35 @@ begin
|
|
40
40
|
end
|
41
41
|
Jeweler::GemcutterTasks.new
|
42
42
|
rescue LoadError
|
43
|
-
puts "Jeweler (or a dependency) not available.
|
43
|
+
puts "Jeweler (or a dependency) not available. This is only required if you plan to package layouts as a gem."
|
44
44
|
end
|
45
45
|
|
46
|
+
# In rails 1.2, plugins aren't available in the path until they're loaded.
|
47
|
+
# Check to see if the rspec plugin is installed first and require
|
48
|
+
# it if it is. If not, use the gem version.
|
49
|
+
|
50
|
+
# Determine where the RSpec plugin is by loading the boot
|
51
|
+
unless defined? RADIANT_ROOT
|
52
|
+
ENV["RAILS_ENV"] = "test"
|
53
|
+
case
|
54
|
+
when ENV["RADIANT_ENV_FILE"]
|
55
|
+
require File.dirname(ENV["RADIANT_ENV_FILE"]) + "/boot"
|
56
|
+
when File.dirname(__FILE__) =~ %r{vendor/radiant/vendor/extensions}
|
57
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../")}/config/boot"
|
58
|
+
else
|
59
|
+
require "#{File.expand_path(File.dirname(__FILE__) + "/../../../")}/config/boot"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
require 'rake'
|
64
|
+
require 'rake/rdoctask'
|
65
|
+
require 'rake/testtask'
|
66
|
+
|
46
67
|
rspec_base = File.expand_path(RADIANT_ROOT + '/vendor/plugins/rspec/lib')
|
47
68
|
$LOAD_PATH.unshift(rspec_base) if File.exist?(rspec_base)
|
48
69
|
require 'spec/rake/spectask'
|
49
|
-
|
70
|
+
require 'cucumber'
|
71
|
+
require 'cucumber/rake/task'
|
50
72
|
|
51
73
|
# Cleanup the RADIANT_ROOT constant so specs will load the environment
|
52
74
|
Object.send(:remove_const, :RADIANT_ROOT)
|
@@ -62,6 +84,8 @@ Spec::Rake::SpecTask.new(:spec) do |t|
|
|
62
84
|
t.spec_files = FileList['spec/**/*_spec.rb']
|
63
85
|
end
|
64
86
|
|
87
|
+
task :features => 'spec:integration'
|
88
|
+
|
65
89
|
namespace :spec do
|
66
90
|
desc "Run all specs in spec directory with RCov"
|
67
91
|
Spec::Rake::SpecTask.new(:rcov) do |t|
|
@@ -70,7 +94,7 @@ namespace :spec do
|
|
70
94
|
t.rcov = true
|
71
95
|
t.rcov_opts = ['--exclude', 'spec', '--rails']
|
72
96
|
end
|
73
|
-
|
97
|
+
|
74
98
|
desc "Print Specdoc for all specs"
|
75
99
|
Spec::Rake::SpecTask.new(:doc) do |t|
|
76
100
|
t.spec_opts = ["--format", "specdoc", "--dry-run"]
|
@@ -84,14 +108,14 @@ namespace :spec do
|
|
84
108
|
t.spec_files = FileList["spec/#{sub}/**/*_spec.rb"]
|
85
109
|
end
|
86
110
|
end
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
111
|
+
|
112
|
+
desc "Run the Cucumber features"
|
113
|
+
Cucumber::Rake::Task.new(:integration) do |t|
|
114
|
+
t.fork = true
|
115
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
116
|
+
# t.feature_pattern = "#{extension_root}/features/**/*.feature"
|
117
|
+
t.profile = "default"
|
118
|
+
end
|
95
119
|
|
96
120
|
# Setup specs for stats
|
97
121
|
task :statsetup do
|
@@ -121,5 +145,22 @@ namespace :spec do
|
|
121
145
|
end
|
122
146
|
end
|
123
147
|
|
148
|
+
desc 'Generate documentation for the layouts extension.'
|
149
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
150
|
+
rdoc.rdoc_dir = 'rdoc'
|
151
|
+
rdoc.title = 'LayoutsExtension'
|
152
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
153
|
+
rdoc.rdoc_files.include('README')
|
154
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
155
|
+
end
|
156
|
+
|
157
|
+
# For extensions that are in transition
|
158
|
+
desc 'Test the Layout extension.'
|
159
|
+
Rake::TestTask.new(:test) do |t|
|
160
|
+
t.libs << 'lib'
|
161
|
+
t.pattern = 'test/**/*_test.rb'
|
162
|
+
t.verbose = true
|
163
|
+
end
|
164
|
+
|
124
165
|
# Load any custom rakefiles for extension
|
125
166
|
Dir[File.dirname(__FILE__) + '/tasks/*.rake'].sort.each { |f| require f }
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.0
|
@@ -1 +1 @@
|
|
1
|
-
= radiant_layout
|
1
|
+
= radiant_layout
|
data/config/routes.rb
ADDED
data/layouts_extension.rb
CHANGED
@@ -2,15 +2,23 @@
|
|
2
2
|
require_dependency 'application_controller'
|
3
3
|
|
4
4
|
class LayoutsExtension < Radiant::Extension
|
5
|
-
version "0.
|
6
|
-
description "
|
5
|
+
version "0.4.0"
|
6
|
+
description "A set of useful extensions to standard Layouts."
|
7
7
|
url "http://github.com/squaretalent/radiant-layouts-extension"
|
8
8
|
|
9
9
|
def activate
|
10
|
+
# Shared Layouts
|
10
11
|
RailsPage
|
11
|
-
ActionController::Base.send :include, ShareLayouts::
|
12
|
-
ActionView::Base.send :include, ShareLayouts::
|
13
|
-
|
12
|
+
ActionController::Base.send :include, ShareLayouts::Controllers::ActionController
|
13
|
+
ActionView::Base.send :include, ShareLayouts::Helpers::ActionView
|
14
|
+
|
15
|
+
# Nested Layouts
|
16
|
+
Page.send :include, NestedLayouts::Tags::Core
|
17
|
+
|
18
|
+
# HAML Layouts
|
19
|
+
Layout.send :include, HamlLayouts::Models::Layout
|
20
|
+
Page.send :include, HamlLayouts::Models::Page
|
21
|
+
HamlFilter
|
14
22
|
end
|
15
23
|
|
16
24
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module HamlLayouts
|
2
|
+
module Models
|
3
|
+
module Layout
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
|
8
|
+
def content
|
9
|
+
if is_haml?
|
10
|
+
Haml::Engine.new(self[:content]).render
|
11
|
+
else
|
12
|
+
self[:content]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Overwrites the standard Radiant Render and pumps out haml if necessary
|
17
|
+
def is_haml?
|
18
|
+
result = false
|
19
|
+
|
20
|
+
if File.extname(name) == '.haml'
|
21
|
+
result = true
|
22
|
+
elsif content_type == 'haml'
|
23
|
+
result = true
|
24
|
+
end
|
25
|
+
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module HamlLayouts
|
2
|
+
module Models
|
3
|
+
module Page
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
|
8
|
+
def parse_object(object)
|
9
|
+
text = object.content
|
10
|
+
if object.respond_to? :filter_id
|
11
|
+
if object.filter_id === 'Haml'
|
12
|
+
# We want to render the tags as html/radius before passing them
|
13
|
+
text = object.filter.filter(text)
|
14
|
+
text = parse(text)
|
15
|
+
else
|
16
|
+
text = parse(text)
|
17
|
+
text = object.filter.filter(text)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
text = parse(text)
|
21
|
+
end
|
22
|
+
text
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module NestedLayouts
|
2
|
+
module Tags
|
3
|
+
module Core
|
4
|
+
|
5
|
+
include Radiant::Taggable
|
6
|
+
|
7
|
+
class TagError < StandardError; end
|
8
|
+
|
9
|
+
desc %{
|
10
|
+
Renders the contents of the tag inside of a "parent" layout, which is selected via the +name+
|
11
|
+
attribute. The contents of this tag are placed at a corresponding <r:content_for_layout/> tag
|
12
|
+
within the parent layout. This tag is intended to be used within your layouts, and should
|
13
|
+
only appear once per layout.
|
14
|
+
|
15
|
+
*Usage:*
|
16
|
+
|
17
|
+
<r:inside_layout name="master">
|
18
|
+
<div id="main-column">
|
19
|
+
<r:content_for_layout/>
|
20
|
+
</div>
|
21
|
+
</r:inside_layout>
|
22
|
+
}
|
23
|
+
tag 'inside_layout' do |tag|
|
24
|
+
if name = tag.attr['name']
|
25
|
+
# Prepare the stacks
|
26
|
+
tag.globals.nested_layouts_content_stack ||= []
|
27
|
+
tag.globals.nested_layouts_layout_stack ||= []
|
28
|
+
|
29
|
+
# Remember the original layout to support the +layout+ tag
|
30
|
+
tag.globals.page_original_layout ||= tag.globals.page.layout # Remember the original layout
|
31
|
+
|
32
|
+
# Find the layout
|
33
|
+
name.strip!
|
34
|
+
if layout = Layout.find_by_name(name)
|
35
|
+
# Track this layout on the stack
|
36
|
+
tag.globals.nested_layouts_layout_stack << name
|
37
|
+
|
38
|
+
# Save contents of inside_layout for later insertion
|
39
|
+
tag.globals.nested_layouts_content_stack << tag.expand
|
40
|
+
|
41
|
+
# Set the page layout that Radiant should use for rendering, which is different than the actual
|
42
|
+
# page's layout when layouts are nested. The final/highest +inside_layout+ tag will set or
|
43
|
+
# overwrite this value for the last time.
|
44
|
+
tag.globals.page.layout = layout
|
45
|
+
tag.globals.page.render
|
46
|
+
else
|
47
|
+
raise TagError.new(%{Error (nested_layouts): Parent layout "#{name.strip}" not found for "inside_layout" tag})
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise TagError.new(%{Error (nested_layouts): "inside_layout" tag must contain a "name" attribute})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc %{
|
55
|
+
Allows nested layouts to target this layout. The contents of <r:inside_layout> tag blocks in another
|
56
|
+
layout will have their contents inserted at the location given by this tag (if they target this
|
57
|
+
layout). This tag also behaves like a standard <r:content/> tag if this layout is specified directly
|
58
|
+
by a page.
|
59
|
+
|
60
|
+
This tag is intended to be used inside layouts.
|
61
|
+
|
62
|
+
*Usage:*
|
63
|
+
|
64
|
+
<html>
|
65
|
+
<body>
|
66
|
+
<r:content_for_layout/>
|
67
|
+
</body>
|
68
|
+
</html>
|
69
|
+
|
70
|
+
}
|
71
|
+
tag 'content_for_layout' do |tag|
|
72
|
+
tag.globals.nested_layouts_content_stack ||= []
|
73
|
+
|
74
|
+
# return the saved content if any, or mimic a default +<r:content/>+ tag (render the body part)
|
75
|
+
tag.globals.nested_layouts_content_stack.pop || tag.globals.page.render_snippet(tag.locals.page.part('body'))
|
76
|
+
end
|
77
|
+
|
78
|
+
desc %{
|
79
|
+
Return the layout name of the current page.
|
80
|
+
|
81
|
+
*Usage:*
|
82
|
+
|
83
|
+
<html>
|
84
|
+
<body id="<r:layout/>"
|
85
|
+
My body tag has an id corresponding to the layout I use. Sweet!
|
86
|
+
</body>
|
87
|
+
</html>
|
88
|
+
}
|
89
|
+
tag 'layout' do |tag|
|
90
|
+
current_layout_name(tag)
|
91
|
+
end
|
92
|
+
|
93
|
+
desc %{ output the contents of tag if layout equals name }
|
94
|
+
tag 'if_layout' do |tag|
|
95
|
+
if name = tag.attr['name']
|
96
|
+
if layout = tag.globals.page_original_layout
|
97
|
+
tag.expand if layout.name == name
|
98
|
+
elsif layout = tag.globals.page.layout
|
99
|
+
tag.expand if layout.name == name
|
100
|
+
end
|
101
|
+
else
|
102
|
+
raise TagError.new(%{Error (nested_layouts): "if_layout" tag must contain a "name" attribute})
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
desc %{ output the contents of tag unless layout equals name }
|
107
|
+
tag 'unless_layout' do |tag|
|
108
|
+
if name = tag.attr['name']
|
109
|
+
if layout = tag.globals.page_original_layout
|
110
|
+
tag.expand if layout.name != name
|
111
|
+
elsif layout = tag.globals.page.layout
|
112
|
+
tag.expand if layout.name != name
|
113
|
+
else
|
114
|
+
tag.expand
|
115
|
+
end
|
116
|
+
else
|
117
|
+
raise TagError.new(%{Error (nested_layouts): "if_layout" tag must contain a "name" attribute})
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
tag 'body' do |tag|
|
122
|
+
%{<body class="#{tag.attr['class']} #{current_layout_name(tag)}">#{tag.expand}</body>}
|
123
|
+
end
|
124
|
+
|
125
|
+
protected
|
126
|
+
|
127
|
+
def current_layout_name(tag)
|
128
|
+
result = ''
|
129
|
+
|
130
|
+
if layout = tag.globals.page_original_layout
|
131
|
+
result = layout.name
|
132
|
+
elsif layout = tag.globals.page.layout
|
133
|
+
result = layout.name
|
134
|
+
end
|
135
|
+
|
136
|
+
result
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|