Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions lib/syntax_tree/haml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,26 @@ class Haml::Parser::ParseNode
# accept a visitor in order to walk through the tree.
def accept(visitor)
case type
in :comment
when :comment
visitor.visit_comment(self)
in :doctype
when :doctype
visitor.visit_doctype(self)
in :filter
when :filter
visitor.visit_filter(self)
in :haml_comment
when :haml_comment
visitor.visit_haml_comment(self)
in :plain
when :plain
visitor.visit_plain(self)
in :root
when :root
visitor.visit_root(self)
in :script
when :script
visitor.visit_script(self)
in :silent_script
when :silent_script
visitor.visit_silent_script(self)
in :tag
when :tag
visitor.visit_tag(self)
else
raise "Unknown node type: #{type}"
end
end

Expand Down
19 changes: 10 additions & 9 deletions lib/syntax_tree/haml/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,11 @@ def visit_tag(node)
def continuation?(node, child)
return false if child.type != :silent_script

case [node.value[:keyword], child.value[:keyword]]
in ["case", "in" | "when" | "else"]
true
in ["if" | "unless", "elsif" | "else"]
true
case node.value[:keyword]
when "case"
%w[in when else].include?(child.value[:keyword])
when "if", "unless"
%w[elsif else].include?(child.value[:keyword])
else
false
end
Expand All @@ -438,11 +438,12 @@ def escaped?(text)
# Take a source string and attempt to parse it into a set of attributes
# that can be used to format the source.
def parse_attributes(source)
case Ripper.sexp(source)
in [:program, [[:hash, *], *]] if parsed =
::Haml::AttributeParser.parse(source)
program = Ripper.sexp(source)
type = program && program[1][0][0]

if type == :hash && (parsed = ::Haml::AttributeParser.parse(source))
parsed.to_h { |key, value| [key, parse_attributes(value)] }
in [:program, [[:string_literal, *], *]]
elsif type == :string_literal
SyntaxTree.parse(source).statements.body[0]
else
LiteralHashValue.new(source)
Expand Down