Skip to content

Commit

Permalink
Add support for embedded Ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Nov 22, 2020
1 parent 42ec554 commit 3a2a4a8
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 2 deletions.
151 changes: 151 additions & 0 deletions eclipse-solargraph-plugin/grammar/erb.tmLanguage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"name": "HTML (Ruby - ERB)",
"scopeName": "text.html.erb",
"fileTypes": ["rhtml", "html.erb"],
"injections": {
"text.html.erb - (meta.embedded.block.erb | meta.embedded.line.erb | meta.tag | comment), L:meta.tag, L:source.js.embedded.html": {
"patterns": [
{
"begin": "(^\\s*)(?=<%+#(?![^%]*%>))",
"beginCaptures": {
"0": {
"name": "punctuation.whitespace.comment.leading.erb"
}
},
"end": "(?!\\G)(\\s*$\\n)?",
"endCaptures": {
"0": {
"name": "punctuation.whitespace.comment.trailing.erb"
}
},
"patterns": [
{
"include": "#comment"
}
]
},
{
"begin": "(^\\s*)(?=<%(?![^%]*%>))",
"beginCaptures": {
"0": {
"name": "punctuation.whitespace.embedded.leading.erb"
}
},
"end": "(?!\\G)(\\s*$\\n)?",
"endCaptures": {
"0": {
"name": "punctuation.whitespace.embedded.trailing.erb"
}
},
"patterns": [
{
"include": "#tags"
}
]
},
{
"include": "#comment"
},
{
"include": "#tags"
}
]
}
},
"patterns": [
{
"include": "text.html.basic"
}
],
"repository": {
"comment": {
"patterns": [
{
"begin": "<%+#",
"beginCaptures": {
"0": {
"name": "punctuation.definition.comment.begin.erb"
}
},
"end": "%>",
"endCaptures": {
"0": {
"name": "punctuation.definition.comment.end.erb"
}
},
"name": "comment.block.erb"
}
]
},
"tags": {
"patterns": [
{
"begin": "<%+(?!>)[-=]?(?![^%]*%>)",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.erb"
}
},
"contentName": "source.ruby.embedded.erb",
"end": "-?%>",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.end.erb"
},
"1": {
"name": "source.ruby"
}
},
"name": "meta.embedded.block.erb",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erb"
}
},
"match": "(#).*?(?=-?%>)",
"name": "comment.line.number-sign.erb"
},
{
"include": "source.ruby"
}
]
},
{
"begin": "<%+(?!>)[-=]?",
"beginCaptures": {
"0": {
"name": "punctuation.section.embedded.begin.erb"
}
},
"contentName": "source.ruby.embedded.erb",
"end": "-?%>",
"endCaptures": {
"0": {
"name": "punctuation.section.embedded.end.erb"
},
"1": {
"name": "source.ruby"
}
},
"name": "meta.embedded.line.erb",
"patterns": [
{
"captures": {
"1": {
"name": "punctuation.definition.comment.erb"
}
},
"match": "(#).*?(?=-?%>)",
"name": "comment.line.number-sign.erb"
},
{
"include": "source.ruby"
}
]
}
]
}
}
}
Binary file added eclipse-solargraph-plugin/icon/erb-editor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"comments": {
"blockComment": [ "<%#", "%>" ]
},
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"],
["<", ">"]
],
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["`", "`"],
["<", ">"],
["%", "%"]
],
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"],
["`", "`"],
["<", ">"],
["%", "%"]
]
}
44 changes: 42 additions & 2 deletions eclipse-solargraph-plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
name="Gemfile"
priority="high">
</content-type>
<content-type
base-type="org.eclipse.core.runtime.text"
file-extensions="erb,rhtml,rhtm"
id="io.github.pyvesb.eclipse_solargraph.erb"
name="Embedded Ruby"
priority="high">
</content-type>
</extension>
<extension
point="org.eclipse.ui.editors">
Expand All @@ -42,6 +49,10 @@
contentTypeId="io.github.pyvesb.eclipse_solargraph.gemfile"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
<editorContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
editorId="org.eclipse.ui.genericeditor.GenericEditor">
</editorContentTypeBinding>
</extension>
<extension
point="org.eclipse.lsp4e.languageServer">
Expand All @@ -58,6 +69,10 @@
contentType="io.github.pyvesb.eclipse_solargraph.gemfile"
id="io.github.pyvesb.eclipse_solargraph">
</contentTypeMapping>
<contentTypeMapping
contentType="io.github.pyvesb.eclipse_solargraph.erb"
id="io.github.pyvesb.eclipse_solargraph">
</contentTypeMapping>
</extension>
<extension
point="org.eclipse.tm4e.registry.grammars">
Expand All @@ -69,6 +84,10 @@
path="grammar/gemfile.tmLanguage.json"
scopeName="source.ruby.gemfile">
</grammar>
<grammar
path="grammar/erb.tmLanguage.json"
scopeName="text.html.erb">
</grammar>
<scopeNameContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph"
scopeName="source.ruby">
Expand All @@ -77,6 +96,10 @@
contentTypeId="io.github.pyvesb.eclipse_solargraph.gemfile"
scopeName="source.ruby.gemfile">
</scopeNameContentTypeBinding>
<scopeNameContentTypeBinding
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
scopeName="text.html.erb">
</scopeNameContentTypeBinding>
</extension>
<extension
point="org.eclipse.ui.genericeditor.presentationReconcilers">
Expand All @@ -88,6 +111,10 @@
class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
contentType="io.github.pyvesb.eclipse_solargraph.gemfile">
</presentationReconciler>
<presentationReconciler
class="org.eclipse.tm4e.ui.text.TMPresentationReconciler"
contentType="io.github.pyvesb.eclipse_solargraph.erb">
</presentationReconciler>
</extension>
<extension
point="org.eclipse.ui.genericeditor.icons">
Expand All @@ -99,16 +126,24 @@
icon="icon/ruby-editor.png"
contentType="io.github.pyvesb.eclipse_solargraph.gemfile">
</icon>
<icon
icon="icon/erb-editor.png"
contentType="io.github.pyvesb.eclipse_solargraph.erb">
</icon>
</extension>
<extension
point="org.eclipse.tm4e.languageconfiguration.languageConfigurations">
<languageConfiguration
contentTypeId="io.github.pyvesb.eclipse_solargraph"
path="language-configuration/language-configuration.json">
path="language-configuration/ruby-configuration.json">
</languageConfiguration>
<languageConfiguration
contentTypeId="io.github.pyvesb.eclipse_solargraph.gemfile"
path="language-configuration/language-configuration.json">
path="language-configuration/ruby-configuration.json">
</languageConfiguration>
<languageConfiguration
contentTypeId="io.github.pyvesb.eclipse_solargraph.erb"
path="language-configuration/erb-configuration.json">
</languageConfiguration>
</extension>
<extension
Expand All @@ -123,6 +158,11 @@
path="snippet/Gemfile"
scopeName="source.ruby.gemfile">
</snippet>
<snippet
name="Embedded Ruby sample"
path="snippet/sample.erb"
scopeName="text.html.erb">
</snippet>
</extension>
<extension
point="org.eclipse.core.runtime.preferences">
Expand Down
6 changes: 6 additions & 0 deletions eclipse-solargraph-plugin/snippet/sample.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<p>Hello, <%= user.first_name %>.</p>
</body>
</html>

0 comments on commit 3a2a4a8

Please sign in to comment.