├── images └── joomla.png ├── .gitignore ├── CHANGELOG.md ├── src ├── README_top.md ├── README_bottom.md ├── snippets.json └── snippets-review.json ├── LICENSE.md ├── package.json ├── README.md └── snippets └── php.json /images/joomla.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anibalsanchez/VSCode-Joomla-Snippets/HEAD/images/joomla.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .editorconfig 2 | .eslintrc.json 3 | .gitkeep 4 | .jsbeautifyrc 5 | .jshintrc 6 | .markdownlint.json 7 | .vscode 8 | *.vsix 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.0.5 4 | 5 | - Minor PR doc tweak. 6 | 7 | ## 0.0.4 8 | 9 | - Many tweaks and first published version. 10 | 11 | ## 0.0.1 12 | 13 | - Creating Snippets 14 | -------------------------------------------------------------------------------- /src/README_top.md: -------------------------------------------------------------------------------- 1 | # VSCode Joomla Snippets 2 | 3 | Visual Studio Code Joomla snippets and code examples for Joomla 3 & 4 Alpha. 4 | 5 | All code snippets are based on and follow the Joomla style guide . 6 | 7 | ## Snippet Prefixes 8 | 9 | | Prefix | Description | 10 | | ------- | ----------| 11 | | j- | Joomla Snippets | 12 | | j4- | Joomla 4 Alpha Snippets | 13 | | jdoc- | Snippets for Templates | 14 | 15 | ## Usage 16 | 17 | All Joomla snippets starts with "j-", "j4-", or "jdoc-". 18 | 19 | ## Joomla Snippets 20 | 21 | | Snippet | Description | 22 | | ------- | ----------| 23 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2018 Anibal Sanchez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/README_bottom.md: -------------------------------------------------------------------------------- 1 | 2 | ## Installation (Mac) 3 | 4 | 1. Launch VS Code 5 | 1. Quick Open (⌘+P) 6 | 1. Enter the following command and press enter: 'ext install vs-code-joomla-snippets' 7 | 1. Choose extension (Author: AnibalSanchez) 8 | 1. Reload VS Code 9 | 10 | ## Installation (Windows, Linux) 11 | 12 | 1. Launch VS Code 13 | 1. Quick Open (Ctrl-Shift-P) 14 | 1. Enter the following command and press enter: 'ext install vs-code-joomla-snippets' 15 | 1. Choose extension (Author: AnibalSanchez) 16 | 1. Reload VS Code 17 | 18 | ## Emmets 19 | 20 | If you want intellisense to show emmets before the snippets, you can force the emmets suggestions to show up at the top, by add the following to your editor user settings: 21 | 22 | ```javascript 23 | { 24 | "emmet.showSuggestionsAsSnippets": true, 25 | "editor.snippetSuggestions": "top" 26 | } 27 | ``` 28 | 29 | ## Feedback 30 | 31 | Please send any feedback or suggestions to [@anibal_sanchez](https://twitter.com/anibal_sanchez) (Twitter) or [create an issue](https://github.com/anibalsanchez/vs-code-joomla-snippets) on GitHub. 32 | 33 | ## Open Source 34 | 35 | This is an open source project and if you want to contribute I've added issues on github that are easy to start with. [![first-timers-only](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/anibalsanchez/vs-code-joomla-snippets/labels/first-timers-only) 36 | 37 | ## Disclaimer 38 | 39 | Important: This extension due to the nature of it's purpose will create 40 | files on your hard drive and if necessary create the respective folder structure. 41 | While it should not override any files during this process, I'm not giving any guarantees or take any responsibility in case of lost data. 42 | 43 | ## License 44 | 45 | MIT 46 | 47 | ## Acknowledgements 48 | 49 | - [Snippets para Visual Studio Code y Joomla](https://www.sergioiglesias.net/blog/joomla/418-snippets-para-visual-studio-code-y-joomla) 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vs-code-joomla-snippets", 3 | "publisher": "AnibalSanchez", 4 | "displayName": "Joomla Snippets", 5 | "description": "Snippets for Joomla. Including Joomla 3.x and Joomla 4 Snippets.", 6 | "icon": "images/joomla.png", 7 | "license": "MIT", 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/anibalsanchez/VSCode-Joomla-Snippets.git" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/anibalsanchez/VSCode-Joomla-Snippets/issues" 14 | }, 15 | "homepage": "https://github.com/anibalsanchez/VSCode-Joomla-Snippets#readme", 16 | "version": "0.0.11", 17 | "engines": { 18 | "vscode": "^1.0.0" 19 | }, 20 | "categories": [ 21 | "Snippets" 22 | ], 23 | "keywords": [ 24 | "Joomla", 25 | "PHP" 26 | ], 27 | "contributes": { 28 | "snippets": [ 29 | { 30 | "language": "php", 31 | "path": "./snippets/php.json" 32 | } 33 | ] 34 | }, 35 | "scripts": { 36 | "build": "npm run build_snippets; npm run build_readme; npm run dups; npm run countPHP", 37 | "publish": "npm version patch; vsce publish; git push", 38 | "patch": "npm version patch", 39 | "install": "npm run build; vsce package; code --install-extension *.vsix", 40 | "build_snippets": "npm run build_php", 41 | "build_php": "cat src/snippets.json > snippets/php.json", 42 | "build_readme": "cat src/README_top.md > README.md; npm run generate_readme_table; cat src/README_bottom.md >> README.md;", 43 | "generate_readme_table": "cat src/snippets.json | grep 'prefix\\|description' | sed -e \"s/description//\" | sed -e \"s/prefix//\" | sed -e 's/ \"\": \"//' | sed -e 's/\",//' | sed -e 'N;s/\\n/ | /' | sed -e 's/$/ |/g' | sed -e 's/^/| /' | sort >> README.md", 44 | "dups": "npm run dup_snippet; npm run dup_name", 45 | "dup_snippet": "cat src/snippets.json | grep '\": {' | sort | uniq -d", 46 | "dup_name": "cat src/snippets.json | grep 'prefix' | sort | uniq -d", 47 | "countPHP": "cat snippets/php.json | grep 'prefix' | wc" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VSCode Joomla Snippets 2 | 3 | Visual Studio Code Joomla snippets and code examples for Joomla 3 & 4 Alpha. 4 | 5 | All code snippets are based on and follow the Joomla style guide . 6 | 7 | ## Snippet Prefixes 8 | 9 | | Prefix | Description | 10 | | ------- | ----------| 11 | | j- | Joomla Snippets | 12 | | j4- | Joomla 4 Alpha Snippets | 13 | | jdoc- | Snippets for Templates | 14 | 15 | ## Usage 16 | 17 | All Joomla snippets starts with "j-", "j4-", or "jdoc-". 18 | 19 | ## Joomla Snippets 20 | 21 | | Snippet | Description | 22 | | ------- | ----------| 23 | | j4-application | Adds the Joomla Factory declaration and the app variable declaration. | 24 | | j4-arrayhelper | Adds the ArrayHelper declaration. | 25 | | j4-component-params-backend-cli | Declaration of the component helper and params retrieval. | 26 | | j4-component-params-frontend | Declaration of the component helper and params retrieval. | 27 | | j4-document | Adds the Joomla Factory declaration and the document variable declaration. | 28 | | j4-factory | Adds the Joomla Factory declaration. | 29 | | j4-formtoken | Method to determine a hash for anti-spoofing variable names. | 30 | | j4-input | Declaration of the JInput. | 31 | | j4-log | Method to add an entry to one custom log file. | 32 | | j4-registry | Adds the Joomla Registry declaration. | 33 | | j4-script | Adds a deferred extension script to the page, to start optimizing load of files. | 34 | | j4-script-inline | Adds an inline script to the page, to start reducing the number of loaded files. | 35 | | j4-script-remote | Adds a linked template script to the page with a version to allow to flush it. | 36 | | j4-script-remote-defer | Adds a deferred remote script to the page, to start optimizing load of files. | 37 | | j4-stylesheet | Adds a stylesheet. | 38 | | j4-stylesheet-inline | Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files. | 39 | | j4-stylesheet-remote | Adds an absolute URL to link a versiones template stylesheet to the page. | 40 | | j4-stylesheet-remote-defer | Adds a deferred remote stylesheet to the page, to start optimizing load of files. | 41 | | j4-template-head | Common template header variables for Joomla 3. | 42 | | j4-text-translation | Declares the text translation helper (a.k.a JText::_). | 43 | | j4-uri-base | Adds the Joomla URI declaration, to get the Base URI. | 44 | | j4-uri-root | Adds the Joomla URI declaration, to get the Root URI. | 45 | | j4-user | Adds the Joomla Factory declaration and the app variable declaration. | 46 | | j-application | Adds the Joomla Factory app variable declaration. | 47 | | j-arrayhelper | Adds the JArrayHelper declaration. | 48 | | j-component-params-backend-cli | Declaration of the component helper and params retrieval. | 49 | | j-component-params-frontend | Declaration of the component helper and params retrieval. | 50 | | j-document | Adds the Joomla document variable declaration. | 51 | | j-factory | Adds the Joomla Factory declaration. | 52 | | j-formtoken | Method to determine a hash for anti-spoofing variable names. | 53 | | j-function | Standard Joomla function declaration. | 54 | | j-input | Declaration of the JInput. | 55 | | j-log | Method to add an entry to one custom log file. | 56 | | j-module-position | Add a module position to a template. | 57 | | j-registry | Adds the Joomla Registry declaration. | 58 | | j-script | Adds a deferred script to the page, to start optimizing load of files. | 59 | | j-script-inline | Adds an inline script to the page, to start reducing the number of loaded files. | 60 | | j-script-remote | Adds a linked template script to the page with a version to allow to flush it. | 61 | | j-script-remote-defer | Adds a deferred remote script to the page, to start optimizing load of files. | 62 | | j-stylesheet | Adds a stylesheet. | 63 | | j-stylesheet-inline | Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files. | 64 | | j-stylesheet-remote | Adds an absolute URL to link a versiones template stylesheet to the page. | 65 | | j-stylesheet-remote-defer | Adds a deferred remote stylesheet to the page, to start optimizing load of files. | 66 | | j-template-head | Common template header variables for Joomla 3. | 67 | | j-text | Expand a JText for Joomla 3. Translates a string into the current language. | 68 | | j-uri-base | Adds the Joomla URI declaration, to get the Base URI. | 69 | | j-uri-root | Adds the Joomla URI declaration, to get the Root URI. | 70 | | j-user | Adds the Joomla Factory declaration and the app variable declaration. | 71 | 72 | ## Installation (Mac) 73 | 74 | 1. Launch VS Code 75 | 1. Quick Open (⌘+P) 76 | 1. Enter the following command and press enter: 'ext install vs-code-joomla-snippets' 77 | 1. Choose extension (Author: AnibalSanchez) 78 | 1. Reload VS Code 79 | 80 | ## Installation (Windows, Linux) 81 | 82 | 1. Launch VS Code 83 | 1. Quick Open (Ctrl-Shift-P) 84 | 1. Enter the following command and press enter: 'ext install vs-code-joomla-snippets' 85 | 1. Choose extension (Author: AnibalSanchez) 86 | 1. Reload VS Code 87 | 88 | ## Emmets 89 | 90 | If you want intellisense to show emmets before the snippets, you can force the emmets suggestions to show up at the top, by add the following to your editor user settings: 91 | 92 | ```javascript 93 | { 94 | "emmet.showSuggestionsAsSnippets": true, 95 | "editor.snippetSuggestions": "top" 96 | } 97 | ``` 98 | 99 | ## Feedback 100 | 101 | Please send any feedback or suggestions to [@anibal_sanchez](https://twitter.com/anibal_sanchez) (Twitter) or [create an issue](https://github.com/anibalsanchez/vs-code-joomla-snippets) on GitHub. 102 | 103 | ## Open Source 104 | 105 | This is an open source project and if you want to contribute I've added issues on github that are easy to start with. [![first-timers-only](https://img.shields.io/badge/first--timers--only-friendly-blue.svg)](https://github.com/anibalsanchez/vs-code-joomla-snippets/labels/first-timers-only) 106 | 107 | ## Disclaimer 108 | 109 | Important: This extension due to the nature of it's purpose will create 110 | files on your hard drive and if necessary create the respective folder structure. 111 | While it should not override any files during this process, I'm not giving any guarantees or take any responsibility in case of lost data. 112 | 113 | ## License 114 | 115 | MIT 116 | 117 | ## Acknowledgements 118 | 119 | - [Snippets para Visual Studio Code y Joomla](https://www.sergioiglesias.net/blog/joomla/418-snippets-para-visual-studio-code-y-joomla) 120 | -------------------------------------------------------------------------------- /snippets/php.json: -------------------------------------------------------------------------------- 1 | { 2 | "J - Add a Function Docblock and Declaration": { 3 | "prefix": "j-function", 4 | "description": "Standard Joomla function declaration.", 5 | "body": [ 6 | "/**", 7 | " * $1", 8 | " *", 9 | " * @param string $aParam Param", 10 | " *", 11 | " * @return void", 12 | " */", 13 | "public function $2()", 14 | "{", 15 | "\t$3", 16 | "}" 17 | ] 18 | }, 19 | "J - Add a module position to a template": { 20 | "prefix": "j-module-position", 21 | "description": "Add a module position to a template.", 22 | "body": [ 23 | "" 24 | ] 25 | }, 26 | "J3 - Add a Component Params - Backend declaration": { 27 | "prefix": "j-component-params-backend-cli", 28 | "description": "Declaration of the component helper and params retrieval.", 29 | "body": [ 30 | "\\$params = JComponentHelper::getParams('{$1:com_component}');" 31 | ] 32 | }, 33 | "J3 - Add a Component Params - Frontend declaration": { 34 | "prefix": "j-component-params-frontend", 35 | "description": "Declaration of the component helper and params retrieval.", 36 | "body": [ 37 | "\\$app = JFactory::getApplication();", 38 | "\\$params = \\$app->getParams('{$1:com_component}');" 39 | ] 40 | }, 41 | "J3 - Add a deferred CSS StyleSheet": { 42 | "prefix": "j-stylesheet-remote-defer", 43 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 44 | "body": [ 45 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 46 | "JFactory::getDocument()->addScriptDeclaration(\\$script);" 47 | ] 48 | }, 49 | "J3 - Add a deferred extension JavaScript file": { 50 | "prefix": "j-script", 51 | "description": "Adds a deferred script to the page, to start optimizing load of files.", 52 | "body": [ 53 | "JHtml::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 54 | ] 55 | }, 56 | "J3 - Add a deferred remote JavaScript file": { 57 | "prefix": "j-script-remote-defer", 58 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 59 | "body": [ 60 | "JFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 61 | ] 62 | }, 63 | "J3 - Add a Document declaration": { 64 | "prefix": "j-document", 65 | "description": "Adds the Joomla document variable declaration.", 66 | "body": [ 67 | "\\$doc = JFactory::getDocument();" 68 | ] 69 | }, 70 | "J3 - Add a Form Token declaration": { 71 | "prefix": "j-formtoken", 72 | "description": "Method to determine a hash for anti-spoofing variable names.", 73 | "body": [ 74 | "\\$token = JFactory::getSession()->getFormToken()" 75 | ] 76 | }, 77 | "J3 - Add a Log call": { 78 | "prefix": "j-log", 79 | "description": "Method to add an entry to one custom log file.", 80 | "body": [ 81 | "JLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), JLog::ALL, array('{$1:com_example}.log'));", 82 | "JLog::add('Message ... ', JLog::INFO, '{$1:com_example}.log');" 83 | ] 84 | }, 85 | "J3 - Add a remote CSS StyleSheet, with version": { 86 | "prefix": "j-stylesheet-remote", 87 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 88 | "body": [ 89 | "JFactory::getDocument()->addStyleSheetVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 90 | ] 91 | }, 92 | "J3 - Add a remote JavaScript file, with version": { 93 | "prefix": "j-script-remote", 94 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 95 | "body": [ 96 | "JFactory::getDocument()->addScriptVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 97 | ] 98 | }, 99 | "J3 - Add a Text translation call": { 100 | "prefix": "j-text", 101 | "description": "Expand a JText for Joomla 3. Translates a string into the current language.", 102 | "body": [ 103 | "echo JText::_('$1');" 104 | ] 105 | }, 106 | "J3 - Add an Application declaration": { 107 | "prefix": "j-application", 108 | "description": "Adds the Joomla Factory app variable declaration.", 109 | "body": [ 110 | "\\$app = JFactory::getApplication();" 111 | ] 112 | }, 113 | "J3 - Add an ArrayHelper declaration": { 114 | "prefix": "j-arrayhelper", 115 | "description": "Adds the JArrayHelper declaration.", 116 | "body": [ 117 | "\\$extra = JArrayHelper::toString(\\$attrs);" 118 | ] 119 | }, 120 | "J3 - Add an extension CSS StyleSheet, with version": { 121 | "prefix": "j-stylesheet", 122 | "description": "Adds a stylesheet.", 123 | "body": [ 124 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 125 | ] 126 | }, 127 | "J3 - Add an inline CSS Style fron an extension file": { 128 | "prefix": "j-stylesheet-inline", 129 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 130 | "body": [ 131 | "\\$filePath = JHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 132 | "JFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 133 | ] 134 | }, 135 | "J3 - Add an inline JavaScript from an extension script": { 136 | "prefix": "j-script-inline", 137 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 138 | "body": [ 139 | "\\$filePath = JHtml::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 140 | "JFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 141 | ] 142 | }, 143 | "J3 - Add J-Factory": { 144 | "prefix": "j-factory", 145 | "description": "Adds the Joomla Factory declaration.", 146 | "body": [ 147 | "JFactory::$1;" 148 | ] 149 | }, 150 | "J3 - Add J-Registry": { 151 | "prefix": "j-registry", 152 | "description": "Adds the Joomla Registry declaration.", 153 | "body": [ 154 | "\\$registry = new JRegistry;" 155 | ] 156 | }, 157 | "J3 - Add J-Template Headers declaration": { 158 | "prefix": "j-template-head", 159 | "description": "Common template header variables for Joomla 3.", 160 | "body": [ 161 | "defined('_JEXEC') or die;", 162 | "\\$app = JFactory::getApplication();", 163 | "\\$doc = JFactory::getDocument();", 164 | "\\$user = JFactory::getUser();", 165 | "\\$this->language = \\$doc->language;", 166 | "\\$this->direction = \\$doc->direction;" 167 | ] 168 | }, 169 | "J3 - Add J-Uri Base declaration": { 170 | "prefix": "j-uri-base", 171 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 172 | "body": [ 173 | "\\$base = JUri::base();" 174 | ] 175 | }, 176 | "J3 - Add J-Uri Root declaration": { 177 | "prefix": "j-uri-root", 178 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 179 | "body": [ 180 | "\\$root = JUri::root();" 181 | ] 182 | }, 183 | "J3 - Add J-User declaration": { 184 | "prefix": "j-user", 185 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 186 | "body": [ 187 | "\\$user = JFactory::getUser();" 188 | ] 189 | }, 190 | "J3 - Add Web J-Input declaration": { 191 | "prefix": "j-input", 192 | "description": "Declaration of the JInput.", 193 | "body": [ 194 | "\\$input = new JInput;" 195 | ] 196 | }, 197 | "J4 - Add a Component Params - Backend declaration": { 198 | "prefix": "j4-component-params-backend-cli", 199 | "description": "Declaration of the component helper and params retrieval.", 200 | "body": [ 201 | "use Joomla\\CMS\\Component\\ComponentHelper;", 202 | "", 203 | "\\$params = ComponentHelper::getParams('{$1:com_component}');" 204 | ] 205 | }, 206 | "J4 - Add a Component Params - Frontend declaration": { 207 | "prefix": "j4-component-params-frontend", 208 | "description": "Declaration of the component helper and params retrieval.", 209 | "body": [ 210 | "use Joomla\\CMS\\Factory as CMSFactory;", 211 | "", 212 | "\\$app = CMSFactory::getApplication();", 213 | "\\$params = \\$app->getParams('{$1:com_component}');" 214 | ] 215 | }, 216 | "J4 - Add a deferred CSS StyleSheet": { 217 | "prefix": "j4-stylesheet-remote-defer", 218 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 219 | "body": [ 220 | "use Joomla\\CMS\\Factory as CMSFactory;", 221 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 222 | "", 223 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 224 | "CMSFactory::getDocument()->addScriptDeclaration(\\$script);" 225 | ] 226 | }, 227 | "J4 - Add a deferred extension JavaScript file": { 228 | "prefix": "j4-script", 229 | "description": "Adds a deferred extension script to the page, to start optimizing load of files.", 230 | "body": [ 231 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 232 | "", 233 | "CMSHTMLHelper::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 234 | ] 235 | }, 236 | "J4 - Add a deferred remote JavaScript file": { 237 | "prefix": "j4-script-remote-defer", 238 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 239 | "body": [ 240 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 241 | "", 242 | "CMSFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 243 | ] 244 | }, 245 | "J4 - Add a Document declaration": { 246 | "prefix": "j4-document", 247 | "description": "Adds the Joomla Factory declaration and the document variable declaration.", 248 | "body": [ 249 | "use Joomla\\CMS\\Factory as CMSFactory;", 250 | "", 251 | "\\$doc = CMSFactory::getDocument();" 252 | ] 253 | }, 254 | "J4 - Add a Form Token declaration": { 255 | "prefix": "j4-formtoken", 256 | "description": "Method to determine a hash for anti-spoofing variable names.", 257 | "body": [ 258 | "use Joomla\\CMS\\Factory as CMSFactory;", 259 | "", 260 | "\\$token = CMSFactory::getSession()->getFormToken()" 261 | ] 262 | }, 263 | "J4 - Add a Log call": { 264 | "prefix": "j4-log", 265 | "description": "Method to add an entry to one custom log file.", 266 | "body": [ 267 | "use Joomla\\CMS\\Log\\Log as CMSLog;", 268 | "", 269 | "CMSLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), CMSLog::ALL, array('{$1:com_example}.log'));", 270 | "CMSLog::add('Message ... ', CMSLog::INFO, '{$1:com_example}.log');" 271 | ] 272 | }, 273 | "J4 - Add a remote CSS StyleSheet, with version": { 274 | "prefix": "j4-stylesheet-remote", 275 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 276 | "body": [ 277 | "use Joomla\\CMS\\Factory as CMSFactory;", 278 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 279 | "", 280 | "CMSFactory::getDocument()->addStyleSheetVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 281 | ] 282 | }, 283 | "J4 - Add a remote JavaScript file, with version": { 284 | "prefix": "j4-script-remote", 285 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 286 | "body": [ 287 | "use Joomla\\CMS\\Factory as CMSFactory;", 288 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 289 | "", 290 | "CMSFactory::getDocument()->addScriptVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 291 | ] 292 | }, 293 | "J4 - Add a Text translation call": { 294 | "prefix": "j4-text-translation", 295 | "description": "Declares the text translation helper (a.k.a JText::_).", 296 | "body": [ 297 | "use Joomla\\CMS\\Language\\Text as CMSText;", 298 | "", 299 | "$l = CMSText::_('{$1:COM_EXAMPLE_A_LABEL}')" 300 | ] 301 | }, 302 | "J4 - Add an Application declaration": { 303 | "prefix": "j4-application", 304 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 305 | "body": [ 306 | "use Joomla\\CMS\\Factory as CMSFactory;", 307 | "", 308 | "\\$app = CMSFactory::getApplication();" 309 | ] 310 | }, 311 | "J4 - Add an ArrayHelper declaration": { 312 | "prefix": "j4-arrayhelper", 313 | "description": "Adds the ArrayHelper declaration.", 314 | "body": [ 315 | "use Joomla\\Utilities\\ArrayHelper;" 316 | ] 317 | }, 318 | "J4 - Add an extension CSS StyleSheet, with version": { 319 | "prefix": "j4-stylesheet", 320 | "description": "Adds a stylesheet.", 321 | "body": [ 322 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 323 | "", 324 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 325 | ] 326 | }, 327 | "J4 - Add an inline CSS Style fron an extension file": { 328 | "prefix": "j4-stylesheet-inline", 329 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 330 | "body": [ 331 | "use Joomla\\CMS\\Factory as CMSFactory;", 332 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 333 | "", 334 | "\\$filePath = CMSHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 335 | "CMSFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 336 | ] 337 | }, 338 | "J4 - Add an inline JavaScript from an extension script": { 339 | "prefix": "j4-script-inline", 340 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 341 | "body": [ 342 | "use Joomla\\CMS\\Factory as CMSFactory;", 343 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 344 | "", 345 | "\\$filePath = CMSHTMLHelper::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 346 | "CMSFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 347 | ] 348 | }, 349 | "J4 - Add J-Factory": { 350 | "prefix": "j4-factory", 351 | "description": "Adds the Joomla Factory declaration.", 352 | "body": [ 353 | "use Joomla\\CMS\\Factory as CMSFactory;", 354 | "", 355 | "CMSFactory::$1;" 356 | ] 357 | }, 358 | "J4 - Add J-Registry": { 359 | "prefix": "j4-registry", 360 | "description": "Adds the Joomla Registry declaration.", 361 | "body": [ 362 | "use Joomla\\Registry\\Registry as CMSRegistry;", 363 | "", 364 | "\\$registry = new CMSRegistry;" 365 | ] 366 | }, 367 | "J4 - Add J-Template Headers declaration": { 368 | "prefix": "j4-template-head", 369 | "description": "Common template header variables for Joomla 3.", 370 | "body": [ 371 | "defined('_JEXEC') or die;", 372 | "use Joomla\\CMS\\Factory as CMSFactory;", 373 | "\\$app = CMSFactory::getApplication();", 374 | "\\$doc = CMSFactory::getDocument();", 375 | "\\$user = CMSFactory::getUser();", 376 | "\\$this->language = \\$doc->language;", 377 | "\\$this->direction = \\$doc->direction;" 378 | ] 379 | }, 380 | "J4 - Add J-Uri Base declaration": { 381 | "prefix": "j4-uri-base", 382 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 383 | "body": [ 384 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 385 | "", 386 | "\\$base = CMSUri::base();" 387 | ] 388 | }, 389 | "J4 - Add J-Uri Root declaration": { 390 | "prefix": "j4-uri-root", 391 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 392 | "body": [ 393 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 394 | "", 395 | "\\$root = CMSUri::root();" 396 | ] 397 | }, 398 | "J4 - Add J-User declaration": { 399 | "prefix": "j4-user", 400 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 401 | "body": [ 402 | "use Joomla\\CMS\\Factory as CMSFactory;", 403 | "", 404 | "\\$user = CMSFactory::getUser();" 405 | ] 406 | }, 407 | "J4 - Add Web J-Input declaration": { 408 | "prefix": "j4-input", 409 | "description": "Declaration of the JInput.", 410 | "body": [ 411 | "use Joomla\\CMS\\Input\\Input as CMSWebInput;", 412 | "", 413 | "\\$input = new CMSWebInput;" 414 | ] 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /src/snippets.json: -------------------------------------------------------------------------------- 1 | { 2 | "J - Add a Function Docblock and Declaration": { 3 | "prefix": "j-function", 4 | "description": "Standard Joomla function declaration.", 5 | "body": [ 6 | "/**", 7 | " * $1", 8 | " *", 9 | " * @param string $aParam Param", 10 | " *", 11 | " * @return void", 12 | " */", 13 | "public function $2()", 14 | "{", 15 | "\t$3", 16 | "}" 17 | ] 18 | }, 19 | "J - Add a module position to a template": { 20 | "prefix": "j-module-position", 21 | "description": "Add a module position to a template.", 22 | "body": [ 23 | "" 24 | ] 25 | }, 26 | "J3 - Add a Component Params - Backend declaration": { 27 | "prefix": "j-component-params-backend-cli", 28 | "description": "Declaration of the component helper and params retrieval.", 29 | "body": [ 30 | "\\$params = JComponentHelper::getParams('{$1:com_component}');" 31 | ] 32 | }, 33 | "J3 - Add a Component Params - Frontend declaration": { 34 | "prefix": "j-component-params-frontend", 35 | "description": "Declaration of the component helper and params retrieval.", 36 | "body": [ 37 | "\\$app = JFactory::getApplication();", 38 | "\\$params = \\$app->getParams('{$1:com_component}');" 39 | ] 40 | }, 41 | "J3 - Add a deferred CSS StyleSheet": { 42 | "prefix": "j-stylesheet-remote-defer", 43 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 44 | "body": [ 45 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 46 | "JFactory::getDocument()->addScriptDeclaration(\\$script);" 47 | ] 48 | }, 49 | "J3 - Add a deferred extension JavaScript file": { 50 | "prefix": "j-script", 51 | "description": "Adds a deferred script to the page, to start optimizing load of files.", 52 | "body": [ 53 | "JHtml::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 54 | ] 55 | }, 56 | "J3 - Add a deferred remote JavaScript file": { 57 | "prefix": "j-script-remote-defer", 58 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 59 | "body": [ 60 | "JFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 61 | ] 62 | }, 63 | "J3 - Add a Document declaration": { 64 | "prefix": "j-document", 65 | "description": "Adds the Joomla document variable declaration.", 66 | "body": [ 67 | "\\$doc = JFactory::getDocument();" 68 | ] 69 | }, 70 | "J3 - Add a Form Token declaration": { 71 | "prefix": "j-formtoken", 72 | "description": "Method to determine a hash for anti-spoofing variable names.", 73 | "body": [ 74 | "\\$token = JFactory::getSession()->getFormToken()" 75 | ] 76 | }, 77 | "J3 - Add a Log call": { 78 | "prefix": "j-log", 79 | "description": "Method to add an entry to one custom log file.", 80 | "body": [ 81 | "JLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), JLog::ALL, array('{$1:com_example}.log'));", 82 | "JLog::add('Message ... ', JLog::INFO, '{$1:com_example}.log');" 83 | ] 84 | }, 85 | "J3 - Add a remote CSS StyleSheet, with version": { 86 | "prefix": "j-stylesheet-remote", 87 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 88 | "body": [ 89 | "JFactory::getDocument()->addStyleSheetVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 90 | ] 91 | }, 92 | "J3 - Add a remote JavaScript file, with version": { 93 | "prefix": "j-script-remote", 94 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 95 | "body": [ 96 | "JFactory::getDocument()->addScriptVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 97 | ] 98 | }, 99 | "J3 - Add a Text translation call": { 100 | "prefix": "j-text", 101 | "description": "Expand a JText for Joomla 3. Translates a string into the current language.", 102 | "body": [ 103 | "echo JText::_('$1');" 104 | ] 105 | }, 106 | "J3 - Add an Application declaration": { 107 | "prefix": "j-application", 108 | "description": "Adds the Joomla Factory app variable declaration.", 109 | "body": [ 110 | "\\$app = JFactory::getApplication();" 111 | ] 112 | }, 113 | "J3 - Add an ArrayHelper declaration": { 114 | "prefix": "j-arrayhelper", 115 | "description": "Adds the JArrayHelper declaration.", 116 | "body": [ 117 | "\\$extra = JArrayHelper::toString(\\$attrs);" 118 | ] 119 | }, 120 | "J3 - Add an extension CSS StyleSheet, with version": { 121 | "prefix": "j-stylesheet", 122 | "description": "Adds a stylesheet.", 123 | "body": [ 124 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 125 | ] 126 | }, 127 | "J3 - Add an inline CSS Style fron an extension file": { 128 | "prefix": "j-stylesheet-inline", 129 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 130 | "body": [ 131 | "\\$filePath = JHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 132 | "JFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 133 | ] 134 | }, 135 | "J3 - Add an inline JavaScript from an extension script": { 136 | "prefix": "j-script-inline", 137 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 138 | "body": [ 139 | "\\$filePath = JHtml::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 140 | "JFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 141 | ] 142 | }, 143 | "J3 - Add J-Factory": { 144 | "prefix": "j-factory", 145 | "description": "Adds the Joomla Factory declaration.", 146 | "body": [ 147 | "JFactory::$1;" 148 | ] 149 | }, 150 | "J3 - Add J-Registry": { 151 | "prefix": "j-registry", 152 | "description": "Adds the Joomla Registry declaration.", 153 | "body": [ 154 | "\\$registry = new JRegistry;" 155 | ] 156 | }, 157 | "J3 - Add J-Template Headers declaration": { 158 | "prefix": "j-template-head", 159 | "description": "Common template header variables for Joomla 3.", 160 | "body": [ 161 | "defined('_JEXEC') or die;", 162 | "\\$app = JFactory::getApplication();", 163 | "\\$doc = JFactory::getDocument();", 164 | "\\$user = JFactory::getUser();", 165 | "\\$this->language = \\$doc->language;", 166 | "\\$this->direction = \\$doc->direction;" 167 | ] 168 | }, 169 | "J3 - Add J-Uri Base declaration": { 170 | "prefix": "j-uri-base", 171 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 172 | "body": [ 173 | "\\$base = JUri::base();" 174 | ] 175 | }, 176 | "J3 - Add J-Uri Root declaration": { 177 | "prefix": "j-uri-root", 178 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 179 | "body": [ 180 | "\\$root = JUri::root();" 181 | ] 182 | }, 183 | "J3 - Add J-User declaration": { 184 | "prefix": "j-user", 185 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 186 | "body": [ 187 | "\\$user = JFactory::getUser();" 188 | ] 189 | }, 190 | "J3 - Add Web J-Input declaration": { 191 | "prefix": "j-input", 192 | "description": "Declaration of the JInput.", 193 | "body": [ 194 | "\\$input = new JInput;" 195 | ] 196 | }, 197 | "J4 - Add a Component Params - Backend declaration": { 198 | "prefix": "j4-component-params-backend-cli", 199 | "description": "Declaration of the component helper and params retrieval.", 200 | "body": [ 201 | "use Joomla\\CMS\\Component\\ComponentHelper;", 202 | "", 203 | "\\$params = ComponentHelper::getParams('{$1:com_component}');" 204 | ] 205 | }, 206 | "J4 - Add a Component Params - Frontend declaration": { 207 | "prefix": "j4-component-params-frontend", 208 | "description": "Declaration of the component helper and params retrieval.", 209 | "body": [ 210 | "use Joomla\\CMS\\Factory as CMSFactory;", 211 | "", 212 | "\\$app = CMSFactory::getApplication();", 213 | "\\$params = \\$app->getParams('{$1:com_component}');" 214 | ] 215 | }, 216 | "J4 - Add a deferred CSS StyleSheet": { 217 | "prefix": "j4-stylesheet-remote-defer", 218 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 219 | "body": [ 220 | "use Joomla\\CMS\\Factory as CMSFactory;", 221 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 222 | "", 223 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 224 | "CMSFactory::getDocument()->addScriptDeclaration(\\$script);" 225 | ] 226 | }, 227 | "J4 - Add a deferred extension JavaScript file": { 228 | "prefix": "j4-script", 229 | "description": "Adds a deferred extension script to the page, to start optimizing load of files.", 230 | "body": [ 231 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 232 | "", 233 | "CMSHTMLHelper::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 234 | ] 235 | }, 236 | "J4 - Add a deferred remote JavaScript file": { 237 | "prefix": "j4-script-remote-defer", 238 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 239 | "body": [ 240 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 241 | "", 242 | "CMSFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 243 | ] 244 | }, 245 | "J4 - Add a Document declaration": { 246 | "prefix": "j4-document", 247 | "description": "Adds the Joomla Factory declaration and the document variable declaration.", 248 | "body": [ 249 | "use Joomla\\CMS\\Factory as CMSFactory;", 250 | "", 251 | "\\$doc = CMSFactory::getDocument();" 252 | ] 253 | }, 254 | "J4 - Add a Form Token declaration": { 255 | "prefix": "j4-formtoken", 256 | "description": "Method to determine a hash for anti-spoofing variable names.", 257 | "body": [ 258 | "use Joomla\\CMS\\Factory as CMSFactory;", 259 | "", 260 | "\\$token = CMSFactory::getSession()->getFormToken()" 261 | ] 262 | }, 263 | "J4 - Add a Log call": { 264 | "prefix": "j4-log", 265 | "description": "Method to add an entry to one custom log file.", 266 | "body": [ 267 | "use Joomla\\CMS\\Log\\Log as CMSLog;", 268 | "", 269 | "CMSLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), CMSLog::ALL, array('{$1:com_example}.log'));", 270 | "CMSLog::add('Message ... ', CMSLog::INFO, '{$1:com_example}.log');" 271 | ] 272 | }, 273 | "J4 - Add a remote CSS StyleSheet, with version": { 274 | "prefix": "j4-stylesheet-remote", 275 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 276 | "body": [ 277 | "use Joomla\\CMS\\Factory as CMSFactory;", 278 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 279 | "", 280 | "CMSFactory::getDocument()->addStyleSheetVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 281 | ] 282 | }, 283 | "J4 - Add a remote JavaScript file, with version": { 284 | "prefix": "j4-script-remote", 285 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 286 | "body": [ 287 | "use Joomla\\CMS\\Factory as CMSFactory;", 288 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 289 | "", 290 | "CMSFactory::getDocument()->addScriptVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 291 | ] 292 | }, 293 | "J4 - Add a Text translation call": { 294 | "prefix": "j4-text-translation", 295 | "description": "Declares the text translation helper (a.k.a JText::_).", 296 | "body": [ 297 | "use Joomla\\CMS\\Language\\Text as CMSText;", 298 | "", 299 | "$l = CMSText::_('{$1:COM_EXAMPLE_A_LABEL}')" 300 | ] 301 | }, 302 | "J4 - Add an Application declaration": { 303 | "prefix": "j4-application", 304 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 305 | "body": [ 306 | "use Joomla\\CMS\\Factory as CMSFactory;", 307 | "", 308 | "\\$app = CMSFactory::getApplication();" 309 | ] 310 | }, 311 | "J4 - Add an ArrayHelper declaration": { 312 | "prefix": "j4-arrayhelper", 313 | "description": "Adds the ArrayHelper declaration.", 314 | "body": [ 315 | "use Joomla\\Utilities\\ArrayHelper;" 316 | ] 317 | }, 318 | "J4 - Add an extension CSS StyleSheet, with version": { 319 | "prefix": "j4-stylesheet", 320 | "description": "Adds a stylesheet.", 321 | "body": [ 322 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 323 | "", 324 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 325 | ] 326 | }, 327 | "J4 - Add an inline CSS Style fron an extension file": { 328 | "prefix": "j4-stylesheet-inline", 329 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 330 | "body": [ 331 | "use Joomla\\CMS\\Factory as CMSFactory;", 332 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 333 | "", 334 | "\\$filePath = CMSHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 335 | "CMSFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 336 | ] 337 | }, 338 | "J4 - Add an inline JavaScript from an extension script": { 339 | "prefix": "j4-script-inline", 340 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 341 | "body": [ 342 | "use Joomla\\CMS\\Factory as CMSFactory;", 343 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 344 | "", 345 | "\\$filePath = CMSHTMLHelper::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 346 | "CMSFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 347 | ] 348 | }, 349 | "J4 - Add J-Factory": { 350 | "prefix": "j4-factory", 351 | "description": "Adds the Joomla Factory declaration.", 352 | "body": [ 353 | "use Joomla\\CMS\\Factory as CMSFactory;", 354 | "", 355 | "CMSFactory::$1;" 356 | ] 357 | }, 358 | "J4 - Add J-Registry": { 359 | "prefix": "j4-registry", 360 | "description": "Adds the Joomla Registry declaration.", 361 | "body": [ 362 | "use Joomla\\Registry\\Registry as CMSRegistry;", 363 | "", 364 | "\\$registry = new CMSRegistry;" 365 | ] 366 | }, 367 | "J4 - Add J-Template Headers declaration": { 368 | "prefix": "j4-template-head", 369 | "description": "Common template header variables for Joomla 3.", 370 | "body": [ 371 | "defined('_JEXEC') or die;", 372 | "use Joomla\\CMS\\Factory as CMSFactory;", 373 | "\\$app = CMSFactory::getApplication();", 374 | "\\$doc = CMSFactory::getDocument();", 375 | "\\$user = CMSFactory::getUser();", 376 | "\\$this->language = \\$doc->language;", 377 | "\\$this->direction = \\$doc->direction;" 378 | ] 379 | }, 380 | "J4 - Add J-Uri Base declaration": { 381 | "prefix": "j4-uri-base", 382 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 383 | "body": [ 384 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 385 | "", 386 | "\\$base = CMSUri::base();" 387 | ] 388 | }, 389 | "J4 - Add J-Uri Root declaration": { 390 | "prefix": "j4-uri-root", 391 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 392 | "body": [ 393 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 394 | "", 395 | "\\$root = CMSUri::root();" 396 | ] 397 | }, 398 | "J4 - Add J-User declaration": { 399 | "prefix": "j4-user", 400 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 401 | "body": [ 402 | "use Joomla\\CMS\\Factory as CMSFactory;", 403 | "", 404 | "\\$user = CMSFactory::getUser();" 405 | ] 406 | }, 407 | "J4 - Add Web J-Input declaration": { 408 | "prefix": "j4-input", 409 | "description": "Declaration of the JInput.", 410 | "body": [ 411 | "use Joomla\\CMS\\Input\\Input as CMSWebInput;", 412 | "", 413 | "\\$input = new CMSWebInput;" 414 | ] 415 | } 416 | } 417 | -------------------------------------------------------------------------------- /src/snippets-review.json: -------------------------------------------------------------------------------- 1 | { 2 | "J3 - Add a deferred CSS StyleSheet": { 3 | "prefix": "j-stylesheet-remote-defer", 4 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 5 | "body": [ 6 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 7 | "JFactory::getDocument()->addScriptDeclaration(\\$script);" 8 | ] 9 | }, 10 | "J3 - Add a deferred extension JavaScript file": { 11 | "prefix": "j-script", 12 | "description": "Adds a deferred script to the page, to start optimizing load of files.", 13 | "body": [ 14 | "JHtml::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 15 | ] 16 | }, 17 | "J3 - Add a deferred remote JavaScript file": { 18 | "prefix": "j-script-remote-defer", 19 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 20 | "body": [ 21 | "JFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 22 | ] 23 | }, 24 | "J3 - Add a remote CSS StyleSheet, with version": { 25 | "prefix": "j-stylesheet-remote", 26 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 27 | "body": [ 28 | "JFactory::getDocument()->addStyleSheetVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 29 | ] 30 | }, 31 | "J3 - Add a remote JavaScript file, with version": { 32 | "prefix": "j-script-remote", 33 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 34 | "body": [ 35 | "JFactory::getDocument()->addScriptVersion(JUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 36 | ] 37 | }, 38 | "J3 - Add an extension CSS StyleSheet, with version": { 39 | "prefix": "j-stylesheet", 40 | "description": "Adds a stylesheet.", 41 | "body": [ 42 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 43 | ] 44 | }, 45 | "J3 - Add an inline CSS Style fron an extension file": { 46 | "prefix": "j-stylesheet-inline", 47 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 48 | "body": [ 49 | "\\$filePath = JHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 50 | "JFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 51 | ] 52 | }, 53 | "J3 - Add an inline JavaScript from an extension script": { 54 | "prefix": "j-script-inline", 55 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 56 | "body": [ 57 | "\\$filePath = JHtml::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 58 | "JFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 59 | ] 60 | }, 61 | "J4 - Add a deferred CSS StyleSheet": { 62 | "prefix": "j4-stylesheet-remote-defer", 63 | "description": "Adds a deferred remote stylesheet to the page, to start optimizing load of files.", 64 | "body": [ 65 | "use Joomla\\CMS\\Factory as CMSFactory;", 66 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 67 | "", 68 | "\\$script = '!function(e){var t=document.createElement(\"link\");t.rel=\"stylesheet\",t.href=\"'{$1:Stylesheet URL}'\",t.type=\"text/css\";var n=document.getElementsByTagName(\"link\")[0];n.parentNode.insertBefore(t,n)}();';", 69 | "CMSFactory::getDocument()->addScriptDeclaration(\\$script);" 70 | ] 71 | }, 72 | "J4 - Add a deferred extension JavaScript file": { 73 | "prefix": "j4-script", 74 | "description": "Adds a deferred extension script to the page, to start optimizing load of files.", 75 | "body": [ 76 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 77 | "", 78 | "CMSHTMLHelper::script('{$1:Extension Script, for example mod_myext/test.min.js}', ['relative' => true], ['defer' => true]);" 79 | ] 80 | }, 81 | "J4 - Add a deferred remote JavaScript file": { 82 | "prefix": "j4-script-remote-defer", 83 | "description": "Adds a deferred remote script to the page, to start optimizing load of files.", 84 | "body": [ 85 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 86 | "", 87 | "CMSFactory::getDocument()->addScript('{$1:Remote URL}', [], ['defer' => true, 'crossorigin' => 'anonymous']);" 88 | ] 89 | }, 90 | "J4 - Add a remote CSS StyleSheet, with version": { 91 | "prefix": "j4-stylesheet-remote", 92 | "description": "Adds an absolute URL to link a versiones template stylesheet to the page.", 93 | "body": [ 94 | "use Joomla\\CMS\\Factory as CMSFactory;", 95 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 96 | "", 97 | "CMSFactory::getDocument()->addStyleSheetVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your css address}');" 98 | ] 99 | }, 100 | "J4 - Add a remote JavaScript file, with version": { 101 | "prefix": "j4-script-remote", 102 | "description": "Adds a linked template script to the page with a version to allow to flush it.", 103 | "body": [ 104 | "use Joomla\\CMS\\Factory as CMSFactory;", 105 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 106 | "", 107 | "CMSFactory::getDocument()->addScriptVersion(CMSUri::base() . '/templates/${1:Your Template Name}/${2:Your js script address}');" 108 | ] 109 | }, 110 | "J4 - Add an extension CSS StyleSheet, with version": { 111 | "prefix": "j4-stylesheet", 112 | "description": "Adds a stylesheet.", 113 | "body": [ 114 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 115 | "", 116 | "JHtml::stylesheet('{$1:Extension Script, for example mod_myext/test.min.css}', ['version' => 'auto', 'relative' => true]);" 117 | ] 118 | }, 119 | "J4 - Add an inline CSS Style fron an extension file": { 120 | "prefix": "j4-stylesheet-inline", 121 | "description": "Adds an inline stylesheet declaration to the page, to start reducing the number of loaded files.", 122 | "body": [ 123 | "use Joomla\\CMS\\Factory as CMSFactory;", 124 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 125 | "", 126 | "\\$filePath = CMSHTMLHelper::stylesheet('mod_.../....min.css', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 127 | "CMSFactory::getDocument()->addStyleDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 128 | ] 129 | }, 130 | "J4 - Add an inline JavaScript from an extension script": { 131 | "prefix": "j4-script-inline", 132 | "description": "Adds an inline script to the page, to start reducing the number of loaded files.", 133 | "body": [ 134 | "use Joomla\\CMS\\Factory as CMSFactory;", 135 | "use Joomla\\CMS\\HTML\\HTMLHelper as CMSHTMLHelper;", 136 | "", 137 | "\\$filePath = CMSHTMLHelper::script('mod_.../....min.js', ['version' => 'auto', 'relative' => true, 'pathOnly' => true]);", 138 | "CMSFactory::getDocument()->addScriptDeclaration(file_get_contents(JPATH_ROOT . \\$filePath));" 139 | ] 140 | }, 141 | "J3 - Add a Component Params - Backend declaration": { 142 | "prefix": "j-component-params-backend-cli", 143 | "description": "Declaration of the component helper and params retrieval.", 144 | "body": [ 145 | "\\$params = JComponentHelper::getParams('{$1:com_component}');" 146 | ] 147 | }, 148 | "J3 - Add a Component Params - Frontend declaration": { 149 | "prefix": "j-component-params-frontend", 150 | "description": "Declaration of the component helper and params retrieval.", 151 | "body": [ 152 | "\\$app = JFactory::getApplication();", 153 | "\\$params = \\$app->getParams('{$1:com_component}');" 154 | ] 155 | }, 156 | "J3 - Add a Document declaration": { 157 | "prefix": "j-document", 158 | "description": "Adds the Joomla document variable declaration.", 159 | "body": [ 160 | "\\$doc = JFactory::getDocument();" 161 | ] 162 | }, 163 | "J3 - Add a Form Token declaration": { 164 | "prefix": "j-formtoken", 165 | "description": "Method to determine a hash for anti-spoofing variable names.", 166 | "body": [ 167 | "\\$token = JFactory::getSession()->getFormToken()" 168 | ] 169 | }, 170 | "J3 - Add a Log call": { 171 | "prefix": "j-log", 172 | "description": "Method to add an entry to one custom log file.", 173 | "body": [ 174 | "JLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), JLog::ALL, array('{$1:com_example}.log'));", 175 | "JLog::add('Message ... ', JLog::INFO, '{$1:com_example}.log');" 176 | ] 177 | }, 178 | "J3 - Add a Text translation call": { 179 | "prefix": "j-text", 180 | "description": "Expand a JText for Joomla 3. Translates a string into the current language.", 181 | "body": [ 182 | "echo JText::_('$1');" 183 | ] 184 | }, 185 | "J3 - Add an Application declaration": { 186 | "prefix": "j-application", 187 | "description": "Adds the Joomla Factory app variable declaration.", 188 | "body": [ 189 | "\\$app = JFactory::getApplication();" 190 | ] 191 | }, 192 | "J3 - Add an ArrayHelper declaration": { 193 | "prefix": "j-arrayhelper", 194 | "description": "Adds the JArrayHelper declaration.", 195 | "body": [ 196 | "\\$extra = JArrayHelper::toString(\\$attrs);" 197 | ] 198 | }, 199 | "J3 - Add J-Template Headers declaration": { 200 | "prefix": "j-template-head", 201 | "description": "Common template header variables for Joomla 3.", 202 | "body": [ 203 | "defined('_JEXEC') or die;", 204 | "\\$app = JFactory::getApplication();", 205 | "\\$doc = JFactory::getDocument();", 206 | "\\$user = JFactory::getUser();", 207 | "\\$this->language = \\$doc->language;", 208 | "\\$this->direction = \\$doc->direction;" 209 | ] 210 | }, 211 | "J3 - Add J-Uri Base declaration": { 212 | "prefix": "j-uri-base", 213 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 214 | "body": [ 215 | "\\$base = JUri::base();" 216 | ] 217 | }, 218 | "J3 - Add J-Uri Root declaration": { 219 | "prefix": "j-uri-root", 220 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 221 | "body": [ 222 | "\\$root = JUri::root();" 223 | ] 224 | }, 225 | "J3 - Add J-User declaration": { 226 | "prefix": "j-user", 227 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 228 | "body": [ 229 | "\\$user = JFactory::getUser();" 230 | ] 231 | }, 232 | "J3 - Add Web J-Input declaration": { 233 | "prefix": "j-input", 234 | "description": "Declaration of the JInput.", 235 | "body": [ 236 | "\\$input = new JInput;" 237 | ] 238 | }, 239 | "J3 - Add J-Factory": { 240 | "prefix": "j-factory", 241 | "description": "Adds the Joomla Factory declaration.", 242 | "body": [ 243 | "JFactory::$1;" 244 | ] 245 | }, 246 | "J3 - Add J-Registry": { 247 | "prefix": "j-registry", 248 | "description": "Adds the Joomla Registry declaration.", 249 | "body": [ 250 | "\\$registry = new JRegistry;" 251 | ] 252 | }, 253 | "J4 - Add a Component Params - Backend declaration": { 254 | "prefix": "j4-component-params-backend-cli", 255 | "description": "Declaration of the component helper and params retrieval.", 256 | "body": [ 257 | "use Joomla\\CMS\\Component\\ComponentHelper;", 258 | "", 259 | "\\$params = ComponentHelper::getParams('{$1:com_component}');" 260 | ] 261 | }, 262 | "J4 - Add a Component Params - Frontend declaration": { 263 | "prefix": "j4-component-params-frontend", 264 | "description": "Declaration of the component helper and params retrieval.", 265 | "body": [ 266 | "use Joomla\\CMS\\Factory as CMSFactory;", 267 | "", 268 | "\\$app = CMSFactory::getApplication();", 269 | "\\$params = \\$app->getParams('{$1:com_component}');" 270 | ] 271 | }, 272 | "J4 - Add a Document declaration": { 273 | "prefix": "j4-document", 274 | "description": "Adds the Joomla Factory declaration and the document variable declaration.", 275 | "body": [ 276 | "use Joomla\\CMS\\Factory as CMSFactory;", 277 | "", 278 | "\\$doc = CMSFactory::getDocument();" 279 | ] 280 | }, 281 | "J4 - Add a Form Token declaration": { 282 | "prefix": "j4-formtoken", 283 | "description": "Method to determine a hash for anti-spoofing variable names.", 284 | "body": [ 285 | "use Joomla\\CMS\\Factory as CMSFactory;", 286 | "", 287 | "\\$token = CMSFactory::getSession()->getFormToken()" 288 | ] 289 | }, 290 | "J4 - Add a Log call": { 291 | "prefix": "j4-log", 292 | "description": "Method to add an entry to one custom log file.", 293 | "body": [ 294 | "use Joomla\\CMS\\Log\\Log as CMSLog;", 295 | "", 296 | "CMSLog::addLogger(array('logger' => 'formattedtext', 'text_file' => '{$1:File name}.log.php'), CMSLog::ALL, array('{$1:com_example}.log'));", 297 | "CMSLog::add('Message ... ', CMSLog::INFO, '{$1:com_example}.log');" 298 | ] 299 | }, 300 | "J4 - Add a Text translation call": { 301 | "prefix": "j4-text-translation", 302 | "description": "Declares the text translation helper (a.k.a JText::_).", 303 | "body": [ 304 | "use Joomla\\CMS\\Language\\Text as CMSText;", 305 | "", 306 | "$l = CMSText::_('{$1:COM_EXAMPLE_A_LABEL}')" 307 | ] 308 | }, 309 | "J4 - Add an Application declaration": { 310 | "prefix": "j4-application", 311 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 312 | "body": [ 313 | "use Joomla\\CMS\\Factory as CMSFactory;", 314 | "", 315 | "\\$app = CMSFactory::getApplication();" 316 | ] 317 | }, 318 | "J4 - Add an ArrayHelper declaration": { 319 | "prefix": "j4-arrayhelper", 320 | "description": "Adds the ArrayHelper declaration.", 321 | "body": [ 322 | "use Joomla\\Utilities\\ArrayHelper;" 323 | ] 324 | }, 325 | "J4 - Add J-Template Headers declaration": { 326 | "prefix": "j4-template-head", 327 | "description": "Common template header variables for Joomla 3.", 328 | "body": [ 329 | "defined('_JEXEC') or die;", 330 | "use Joomla\\CMS\\Factory as CMSFactory;", 331 | "\\$app = CMSFactory::getApplication();", 332 | "\\$doc = CMSFactory::getDocument();", 333 | "\\$user = CMSFactory::getUser();", 334 | "\\$this->language = \\$doc->language;", 335 | "\\$this->direction = \\$doc->direction;" 336 | ] 337 | }, 338 | "J4 - Add J-Uri Base declaration": { 339 | "prefix": "j4-uri-base", 340 | "description": "Adds the Joomla URI declaration, to get the Base URI.", 341 | "body": [ 342 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 343 | "", 344 | "\\$base = CMSUri::base();" 345 | ] 346 | }, 347 | "J4 - Add J-Uri Root declaration": { 348 | "prefix": "j4-uri-root", 349 | "description": "Adds the Joomla URI declaration, to get the Root URI.", 350 | "body": [ 351 | "use Joomla\\CMS\\Uri\\Uri as CMSUri;", 352 | "", 353 | "\\$root = CMSUri::root();" 354 | ] 355 | }, 356 | "J4 - Add J-User declaration": { 357 | "prefix": "j4-user", 358 | "description": "Adds the Joomla Factory declaration and the app variable declaration.", 359 | "body": [ 360 | "use Joomla\\CMS\\Factory as CMSFactory;", 361 | "", 362 | "\\$user = CMSFactory::getUser();" 363 | ] 364 | }, 365 | "J4 - Add Web J-Input declaration": { 366 | "prefix": "j4-input", 367 | "description": "Declaration of the JInput.", 368 | "body": [ 369 | "use Joomla\\CMS\\Input\\Input as CMSWebInput;", 370 | "", 371 | "\\$input = new CMSWebInput;" 372 | ] 373 | }, 374 | "J4 - Add J-Factory": { 375 | "prefix": "j4-factory", 376 | "description": "Adds the Joomla Factory declaration.", 377 | "body": [ 378 | "use Joomla\\CMS\\Factory as CMSFactory;", 379 | "", 380 | "CMSFactory::$1;" 381 | ] 382 | }, 383 | "J4 - Add J-Registry": { 384 | "prefix": "j4-registry", 385 | "description": "Adds the Joomla Registry declaration.", 386 | "body": [ 387 | "use Joomla\\Registry\\Registry as CMSRegistry;", 388 | "", 389 | "\\$registry = new CMSRegistry;" 390 | ] 391 | }, 392 | "J - Add a module position to a template": { 393 | "prefix": "j-module-position", 394 | "description": "Add a module position to a template.", 395 | "body": [ 396 | "" 397 | ] 398 | }, 399 | "J - Add a Function Docblock and Declaration": { 400 | "prefix": "j-function", 401 | "description": "Standard Joomla function declaration.", 402 | "body": [ 403 | "/**", 404 | " * $1", 405 | " *", 406 | " * @param string $aParam Param", 407 | " *", 408 | " * @return void", 409 | " */", 410 | "public function $2()", 411 | "{", 412 | "\t$3", 413 | "}" 414 | ] 415 | } 416 | } 417 | --------------------------------------------------------------------------------