Class: Rufo::ErbFormatter
- Inherits:
-
Object
- Object
- Rufo::ErbFormatter
- Defined in:
- lib/rufo/erb_formatter.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(code, **options) ⇒ ErbFormatter
constructor
A new instance of ErbFormatter.
Constructor Details
#initialize(code, **options) ⇒ ErbFormatter
Returns a new instance of ErbFormatter.
26 27 28 29 30 31 32 |
# File 'lib/rufo/erb_formatter.rb', line 26 def initialize(code, **) = @scanner = CustomScanner.new(code) @code_mode = false @current_lineno = 0 @current_column = 0 end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
24 25 26 |
# File 'lib/rufo/erb_formatter.rb', line 24 def result @result end |
Class Method Details
.format(code, **options) ⇒ Object
20 21 22 |
# File 'lib/rufo/erb_formatter.rb', line 20 def self.format(code, **) new(code, **).format end |
Instance Method Details
#format ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rufo/erb_formatter.rb', line 34 def format out = [] process_erb do |(type, content)| if type == :code formatted_code = process_code(content) indented_code = formatted_code.lines.join(" " * current_column) out << " #{indented_code} " else out << content end update_lineno(out.last) update_column(out.last) end @result = out.join("") end |