From 4ad2962050eac05d16c8619da67eef062f0e6fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 17 Nov 2015 23:56:39 -0300 Subject: [PATCH 1/4] :bug: Fix closing erb tag being considered two separate tokens --- grammars/html (ruby - erb).cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/html (ruby - erb).cson b/grammars/html (ruby - erb).cson index e353422..5f35656 100644 --- a/grammars/html (ruby - erb).cson +++ b/grammars/html (ruby - erb).cson @@ -72,7 +72,7 @@ '0': 'name': 'punctuation.section.embedded.begin.erb' 'contentName': 'source.ruby' - 'end': '(-?%)>' + 'end': '-?%>' 'endCaptures': '0': 'name': 'punctuation.section.embedded.end.erb' @@ -98,7 +98,7 @@ '0': 'name': 'punctuation.section.embedded.begin.erb' 'contentName': 'source.ruby' - 'end': '(-?%)>' + 'end': '-?%>' 'endCaptures': '0': 'name': 'punctuation.section.embedded.end.erb' From b47363f3de8dd73639b67b8dad9adec0edb54fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Tue, 17 Nov 2015 23:58:20 -0300 Subject: [PATCH 2/4] :bug: Fix embedded ruby tokens being marked as plain ruby tokens --- grammars/html (ruby - erb).cson | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grammars/html (ruby - erb).cson b/grammars/html (ruby - erb).cson index 5f35656..89eff1b 100644 --- a/grammars/html (ruby - erb).cson +++ b/grammars/html (ruby - erb).cson @@ -71,7 +71,7 @@ 'beginCaptures': '0': 'name': 'punctuation.section.embedded.begin.erb' - 'contentName': 'source.ruby' + 'contentName': 'source.ruby.embedded' 'end': '-?%>' 'endCaptures': '0': @@ -97,7 +97,7 @@ 'beginCaptures': '0': 'name': 'punctuation.section.embedded.begin.erb' - 'contentName': 'source.ruby' + 'contentName': 'source.ruby.embedded' 'end': '-?%>' 'endCaptures': '0': From 1f52f8e4a931a51e8a503a697a176a922562792f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 18 Nov 2015 00:00:57 -0300 Subject: [PATCH 3/4] :white_check_mark: Add basic tests for HTML (Ruby - ERB) grammar --- spec/ruby-spec.coffee | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/spec/ruby-spec.coffee b/spec/ruby-spec.coffee index b2a817c..3b25275 100644 --- a/spec/ruby-spec.coffee +++ b/spec/ruby-spec.coffee @@ -532,3 +532,30 @@ describe "Ruby grammar", -> expect(tokens[6]).toEqual value: 'Array#[](0), Array', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.yard.ruby', 'comment.line.type.yard.ruby'] expect(tokens[7]).toEqual value: ']', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.yard.ruby', 'comment.line.type.yard.ruby', 'comment.line.punctuation.yard.ruby'] expect(tokens[8]).toEqual value: ' comment', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.string.yard.ruby'] + +describe "HTML (Ruby - ERB) grammar", -> + grammar = null + + beforeEach -> + waitsForPromise -> + atom.packages.activatePackage("language-ruby") + + runs -> + grammar = atom.grammars.grammarForScopeName("text.html.erb") + + it "parses the grammar", -> + expect(grammar).toBeTruthy() + expect(grammar.scopeName).toBe "text.html.erb" + + it "tokenizes embedded ruby", -> + {tokens} = grammar.tokenizeLine('<%= self %>') + expect(tokens[0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.begin.erb'] + expect(tokens[1]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded'] + expect(tokens[2]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded', 'variable.language.self.ruby'] + expect(tokens[3]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded'] + expect(tokens[4]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.end.erb'] + + lines = grammar.tokenizeLines('<%=\nself\n%>') + expect(lines[0][0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.begin.erb'] + expect(lines[1][0]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'source.ruby.embedded', 'variable.language.self.ruby'] + expect(lines[2][0]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.end.erb'] From 8ac99d901d8affdc7617dc67487b7b1386f8af85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Wed, 18 Nov 2015 00:22:03 -0300 Subject: [PATCH 4/4] :art: Improve code structure and consistency --- grammars/html (ruby - erb).cson | 4 ++-- spec/erb-spec.coffee | 26 ++++++++++++++++++++++++++ spec/ruby-spec.coffee | 27 --------------------------- 3 files changed, 28 insertions(+), 29 deletions(-) create mode 100644 spec/erb-spec.coffee diff --git a/grammars/html (ruby - erb).cson b/grammars/html (ruby - erb).cson index 89eff1b..64a8b9b 100644 --- a/grammars/html (ruby - erb).cson +++ b/grammars/html (ruby - erb).cson @@ -71,7 +71,7 @@ 'beginCaptures': '0': 'name': 'punctuation.section.embedded.begin.erb' - 'contentName': 'source.ruby.embedded' + 'contentName': 'source.ruby.embedded.erb' 'end': '-?%>' 'endCaptures': '0': @@ -97,7 +97,7 @@ 'beginCaptures': '0': 'name': 'punctuation.section.embedded.begin.erb' - 'contentName': 'source.ruby.embedded' + 'contentName': 'source.ruby.embedded.erb' 'end': '-?%>' 'endCaptures': '0': diff --git a/spec/erb-spec.coffee b/spec/erb-spec.coffee new file mode 100644 index 0000000..83b987b --- /dev/null +++ b/spec/erb-spec.coffee @@ -0,0 +1,26 @@ +describe "HTML (Ruby - ERB) grammar", -> + grammar = null + + beforeEach -> + waitsForPromise -> + atom.packages.activatePackage("language-ruby") + + runs -> + grammar = atom.grammars.grammarForScopeName("text.html.erb") + + it "parses the grammar", -> + expect(grammar).toBeTruthy() + expect(grammar.scopeName).toBe "text.html.erb" + + it "tokenizes embedded ruby", -> + {tokens} = grammar.tokenizeLine('<%= self %>') + expect(tokens[0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.begin.erb'] + expect(tokens[1]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb'] + expect(tokens[2]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb', 'variable.language.self.ruby'] + expect(tokens[3]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded.erb'] + expect(tokens[4]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.end.erb'] + + lines = grammar.tokenizeLines('<%=\nself\n%>') + expect(lines[0][0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.begin.erb'] + expect(lines[1][0]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'source.ruby.embedded.erb', 'variable.language.self.ruby'] + expect(lines[2][0]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.end.erb'] diff --git a/spec/ruby-spec.coffee b/spec/ruby-spec.coffee index 3b25275..b2a817c 100644 --- a/spec/ruby-spec.coffee +++ b/spec/ruby-spec.coffee @@ -532,30 +532,3 @@ describe "Ruby grammar", -> expect(tokens[6]).toEqual value: 'Array#[](0), Array', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.yard.ruby', 'comment.line.type.yard.ruby'] expect(tokens[7]).toEqual value: ']', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.yard.ruby', 'comment.line.type.yard.ruby', 'comment.line.punctuation.yard.ruby'] expect(tokens[8]).toEqual value: ' comment', scopes: ['source.ruby', 'comment.line.number-sign.ruby', 'comment.line.string.yard.ruby'] - -describe "HTML (Ruby - ERB) grammar", -> - grammar = null - - beforeEach -> - waitsForPromise -> - atom.packages.activatePackage("language-ruby") - - runs -> - grammar = atom.grammars.grammarForScopeName("text.html.erb") - - it "parses the grammar", -> - expect(grammar).toBeTruthy() - expect(grammar.scopeName).toBe "text.html.erb" - - it "tokenizes embedded ruby", -> - {tokens} = grammar.tokenizeLine('<%= self %>') - expect(tokens[0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.begin.erb'] - expect(tokens[1]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded'] - expect(tokens[2]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded', 'variable.language.self.ruby'] - expect(tokens[3]).toEqual value: ' ', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'source.ruby.embedded'] - expect(tokens[4]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.line.erb', 'punctuation.section.embedded.end.erb'] - - lines = grammar.tokenizeLines('<%=\nself\n%>') - expect(lines[0][0]).toEqual value: '<%=', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.begin.erb'] - expect(lines[1][0]).toEqual value: 'self', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'source.ruby.embedded', 'variable.language.self.ruby'] - expect(lines[2][0]).toEqual value: '%>', scopes: ['text.html.erb', 'meta.embedded.block.erb', 'punctuation.section.embedded.end.erb']