Class: HtmlBeautifier::RubyIndenter

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlbeautifier/ruby_indenter.rb

Constant Summary collapse

INDENT_KEYWORDS =
%w[if elsif else unless while until begin for].freeze
OUTDENT_KEYWORDS =
%w[elsif else end].freeze
RUBY_INDENT =
%r{
  ^ ( #{INDENT_KEYWORDS.join("|")} )\b
  | \b ( do | \{ ) ( \s* \| [^|]+ \| )? $
}xo
RUBY_OUTDENT =
%r{ ^ ( #{OUTDENT_KEYWORDS.join("|")} | \} ) \b }xo

Instance Method Summary collapse

Instance Method Details

#indent?(lines) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/htmlbeautifier/ruby_indenter.rb', line 17

def indent?(lines)
  lines.last =~ RUBY_INDENT
end

#outdent?(lines) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/htmlbeautifier/ruby_indenter.rb', line 13

def outdent?(lines)
  lines.first =~ RUBY_OUTDENT
end