better_html 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9b3e15933b5788d810377d49068228464e17fa3
4
- data.tar.gz: 18c03ea104454fec79e3a9dd8cf29d5ec83f8adb
3
+ metadata.gz: 32b2be796cb45394207282b6a25e8693d1ce3f97
4
+ data.tar.gz: 476a5f910d219388ae59fce6d659a42c39592b7c
5
5
  SHA512:
6
- metadata.gz: f93049ef7e686b1c1419d05f86c6240bed8e18016b2e186b6b813d9760fd0662b6db83de4ba5cf18e9b1d4c0716ae358cf25d49b4e0f695ac9866b0506e527e4
7
- data.tar.gz: f6c7e9af3e8f72269321f954982313fcf907b44a40a97fd3509239d73252b0c87d418e677cb8e7392789b7f658bb73f556a43ffdc18ab4a76d83fc38cbf8f8dd
6
+ metadata.gz: e1db514d84e7fd2ba2f6af76afeb01ca1dfd386d98b4c0cf969046e7ab48b4359a3c6697e38836db7722916a250dd716e5e477376981c9b711f48dd435626990
7
+ data.tar.gz: 9cc7b477585bdb26bedc4ee9858e8a1b02d0ba9fdbc19f4dc602049bbc6ae359429443cd3ea0939da4913165042df6d49c781980436c04514e19bc4d1521f116
@@ -9,6 +9,16 @@ module BetterHtml
9
9
  class Parser
10
10
  attr_reader :template_language
11
11
 
12
+ class Error < HtmlError
13
+ attr_reader :location
14
+ alias_method :loc, :location
15
+
16
+ def initialize(message, location:)
17
+ super(message)
18
+ @location = location
19
+ end
20
+ end
21
+
12
22
  def initialize(document, template_language: :html)
13
23
  @document = document
14
24
  @template_language = template_language
@@ -33,6 +43,15 @@ module BetterHtml
33
43
  @ast ||= build_document_node
34
44
  end
35
45
 
46
+ def parser_errors
47
+ @erb.parser.errors.map do |error|
48
+ Error.new(
49
+ error.message,
50
+ location: Tokenizer::Location.new(@document, error.position, error.position + 1)
51
+ )
52
+ end
53
+ end
54
+
36
55
  def inspect
37
56
  "#<#{self.class.name} ast=#{ast.inspect}>"
38
57
  end
@@ -1,3 +1,3 @@
1
1
  module BetterHtml
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -12,6 +12,18 @@ module BetterHtml
12
12
  assert_equal s(:document), tree.ast
13
13
  end
14
14
 
15
+ test "parser errors" do
16
+ tree = Parser.new('<>')
17
+
18
+ assert_equal 1, tree.parser_errors.size
19
+ assert_equal "expected '/' or tag name", tree.parser_errors[0].message
20
+ assert_equal 1..2, tree.parser_errors[0].location.range
21
+ assert_equal <<~EOF.strip, tree.parser_errors[0].location.line_source_with_underline
22
+ <>
23
+ ^
24
+ EOF
25
+ end
26
+
15
27
  test "consume cdata nodes" do
16
28
  code = "<![CDATA[ foo ]]>"
17
29
  tree = Parser.new(code)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_html
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francois Chagnon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-22 00:00:00.000000000 Z
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ast
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.0.5
103
+ version: 0.0.6
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.0.5
110
+ version: 0.0.6
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement