Skip to content

Commit

Permalink
Add the rest of package
Browse files Browse the repository at this point in the history
  • Loading branch information
retgoat committed Jan 27, 2016
1 parent fa4363e commit f9ce46b
Show file tree
Hide file tree
Showing 13 changed files with 507 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pyc
*.cache
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 0.0.1

* Package released
194 changes: 194 additions & 0 deletions ESpec.tmLanguage
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array>
<string>exs</string>
</array>
<key>foldingStartMarker</key>
<string>(?x)^
(\s*+
(module|class|def
|background|feature|subscribe
|before|describe|it|scenario
|unless|if
|case
|begin
|for|while|until
|^=begin
|( "(\\.|[^"])*+" # eat a double quoted string
| '(\\.|[^'])*+' # eat a single quoted string
| [^#"'] # eat all but comments and strings
)*
( \s (do|begin|case)
| (?&lt;!\$)[-+=&amp;|*/~%^&lt;&gt;~] \s*+ (if|unless)
)
)\b
(?! [^;]*+ ; .*? \bend\b )
|( "(\\.|[^"])*+" # eat a double quoted string
| '(\\.|[^'])*+' # eat a single quoted string
| [^#"'] # eat all but comments and strings
)*
( \{ (?! [^}]*+ \} )
| \[ (?! [^\]]*+ \] )
)
).*$
| [#] .*? \(fold\) \s*+ $ # Sune’s special marker
</string>
<key>foldingStopMarker</key>
<string>(?x)
( (^|;) \s*+ end \s*+ ([#].*)? $
| (^|;) \s*+ end \. .* $
| ^ \s*+ [}\]] \s*+ ([#].*)? $
| [#] .*? \(end\) \s*+ $ # Sune’s special marker
| ^=end
)</string>
<key>keyEquivalent</key>
<string>^~R</string>
<key>name</key>
<string>ESpec</string>
<key>patterns</key>
<array>
<dict>
<key>match</key>
<string>(?&lt;!\.)\b(before\b|after\b|subject\b!?|let\b!?)</string>
<key>name</key>
<string>keyword.other.espec</string>
</dict>
<dict>
<key>include</key>
<string>#behaviour</string>
</dict>
<dict>
<key>include</key>
<string>#single-line-example</string>
</dict>
<dict>
<key>include</key>
<string>#pending</string>
</dict>
<dict>
<key>include</key>
<string>#example</string>
</dict>
<dict>
<key>include</key>
<string>source.elixir</string>
</dict>
</array>
<key>repository</key>
<dict>
<key>behaviour</key>
<dict>
<key>begin</key>
<string>^\s*(?:(ESpec)\.)?(describe|context|feature)\b</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>support.class.elixir</string>
</dict>
<key>2</key>
<dict>
<key>name</key>
<string>keyword.other.espec.behaviour</string>
</dict>
</dict>
<key>end</key>
<string>\b(do(?=\s*$))|{</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.elixir.start-block</string>
</dict>
</dict>
<key>name</key>
<string>meta.espec.behaviour</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.elixir</string>
</dict>
</array>
</dict>
<key>example</key>
<dict>
<key>begin</key>
<string>^\s*(it|specify|scenario)\b</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.espec.example</string>
</dict>
</dict>
<key>end</key>
<string>\b(do(?=\s*$))|{</string>
<key>endCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.control.elixir.start-block</string>
</dict>
</dict>
<key>name</key>
<string>meta.espec.example</string>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.elixir</string>
</dict>
</array>
</dict>
<key>pending</key>
<dict>
<key>begin</key>
<string>^\s*(it|specify|scenario)\b(?=((?!do|{).)*$)</string>
<key>end</key>
<string>$</string>
<key>beginCaptures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.espec.pending</string>
</dict>
</dict>
<key>patterns</key>
<array>
<dict>
<key>include</key>
<string>source.elixir</string>
</dict>
</array>
<key>name</key>
<string>meta.espec.pending</string>
</dict>
<key>single-line-example</key>
<dict>
<key>captures</key>
<dict>
<key>1</key>
<dict>
<key>name</key>
<string>keyword.other.espec.example</string>
</dict>
</dict>
<key>match</key>
<string>^\s*(it|specify|scenario)\s*{</string>
</dict>
</dict>
<key>scopeName</key>
<string>source.elixir.espec</string>
<key>uuid</key>
<string>923F0A10-96B9-4792-99A4-94FEF66E0B8C</string>
</dict>
</plist>
90 changes: 90 additions & 0 deletions ESpecCreateModule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import sublime, sublime_plugin, time
import re

from textwrap import dedent
from ESpec.shared import other_group_in_pair


def snake_case(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()


class GotoLineCommand(sublime_plugin.TextCommand):

def run(self, edit, line, column=0):
pt = self.view.text_point(line - 1, column)

self.view.sel().clear()
self.view.sel().add(sublime.Region(pt))

self.view.show(pt)


class EspecNewModuleCommand(sublime_plugin.TextCommand):

def run(self, edit, name, namespace):
class_template = dedent('''
class {name}
end
'''.lstrip('\n').rstrip(' \n').format(name=name))

module_template = dedent('''
module {module}
{definition}
end
'''.lstrip('\n').rstrip(' \n'))

template, level = class_template, len(namespace)

while namespace:
module = namespace.pop()
template = module_template.format(module=module, definition=self.indent(template))

self.view.insert(edit, 0, template)
self.view.run_command('goto_line', { 'line': 2 + level, 'column': level * 2 })

def indent(self, text, space=2):
return '\n'.join(' ' * space + line for line in text.split('\n'))


class EspecNewSpecCommand(sublime_plugin.TextCommand):

def run(self, edit, name):
template = dedent('''
require 'spec_helper'
describe {name} do
end
'''.strip('\n').format(name=name))

self.view.insert(edit, 0, template)
self.view.run_command('goto_line', { 'line': 4 })


class EspecCreateModuleCommand(sublime_plugin.WindowCommand):

def run(self):
self.window.show_input_panel("Enter module name:", "", self.on_done, None, None)

def on_done(self, text):
if not text: return

*namespace, name = re.split(r'/|::', text.strip(' _/'))

# create the module
module = self.window.new_file()
module.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
module.set_name(snake_case(name) + '.rb')

module.run_command('rspec_new_module', { 'name': name, 'namespace': namespace })

# create the spec
spec = self.window.new_file()
self.window.run_command('move_to_group', { 'group': other_group_in_pair(self.window) })
spec.set_syntax_file('Packages/Ruby/Ruby.tmLanguage')
spec.set_name(snake_case(name) + '_spec.rb')

spec.run_command('rspec_new_spec', { 'name': '::'.join(namespace + [name]) })
26 changes: 26 additions & 0 deletions ESpecDetectFileType.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sublime, sublime_plugin
import os

class ESpecDetectFileTypeCommand(sublime_plugin.EventListener):
'''
Detects current file type if the file's extension
'''

def on_load(self, view):
filename = view.file_name()

if not filename: return # not saved

name = os.path.basename(filename.lower())
if name.endswith("_spec.exs"):
set_syntax(view, "ESpec")
elif name == "factories.exs":
set_syntax(view, "ESpec")


def set_syntax(view, syntax, path=None):
if path is None:
path = syntax

view.settings().set('syntax', 'Packages/'+ path + '/' + syntax + '.tmLanguage')
print("Switched syntax to: " + syntax)
Loading

0 comments on commit f9ce46b

Please sign in to comment.