Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize bundle: rewrite grammar and add new commands/snippets. #63

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
<key>command</key>
<string>#!/usr/bin/env ruby18

require "#{ENV['TM_BUNDLE_SUPPORT']}/jsmate"
require "#{ENV['TM_BUNDLE_SUPPORT']}/documentation"

JavaScript::documentationForWord
</string>
Documentation::open_page_for(STDIN.read)</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
Expand Down
2 changes: 1 addition & 1 deletion Commands/Reformat Document : Selection.tmCommand
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env python
<string>#!/usr/bin/env python3

import os
import sys
Expand Down
30 changes: 30 additions & 0 deletions Commands/Run in Node.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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>beforeRunningCommand</key>
<string>saveModifiedFiles</string>
<key>command</key>
<string>#!/bin/bash

[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] &amp;&amp; . "${TM_SUPPORT_PATH}/lib/bash_init.sh"

"${TM_BUNDLE_SUPPORT}/run_script.sh"</string>
<key>input</key>
<string>document</string>
<key>keyEquivalent</key>
<string>@r</string>
<key>name</key>
<string>Run in Node</string>
<key>outputCaret</key>
<string>heuristic</string>
<key>outputFormat</key>
<string>html</string>
<key>outputLocation</key>
<string>newWindow</string>
<key>scope</key>
<string>source.js</string>
<key>uuid</key>
<string>F20780A9-CE3A-41D5-99B8-F5183AB54A98</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Preferences/Comments.tmPreferences
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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>name</key>
<string>Indentation: Disable Inside Template Strings</string>
<key>scope</key>
<string>source.js string.quoted.other.template</string>
<key>settings</key>
<dict>
<key>disableIndentCorrections</key>
<true/>
</dict>
<key>uuid</key>
<string>A3DD3386-DDBA-4837-B80E-06FBC7A3FD68</string>
</dict>
</plist>
19 changes: 19 additions & 0 deletions Preferences/Symbol List: Functions.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>name</key>
<string>Symbol List: Functions</string>
<key>scope</key>
<string>source.js entity.name.function</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
<key>symbolTransformation</key>
<string>s/ / /</string>
</dict>
<key>uuid</key>
<string>C58AC81C-F47B-4E0C-B9C0-9CBA7F02C46C</string>
</dict>
</plist>
19 changes: 19 additions & 0 deletions Preferences/Symbol List: Methods.tmPreferences
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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>name</key>
<string>Symbol List: Methods</string>
<key>scope</key>
<string>source.js meta.class-method.js entity.name.function.js</string>
<key>settings</key>
<dict>
<key>showInSymbolList</key>
<integer>1</integer>
<key>symbolTransformation</key>
<string>s/^/#/</string>
</dict>
<key>uuid</key>
<string>C0ECB1FE-196C-4210-BB9F-207E59D9E429</string>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<plist version="1.0">
<dict>
<key>content</key>
<string>function ${1:functionName}($2) {
$0
<string>function ($1) {
${0:$TM_SELECTED_TEXT}
}</string>
<key>name</key>
<string>Function</string>
<string>Anonymous Function</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>fun</string>
<string>f</string>
<key>uuid</key>
<string>F0E4FB6A-4878-48C6-A777-62438DF1E14F</string>
<string>4C6EDB43-3E2E-411B-A016-13C135C59833</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Snippets/Object key — key: "value".tmSnippet
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions Snippets/debug.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>console.debug(${1:$TM_SELECTED_TEXT});</string>
<key>name</key>
<string>debug</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>debug</string>
<key>uuid</key>
<string>B09E67F5-ED9E-4C22-BFA4-ED61F0E4D3B3</string>
</dict>
</plist>
10 changes: 5 additions & 5 deletions Snippets/function.tmSnippet
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
<plist version="1.0">
<dict>
<key>content</key>
<string>function ($1) {
${0:$TM_SELECTED_TEXT}
<string>function ${1:functionName}($2) {
$0
}</string>
<key>name</key>
<string>Anonymous Function</string>
<string>Function</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>f</string>
<string>fun</string>
<key>uuid</key>
<string>4C6EDB43-3E2E-411B-A016-13C135C59833</string>
<string>F0E4FB6A-4878-48C6-A777-62438DF1E14F</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Snippets/getAttribute.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>getAttribute(${1:'${2:name}'})</string>
<key>name</key>
<string>getAttribute</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>get</string>
<key>uuid</key>
<string>13A083C2-1F73-4CD6-9982-BFBCC5EB58B0</string>
</dict>
</plist>
File renamed without changes.
16 changes: 16 additions & 0 deletions Snippets/import.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>import ${1:${2:library} from }${3:'${4:path}'};</string>
<key>name</key>
<string>import</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>imp</string>
<key>uuid</key>
<string>8F536653-6212-4A3A-ABF5-F47AC1ADAF21</string>
</dict>
</plist>
18 changes: 18 additions & 0 deletions Snippets/new Promise.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>content</key>
<string>new Promise((resolve, reject) =&gt; {
$0
});</string>
<key>name</key>
<string>new Promise</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>pro</string>
<key>uuid</key>
<string>89CEA10F-CB8E-45A2-A206-BD7EE8118791</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Snippets/querySelector.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>querySelector(${1:'${2:selector}'})</string>
<key>name</key>
<string>querySelector</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>qsa</string>
<key>uuid</key>
<string>29B39100-632C-498F-829A-CF0F71DE0B25</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Snippets/querySelectorAll.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>querySelectorAll(${1:'${2:selector}'})</string>
<key>name</key>
<string>querySelectorAll</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>qsa</string>
<key>uuid</key>
<string>29A152B6-8C5F-4BD3-82F2-EC7F21FA00A3</string>
</dict>
</plist>
16 changes: 16 additions & 0 deletions Snippets/require.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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>content</key>
<string>require(${1:'${2:library}'})</string>
<key>name</key>
<string>require</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>req</string>
<key>uuid</key>
<string>FC9298E3-8ED7-4868-8C91-E50755F37325</string>
</dict>
</plist>
18 changes: 18 additions & 0 deletions Snippets/then.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?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>content</key>
<string>then((${1:result}) =&gt; ${2:{
${0}
\}})</string>
<key>name</key>
<string>then</string>
<key>scope</key>
<string>source.js</string>
<key>tabTrigger</key>
<string>then</string>
<key>uuid</key>
<string>086ACC46-8307-4C69-B862-69302BFBBD66</string>
</dict>
</plist>
67 changes: 67 additions & 0 deletions Support/documentation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
require 'yaml'
require 'pp'

require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes"
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui"

module Documentation
HOST = "https://developer.mozilla.org/en-US/docs/Web"
YAML_PATH = "#{ENV['TM_BUNDLE_SUPPORT']}/index.yaml"

SEARCH_URL = 'https://developer.mozilla.org/en-US/search?topic=apps&topic=html&topic=css&topic=js&topic=api&topic=canvas&topic=svg&topic=webgl&topic=mobile&topic=webdev&topic=http&topic=webext&q='

class << self

def search_and_exit(token)
url = "#{SEARCH_URL}#{token}"
TextMate::exit_show_html(
"<meta http-equiv='Refresh' content='0;URL=#{url}'>"
)
end

def show_url_and_exit(url)
url = "#{HOST}#{url}"
TextMate::exit_show_html(
"<meta http-equiv='Refresh' content='0;URL=#{url}'>"
)
end

def reference(token)
@yaml ||= YAML::load( File.read(YAML_PATH) )
@yaml[token]
end

def open_page_for(token)
items = reference(token) || []

# If there are no matches, we just load a search results page for the
# token.
if items.size == 0
search_and_exit(token)
end

# Usually there will be only one option, so we can jump straight to it.
if items.size == 1
show_url_and_exit(items[0][:url])
end

# We have more than one possible match (e.g., `indexOf` or `slice`).
# Ask the user to pick one.
index = {}
choices = items.map do |item|
index[ item[:name] ] = item[:url]
item[:name]
end

choice = TextMate::UI.request_item(
:items => choices,
:title => 'Choose an Option'
)

# Did the user hit Cancel?
TextMate::exit_discard if choice.nil?

show_url_and_exit(index[choice])
end
end
end
Loading