Skip to content

Instantly share code, notes, and snippets.

@jargnar
Last active July 17, 2025 04:08
Show Gist options
  • Save jargnar/28e93f3f739a62f1224a27b9a684e21e to your computer and use it in GitHub Desktop.
Save jargnar/28e93f3f739a62f1224a27b9a684e21e to your computer and use it in GitHub Desktop.
A sublime syntax file hand crafted and tuned perfectly for Ruby on Rails
%YAML 1.2
---
name: TempleOfRails
file_extensions: [rb]
scope: source.ruby.rails
contexts:
main:
# comments
- match: '#.*$'
scope: comment.line.number-sign.ruby
# block comments
- match: '^\s*=begin\b'
scope: punctuation.definition.comment.ruby
push:
- meta_scope: comment.block.ruby
- match: '^\s*=end\b'
scope: punctuation.definition.comment.ruby
pop: true
# assignment ops
- match: (?<![=<>])=(?!=|>)
scope: keyword.operator.assignment.ruby
# comparison ops
- match: (?:===|==|!=|<=|>=|<=>|<|>)
scope: keyword.operator.comparison.ruby
# logical ops
- match: \b(?:and|or|not)\b|(?:&&|\|\||!)
scope: keyword.operator.logical.ruby
# function defs
- match: \bdef\b\s+(?:self\.)?([a-zA-Z_]\w*[!?=]?)
captures:
0: keyword.function.ruby
1: entity.name.function.ruby
# method calls
- match: (?<=\.)[a-zA-Z_]\w*[!?=]?
scope: variable.function.ruby
# class defs
- match: \bclass\b\s+([A-Z]\w*(?:::[A-Z]\w*)*)(?:\s*<\s*([A-Z]\w*(?:::[A-Z]\w*)*))?
captures:
0: keyword.class.ruby
1: entity.name.class.ruby
2: entity.other.inherited-class.ruby
# module defs
- match: \bmodule\b\s+([A-Z]\w*(?:::[A-Z]\w*)*)
captures:
0: keyword.module.ruby
1: entity.name.type.namespace.ruby
# some keywords
- match: \b(end|class|if|else|elsif|return|until|module|include|included|class_methods|extend|do|begin|rescue)\b
scope: keyword
# keywords like private
- match: \b(private)\b
scope: keyword.declaration.private.ruby
# symbols
- match: (?<!:):(?!:)([a-zA-Z_]\w*[!?=]?)
captures:
0: punctuation.definition.constant.ruby
1: constant.other.symbol.ruby
# hash keys
- match: (?<!:)\b([a-zA-Z_]\w*[!?=]?)(:)(?!:)
captures:
1: variable.parameter.tag.key.ruby
2: punctuation.separator.key-value.ruby
# strings
- match: '"'
push: string
# basic numerals
- match: (?<!\.)\b\d(?:_?\d)*(?:\.\d(?:_?\d)*)?(?:[eE][+-]?\d(?:_?\d)*)?\b
scope: constant.numeric.ruby
# Rails helpers (only some for now, to do: add all)
- match: \b(after_action|append_after_action|prepend_after_action|around_action|append_around_action|prepend_around_action|before_action|append_before_action|prepend_before_action|skip_after_action|skip_around_action|skip_before_action)\b
scope: support.function.rails.callback.ruby
- match: \b(render|redirect_to)\b
scope: support.function.rails.response.ruby
- match: \b(expires_in|fresh_when|stale)\b
scope: support.function.rails.caching.ruby
- match: \b(allow_browser)\b
scope: support.function.rails.browser-guard.ruby
- match: \b(helper_method)\b
scope: support.function.rails.helper.ruby
string:
- meta_scope: string.quoted.double.ruby
- match: \\.
scope: constant.character.escape.ruby
- match: '"'
pop: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment