Skip to content

Commit

Permalink
Add check for Vedeu::Views::Char;
Browse files Browse the repository at this point in the history
In Presentation::Colour and Presentation::Styles, a check has been added for
whether we are dealing with a Vedeu::Views::Char- if so, then we can use the
'#interface' method of that class to get the colour information instead of the
slower '#parent' route.

Work relating to #302.
  • Loading branch information
gavinlaking committed Nov 12, 2015
1 parent 82ed799 commit b00f984
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 22 deletions.
9 changes: 9 additions & 0 deletions lib/vedeu/output/presentation/colour.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def background
@background ||= if colour
colour.background

elsif self.is_a?(Vedeu::Views::Char) && name
interface.colour.background

elsif parent
parent.background

Expand All @@ -39,6 +42,9 @@ def colour
@colour ||= if attributes[:colour]
Vedeu::Colours::Colour.coerce(attributes[:colour])

elsif self.is_a?(Vedeu::Views::Char) && name
Vedeu::Colours::Colour.coerce(interface.colour)

elsif parent
Vedeu::Colours::Colour.coerce(parent.colour)

Expand All @@ -65,6 +71,9 @@ def foreground
@foreground ||= if colour
colour.foreground

elsif self.is_a?(Vedeu::Views::Char) && name
interface.colour.background

elsif parent
parent.foreground

Expand Down
3 changes: 3 additions & 0 deletions lib/vedeu/output/presentation/styles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def style
@style ||= if attributes[:style]
Vedeu::Presentation::Style.coerce(attributes[:style])

elsif self.is_a?(Vedeu::Views::Char) && name
Vedeu::Presentation::Style.coerce(interface.style)

elsif parent
Vedeu::Presentation::Style.coerce(parent.style)

Expand Down
4 changes: 2 additions & 2 deletions test/lib/vedeu/models/views/char_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Views
}
let(:border) { nil }
let(:colour) { nil }
let(:_name) { nil }
let(:_name) { 'Vedeu::Views::Char' }
let(:style) { nil }
let(:position) { nil }
let(:parent_colour) { nil }
Expand Down Expand Up @@ -128,7 +128,7 @@ module Views
background: '',
foreground: '',
},
name: '',
name: 'Vedeu::Views::Char',
parent: {
background: '',
foreground: '',
Expand Down
47 changes: 29 additions & 18 deletions test/lib/vedeu/models/views/html_char_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Views
}
let(:border) {}
let(:colour) {}
let(:_name) {}
let(:_name) { 'Vedeu::Views::HTMLChar' }
let(:parent) { Vedeu::Views::Line.new(colour: parent_colour) }
let(:parent_colour) {}
let(:_value) {}
Expand Down Expand Up @@ -63,25 +63,36 @@ module Views
end

context 'when there is no colour' do
context 'when there is a parent colour' do
let(:parent_colour) {
Vedeu::Colours::Colour.new(background: '#002222',
foreground: '#dd2200')
}

it { subject.must_equal(
"<td style='" \
"border:1px #002222 solid;" \
"background:#002222;" \
"color:#dd2200;" \
"border-top:1px #dd2200 solid;" \
"border-left:1px #dd2200 solid;" \
"'>&nbsp;</td>"
) }
context 'when there is an interface' do
it { subject.must_equal("<td style=''>&nbsp;</td>") }
end

context 'when there is no parent colour' do
it { subject.must_equal("<td style=''>&nbsp;</td>") }
context 'when there is no interface' do
let(:_name) {}

context 'when there is a parent colour' do
let(:parent_colour) {
Vedeu::Colours::Colour.new(background: '#002222',
foreground: '#dd2200')
}

it { subject.must_equal(
"<td style='" \
"border:1px #002222 solid;" \
"background:#002222;" \
"color:#dd2200;" \
"border-top:1px #dd2200 solid;" \
"border-left:1px #dd2200 solid;" \
"'>&nbsp;</td>"
) }
end

context 'when there is no parent colour' do
let(:parent) {}
let(:parent_colour) {}

it { subject.must_equal("<td style=''>&nbsp;</td>") }
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/lib/vedeu/output/renderers/json_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Renderers
let(:instance) { described.new(options) }
let(:options) { {} }
let(:output) { Vedeu::Models::Page.new }
let(:_name) {}
let(:_name) { 'Vedeu::Renderers::JSON' }

before do
::File.stubs(:write)
Expand Down Expand Up @@ -49,7 +49,7 @@ module Renderers
" \"background\": \"\\u001b[48;2;255;0;0m\",\n" \
" \"foreground\": \"\\u001b[38;2;255;255;255m\"\n" \
" },\n" \
" \"name\": \"\",\n" \
" \"name\": \"Vedeu::Renderers::JSON\",\n" \
" \"parent\": {\n" \
" },\n" \
" \"position\": {\n" \
Expand Down

0 comments on commit b00f984

Please sign in to comment.