lib/slim_lint/document.rb in slim_lint-0.2.0 vs lib/slim_lint/document.rb in slim_lint-0.3.0
- old
+ new
@@ -1,19 +1,35 @@
module SlimLint
# Represents a parsed Slim document and its associated metadata.
class Document
- attr_reader :config, :file, :sexp, :source, :source_lines
+ # File name given to source code parsed from just a string.
+ STRING_SOURCE = '(string)'
+ # @return [SlimLint::Configuration] Configuration used to parse template
+ attr_reader :config
+
+ # @return [String] Slim template file path
+ attr_reader :file
+
+ # @return [SlimLint::Sexp] Sexpression representing the parsed document
+ attr_reader :sexp
+
+ # @return [String] original source code
+ attr_reader :source
+
+ # @return [Array<String>] original source code as an array of lines
+ attr_reader :source_lines
+
# Parses the specified Slim code into a {Document}.
#
# @param source [String] Slim code to parse
# @param options [Hash]
# @option file [String] file name of document that was parsed
# @raise [Slim::Parser::Error] if there was a problem parsing the document
def initialize(source, options)
@config = options[:config]
- @file = options.fetch(:file, '(string)')
+ @file = options.fetch(:file, STRING_SOURCE)
process_source(source)
end
private
@@ -22,11 +38,11 @@
# @raise [Slim::Parser::Error] if there was a problem parsing the document
def process_source(source)
@source = strip_frontmatter(source)
@source_lines = @source.split("\n")
- @engine = SlimLint::Engine.new(file: @file)
- @sexp = @engine.call(source)
+ engine = SlimLint::Engine.new(file: @file)
+ @sexp = engine.parse(source)
end
# Removes YAML frontmatter
def strip_frontmatter(source)
if config['skip_frontmatter'] &&