Skip to content

Commit

Permalink
Hack Output::Text wrapping;
Browse files Browse the repository at this point in the history
Now works with Views::View and Views::Line models, though still needs more work.

Work related to #341.
  • Loading branch information
gavinlaking committed Dec 12, 2015
1 parent c41bb26 commit 7a934c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
41 changes: 36 additions & 5 deletions lib/vedeu/output/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def self.add(value = '', options = {})
end

# @see Vedeu::DSL::Text#text
# @todo Remove this method once functionality moved elsewhere.
def self.with(value = '', options = {})
new(value, options).aligned
end
Expand Down Expand Up @@ -60,9 +61,15 @@ def aligned
# @return [void]
def add
if wrap?
model.add(wrapped)
if view?
model.add(wrapped)

else
elsif line? && model_parent_view?
model_parent.add(wrapped)

end

elsif model
model.add(content)

end
Expand Down Expand Up @@ -106,9 +113,12 @@ def colour
if options[:colour] || options[:background] || options[:foreground]
Vedeu::Colours::Colour.coerce(options)

else
elsif model
model.colour

else
{}

end
end

Expand Down Expand Up @@ -157,14 +167,35 @@ def line
@line ||= Vedeu::Views::Line.build(parent: parent, client: client)
end

# @return [Boolean]
def view?
model && model.is_a?(Vedeu::Views::View)
end

# @return [Boolean]
def line?
model && model.is_a?(Vedeu::Views::Line)
end

# Returns the model option when set.
#
# @return [Vedeu::Views::View|
# Vedeu::Views::Line|
# Vedeu::Null::Generic|
# Vedeu::Views::Stream]
def model
@model ||= options[:model] || Vedeu::Null::Generic.new
options[:model]
end

# @return [void]
def model_parent
options[:model].parent
end

# @return [Boolean]
def model_parent_view?
options[:model].parent &&
options[:model].parent.is_a?(Vedeu::Views::View)
end

# @see Vedeu::Output::Wordwrap#mode
Expand Down Expand Up @@ -221,7 +252,7 @@ def string
#
# @return [void]
def style
model.style
model.style if model
end

# Return a boolean indicating that the string is greater than
Expand Down
15 changes: 14 additions & 1 deletion test/support/examples/material_colours_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,17 @@ class VedeuMaterialColoursApp
colour background: '#555555', foreground: '#ffffff'
geometry do
x 3
xn 13
xn 23
y 36
yn 39
end
end

Vedeu.interface 'wrapping2' do
colour background: '#888888', foreground: '#ffffff'
geometry do
x 26
xn 46
y 36
yn 39
end
Expand Down Expand Up @@ -598,6 +608,9 @@ class VedeuMaterialColoursApp
line { text 'This is a line of text that should wrap.', mode: :wrap }
end
end
view('wrapping2') do
text 'This is a line of text that should wrap.', mode: :wrap
end
end

Vedeu.focus_by_name 'main_interface'
Expand Down

0 comments on commit 7a934c6

Please sign in to comment.