Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lotus::View::Layout => Lotus::Layout
- Loading branch information
Showing
7 changed files
with
58 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'lotus/view/rendering/layout_registry' | ||
require 'lotus/view/rendering/layout_scope' | ||
require 'lotus/view/rendering/null_layout' | ||
|
||
module Lotus | ||
module Layout | ||
def self.included(base) | ||
base.class_eval do | ||
extend Lotus::View::Dsl.dup | ||
extend ClassMethods | ||
end | ||
|
||
Lotus::View.layouts.add(base) | ||
end | ||
|
||
module ClassMethods | ||
SUFFIX = '_layout'.freeze | ||
|
||
def registry | ||
@@registry ||= View::Rendering::LayoutRegistry.new(self) | ||
end | ||
|
||
def template | ||
super.gsub(suffix, '') | ||
end | ||
|
||
def suffix | ||
SUFFIX | ||
end | ||
|
||
protected | ||
def load! | ||
registry.freeze | ||
end | ||
end | ||
|
||
def initialize(scope, rendered) | ||
@scope, @rendered = View::Rendering::LayoutScope.new(self, scope), rendered | ||
end | ||
|
||
def render | ||
template.render(@scope, &Proc.new{@rendered}) | ||
end | ||
|
||
protected | ||
def template | ||
self.class.registry.resolve({format: @scope.format}) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,10 @@ | ||
require 'test_helper' | ||
|
||
describe Lotus::View do | ||
describe 'layout' do | ||
describe 'when Lotus::View.layout is nil' do | ||
describe "and it isn't specified at view level" do | ||
it 'has NullLayout' do | ||
HelloWorldView.layout.must_equal(Lotus::View::Rendering::NullLayout) | ||
end | ||
end | ||
|
||
describe "and it is specified at view level" do | ||
it 'has the specified value' do | ||
AppView.layout.must_equal(ApplicationLayout) | ||
end | ||
|
||
describe "and a subclass has a different value" do | ||
it 'has the specified value' do | ||
AppViewLayout.layout.must_equal(Lotus::View::Rendering::NullLayout) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'when Lotus::View.layout has a value' do | ||
before do | ||
Lotus::View.layout = :global | ||
|
||
App::View.class_eval { @layout = nil } | ||
App::View.layout(Lotus::View::Rendering::LayoutFinder.new(App::View).find) | ||
end | ||
|
||
after do | ||
Lotus::View.layout = nil | ||
Lotus::View.layout.freeze | ||
end | ||
|
||
describe "and it isn't specified at view level" do | ||
it 'returns the global value' do | ||
App::View.layout.must_equal(Lotus::View.layout) | ||
end | ||
end | ||
|
||
describe "and it is specified at view level" do | ||
it 'has the specified value' do | ||
AppView.layout.must_equal(ApplicationLayout) | ||
end | ||
|
||
describe "and a subclass has a different value" do | ||
it 'has the specified value' do | ||
AppViewLayout.layout.must_equal(Lotus::View::Rendering::NullLayout) | ||
end | ||
end | ||
end | ||
describe Lotus::Layout do | ||
describe 'rendering from layout' do | ||
it 'renders partial' do | ||
rendered = IndexView.render({format: :html}, {}) | ||
rendered.must_match %(<div id="sidebar"></div>) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.