hamlit 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hamlit/concerns/error.rb +4 -0
- data/lib/hamlit/concerns/indentable.rb +35 -0
- data/lib/hamlit/parser.rb +3 -0
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/error_spec.rb +9 -0
- data/spec/hamlit/engine/indent_spec.rb +14 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cd8171af3715df926bcc809abc6bac110e99fb1
|
4
|
+
data.tar.gz: 94789c593c71581ff6d36ed947914acee93e5e6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32471cca6c6628befa00c74685089ebac83cdde4497f51e2ba103d41a2657e925ca1360792d24c054b578fbfa091738d42848707b873811a9dcc4dc8800e6b7f
|
7
|
+
data.tar.gz: 082bf0f71595fe4c730a747f197665d5a17944ce738d8bbc9c427cdd21746a6a263a1115f56b4c474523e477f9dc6aeb23d1ba1bf71db4b726ffc3330b19836d
|
@@ -48,6 +48,41 @@ module Hamlit
|
|
48
48
|
return false unless line
|
49
49
|
count_indent(line) == @current_indent
|
50
50
|
end
|
51
|
+
|
52
|
+
# Validate the template is using consitent indentation, 2 spaces or a tab.
|
53
|
+
def validate_indentation!(template)
|
54
|
+
last_indent = ''
|
55
|
+
|
56
|
+
indents = template.scan(/^[ \t]+/)
|
57
|
+
indents.each do |indent|
|
58
|
+
if last_indent.include?(' ') && indent.include?("\t") ||
|
59
|
+
last_indent.include?("\t") && indent.include?(' ')
|
60
|
+
syntax_error!(%Q{Inconsistent indentation: #{indent_label(indent)} used for indentation, but the rest of the document was indented using #{indent_label(last_indent)}.})
|
61
|
+
end
|
62
|
+
|
63
|
+
last_indent = indent
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def indent_label(indent)
|
68
|
+
return %Q{"#{indent}"} if indent.include?(' ') && indent.include?("\t")
|
69
|
+
|
70
|
+
label = indent.include?(' ') ? 'space' : 'tab'
|
71
|
+
length = indent.match(/[ \t]+/).to_s.length
|
72
|
+
|
73
|
+
"#{length} #{label}#{'s' if length > 1}"
|
74
|
+
end
|
75
|
+
|
76
|
+
# Replace hard tabs into 2 spaces
|
77
|
+
def replace_hard_tabs(template)
|
78
|
+
lines = []
|
79
|
+
template.each_line do |line|
|
80
|
+
lines << line.gsub(/^\t+/) do |match|
|
81
|
+
' ' * (match.length * 2)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
lines.join
|
85
|
+
end
|
51
86
|
end
|
52
87
|
end
|
53
88
|
end
|
data/lib/hamlit/parser.rb
CHANGED
@@ -39,7 +39,10 @@ module Hamlit
|
|
39
39
|
|
40
40
|
# Reset the parser state.
|
41
41
|
def reset(template)
|
42
|
+
validate_indentation!(template)
|
43
|
+
template = replace_hard_tabs(template)
|
42
44
|
template = preprocess_multilines(template)
|
45
|
+
|
43
46
|
reset_lines(template.split("\n"))
|
44
47
|
reset_indent
|
45
48
|
reset_outer_removal
|
data/lib/hamlit/version.rb
CHANGED
@@ -43,5 +43,14 @@ describe Hamlit::Engine do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
it 'raises syntax error for an inconsistent indentation' do
|
48
|
+
expect { render_string(<<-HAML.unindent) }.
|
49
|
+
%a
|
50
|
+
%b
|
51
|
+
\t\t%b
|
52
|
+
HAML
|
53
|
+
to raise_error(Hamlit::SyntaxError, 'Inconsistent indentation: 2 tabs used for indentation, but the rest of the document was indented using 2 spaces.')
|
54
|
+
end
|
46
55
|
end
|
47
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|
@@ -361,6 +361,7 @@ files:
|
|
361
361
|
- spec/hamlit/engine/comment_spec.rb
|
362
362
|
- spec/hamlit/engine/doctype_spec.rb
|
363
363
|
- spec/hamlit/engine/error_spec.rb
|
364
|
+
- spec/hamlit/engine/indent_spec.rb
|
364
365
|
- spec/hamlit/engine/multiline_spec.rb
|
365
366
|
- spec/hamlit/engine/new_attribute_spec.rb
|
366
367
|
- spec/hamlit/engine/old_attributes_spec.rb
|
@@ -474,6 +475,7 @@ test_files:
|
|
474
475
|
- spec/hamlit/engine/comment_spec.rb
|
475
476
|
- spec/hamlit/engine/doctype_spec.rb
|
476
477
|
- spec/hamlit/engine/error_spec.rb
|
478
|
+
- spec/hamlit/engine/indent_spec.rb
|
477
479
|
- spec/hamlit/engine/multiline_spec.rb
|
478
480
|
- spec/hamlit/engine/new_attribute_spec.rb
|
479
481
|
- spec/hamlit/engine/old_attributes_spec.rb
|