hamlit 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/hamlit/parsers/script.rb +18 -1
- data/lib/hamlit/version.rb +1 -1
- data/spec/hamlit/engine/silent_script_spec.rb +21 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 930fc5e028d874b28cbf4c78e7d9434d3f41d73a
|
4
|
+
data.tar.gz: a8bab06e6c9d0f6af1da12913e843b8582ad778d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d7dc13fd325f3586af88a73214afc60f55392d67fa3dfbbe4f13d7a8a639cc2217eba60618c1db6f12eefa1eebaa23756a6ae9f8270df5400d5268b57de98ff
|
7
|
+
data.tar.gz: 8d028d23a2e55d4b3c923bc299a3d4aa02793da3826ad76a37f4b1829c291b62eb49da5f8dc3a0e26e9bc846bb1d99b2177a2493674ca7e1600db475bc45b8de
|
data/CHANGELOG.md
CHANGED
@@ -12,6 +12,10 @@ module Hamlit
|
|
12
12
|
|
13
13
|
INTERNAL_STATEMENTS = %w[else elsif rescue ensure when].freeze
|
14
14
|
DEFAULT_SCRIPT_OPTIONS = { force_escape: false, disable_escape: false }.freeze
|
15
|
+
PREFIX_BY_STATEMENT = {
|
16
|
+
'when' => 'case',
|
17
|
+
'rescue' => 'begin',
|
18
|
+
}.freeze
|
15
19
|
|
16
20
|
included do
|
17
21
|
include Concerns::Escapable
|
@@ -73,8 +77,11 @@ module Hamlit
|
|
73
77
|
end
|
74
78
|
|
75
79
|
def remove_comment(code, comment_check: false)
|
76
|
-
result
|
80
|
+
result = ''
|
77
81
|
with_comment = false
|
82
|
+
prefix = find_prefix(code)
|
83
|
+
code = "#{prefix}#{code}"
|
84
|
+
|
78
85
|
Ripper.lex(code).each do |(row, col), type, str|
|
79
86
|
if type == :on_comment
|
80
87
|
with_comment = true
|
@@ -82,11 +89,21 @@ module Hamlit
|
|
82
89
|
end
|
83
90
|
result += str
|
84
91
|
end
|
92
|
+
result = result.gsub(/\A#{prefix}/, '') if prefix
|
85
93
|
|
86
94
|
return [result, with_comment] if comment_check
|
87
95
|
result
|
88
96
|
end
|
89
97
|
|
98
|
+
# Code starting with `when` can't be properly understood by Ripper.lex.
|
99
|
+
# This method returns `case;` to fix that.
|
100
|
+
def find_prefix(code)
|
101
|
+
PREFIX_BY_STATEMENT.each do |statement, prefix|
|
102
|
+
return "#{prefix};" if code =~ /\A#{statement} /
|
103
|
+
end
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
90
107
|
def has_block?
|
91
108
|
next_indent == @current_indent + 1
|
92
109
|
end
|
data/lib/hamlit/version.rb
CHANGED
@@ -152,6 +152,16 @@ describe Hamlit::Engine do
|
|
152
152
|
HTML
|
153
153
|
end
|
154
154
|
|
155
|
+
it 'renders case-when with multiple candidates' do
|
156
|
+
assert_render(<<-'HAML', <<-HTML)
|
157
|
+
- case 'a'
|
158
|
+
- when 'a', 'b'
|
159
|
+
ok
|
160
|
+
HAML
|
161
|
+
ok
|
162
|
+
HTML
|
163
|
+
end
|
164
|
+
|
155
165
|
it 'renders begin-rescue' do
|
156
166
|
assert_render(<<-'HAML', <<-HTML)
|
157
167
|
- begin
|
@@ -166,6 +176,17 @@ describe Hamlit::Engine do
|
|
166
176
|
HTML
|
167
177
|
end
|
168
178
|
|
179
|
+
it 'renders rescue with error' do
|
180
|
+
assert_render(<<-'HAML', <<-HTML)
|
181
|
+
- begin
|
182
|
+
- raise 'error'
|
183
|
+
- rescue RuntimeError => e
|
184
|
+
hello
|
185
|
+
HAML
|
186
|
+
hello
|
187
|
+
HTML
|
188
|
+
end
|
189
|
+
|
169
190
|
it 'joins a next line if a current line ends with ","' do
|
170
191
|
assert_render("- foo = [', \n ']\n= foo", <<-HTML)
|
171
192
|
[", "]
|
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: 1.4.
|
4
|
+
version: 1.4.3
|
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-
|
11
|
+
date: 2015-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -569,3 +569,4 @@ test_files:
|
|
569
569
|
- spec/rails/vendor/assets/javascripts/.keep
|
570
570
|
- spec/rails/vendor/assets/stylesheets/.keep
|
571
571
|
- spec/spec_helper.rb
|
572
|
+
has_rdoc:
|