summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-12-14 11:27:52 -0300
committerAbinoam Praxedes Marques Jr <abinoam@gmail.com>2015-12-14 11:27:52 -0300
commit2339259773cd04104967d883dfa07fbf9d646d18 (patch)
treef3266b3abc9835607b165b1b6e62ecedd31778ae
parentab02507667ba46fbe71e430c59253d1deb1635f0 (diff)
downloadhighline-2339259773cd04104967d883dfa07fbf9d646d18.tar.gz
Reindent HighLine::Statement
-rw-r--r--lib/highline/statement.rb146
1 files changed, 74 insertions, 72 deletions
diff --git a/lib/highline/statement.rb b/lib/highline/statement.rb
index f3df34f..5e6e2f2 100644
--- a/lib/highline/statement.rb
+++ b/lib/highline/statement.rb
@@ -4,77 +4,79 @@ require 'highline/wrapper'
require 'highline/paginator'
require 'highline/template_renderer'
-# This class handles proper formatting based
-# on a HighLine context, applying wrapping,
-# pagination, indentation and color rendering
-# when necessary. It's used by {HighLine#render_statement}
-# @see HighLine#render_statement
-class HighLine::Statement
- # The source object to be stringfied and formatted.
- attr_reader :source
-
- # The HighLine context
- # @return [HighLine]
- attr_reader :highline
-
- # The stringfied source object
- # @return [String]
- attr_reader :template_string
-
- # It needs the input String and the HighLine context
- # @param source [#to_s]
- # @param highline [HighLine] context
- def initialize(source, highline)
- @highline = highline
- @source = source
- @template_string = stringfy(source)
- end
-
- # Returns the formated statement.
- # Applies wrapping, pagination, indentation and color rendering
- # based on HighLine instance settings.
- # @return [String] formated statement
- def statement
- @statement ||= format_statement
- end
-
- # (see #statement)
- # Delegates to {#statement}
- def to_s
- statement
- end
-
- private
-
- def stringfy(template_string)
- String(template_string || "").dup
- end
-
- def format_statement
- return template_string unless template_string.length > 0
-
- statement = render_template
-
- statement = HighLine::Wrapper.wrap(statement, highline.wrap_at)
- statement = HighLine::Paginator.new(highline).page_print(statement)
-
- statement = statement.gsub(/\n(?!$)/,"\n#{highline.indentation}") if highline.multi_indent
- statement
- end
-
- def render_template
- # Assigning to a local var so it may be
- # used inside instance eval block
-
- template_renderer = TemplateRenderer.new(template, source, highline)
- template_renderer.render
- end
-
- def template
- @template ||= ERB.new(template_string, nil, "%")
- end
-
- def self.const_missing(constant)
- HighLine.const_get(constant)
+class HighLine
+ # This class handles proper formatting based
+ # on a HighLine context, applying wrapping,
+ # pagination, indentation and color rendering
+ # when necessary. It's used by {HighLine#render_statement}
+ # @see HighLine#render_statement
+ class Statement
+ # The source object to be stringfied and formatted.
+ attr_reader :source
+
+ # The HighLine context
+ # @return [HighLine]
+ attr_reader :highline
+
+ # The stringfied source object
+ # @return [String]
+ attr_reader :template_string
+
+ # It needs the input String and the HighLine context
+ # @param source [#to_s]
+ # @param highline [HighLine] context
+ def initialize(source, highline)
+ @highline = highline
+ @source = source
+ @template_string = stringfy(source)
+ end
+
+ # Returns the formated statement.
+ # Applies wrapping, pagination, indentation and color rendering
+ # based on HighLine instance settings.
+ # @return [String] formated statement
+ def statement
+ @statement ||= format_statement
+ end
+
+ # (see #statement)
+ # Delegates to {#statement}
+ def to_s
+ statement
+ end
+
+ private
+
+ def stringfy(template_string)
+ String(template_string || "").dup
+ end
+
+ def format_statement
+ return template_string unless template_string.length > 0
+
+ statement = render_template
+
+ statement = HighLine::Wrapper.wrap(statement, highline.wrap_at)
+ statement = HighLine::Paginator.new(highline).page_print(statement)
+
+ statement = statement.gsub(/\n(?!$)/,"\n#{highline.indentation}") if highline.multi_indent
+ statement
+ end
+
+ def render_template
+ # Assigning to a local var so it may be
+ # used inside instance eval block
+
+ template_renderer = TemplateRenderer.new(template, source, highline)
+ template_renderer.render
+ end
+
+ def template
+ @template ||= ERB.new(template_string, nil, "%")
+ end
+
+ def self.const_missing(constant)
+ HighLine.const_get(constant)
+ end
end
end \ No newline at end of file