Module: SyntaxTree::Haml

Defined in:
lib/syntax_tree/haml.rb,
lib/syntax_tree/haml/format.rb,
lib/syntax_tree/haml/version.rb,
lib/syntax_tree/haml/pretty_print.rb

Defined Under Namespace

Classes: Format, PrettyPrint, Visitor

Constant Summary collapse

DOCTYPE_TYPES =
{
  "basic" => "Basic",
  "frameset" => "Frameset",
  "mobile" => "Mobile",
  "rdfa" => "RDFa",
  "strict" => "Strict",
  "xml" => "XML"
}
DOCTYPE_VERSIONS =
%w[1.1 5]
VERSION =
"4.0.3"

Class Method Summary collapse

Class Method Details

.format(source, maxwidth = 80, options: Formatter::Options.new) ⇒ Object

This is the main entrypoint for the formatter. It parses the source, builds a formatter, then pretty prints the result.



36
37
38
39
40
41
42
# File 'lib/syntax_tree/haml.rb', line 36

def self.format(source, maxwidth = 80, options: Formatter::Options.new)
  formatter = Format::Formatter.new(source, +"", maxwidth, options: options)
  parse(source).format(formatter)

  formatter.flush
  formatter.output
end

.parse(source) ⇒ Object

This is the main parser entrypoint, and just delegates to the Haml gem’s parser to do the heavy lifting.



30
31
32
# File 'lib/syntax_tree/haml.rb', line 30

def self.parse(source)
  ::Haml::Parser.new({}).call(source)
end

.read(filepath) ⇒ Object

This is a required API for syntax tree which just delegates to File.read.



45
46
47
# File 'lib/syntax_tree/haml.rb', line 45

def self.read(filepath)
  File.read(filepath)
end