From ca973c76e9a391fc868025d98d16fd249d00c7c9 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Wed, 28 Aug 2019 00:11:08 -0700 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98oni-twig=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now this only contains snippets. --- .gitlab-ci.yml | 11 +++++++ GNUmakefile | 16 ++++++++- oni-twig/Cask | 11 +++++++ oni-twig/oni-twig.el | 54 +++++++++++++++++++++++++++++++ oni-twig/snippets/twig-mode/_self | 5 +++ oni-twig/snippets/twig-mode/blk | 7 ++++ oni-twig/snippets/twig-mode/def | 7 ++++ oni-twig/snippets/twig-mode/ext | 5 +++ oni-twig/snippets/twig-mode/for | 7 ++++ oni-twig/snippets/twig-mode/if | 7 ++++ oni-twig/snippets/twig-mode/ife | 9 ++++++ oni-twig/snippets/twig-mode/iif | 5 +++ oni-twig/snippets/twig-mode/imp | 7 ++++ oni-twig/snippets/twig-mode/mac | 7 ++++ oni-twig/snippets/twig-mode/set | 5 +++ 15 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 oni-twig/Cask create mode 100644 oni-twig/oni-twig.el create mode 100644 oni-twig/snippets/twig-mode/_self create mode 100644 oni-twig/snippets/twig-mode/blk create mode 100644 oni-twig/snippets/twig-mode/def create mode 100644 oni-twig/snippets/twig-mode/ext create mode 100644 oni-twig/snippets/twig-mode/for create mode 100644 oni-twig/snippets/twig-mode/if create mode 100644 oni-twig/snippets/twig-mode/ife create mode 100644 oni-twig/snippets/twig-mode/iif create mode 100644 oni-twig/snippets/twig-mode/imp create mode 100644 oni-twig/snippets/twig-mode/mac create mode 100644 oni-twig/snippets/twig-mode/set diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cc85730..e27709d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -96,6 +96,16 @@ package-oni-ruby: paths: - oni-ruby/dist/ +package-oni-twig: + stage: pre-package-multifile + before_script: + - rm -rf oni-elisp/dist + script: + - cask --path oni-twig package + artifacts: + paths: + - oni-twig/dist/ + test-oni-alert: stage: test script: make test-oni-alert @@ -152,6 +162,7 @@ package: - package-oni-php - package-oni-python - package-oni-ruby + - package-oni-twig before_script: - rm -rf bin/ - mkdir bin/ diff --git a/GNUmakefile b/GNUmakefile index 2b478ff..b409d96 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,7 +4,7 @@ PACKAGE_TARGETS := $(addprefix package-,$(FILES)) package: $(PACKAGE_TARGETS) package-oni-conf package-oni-css package-oni-elisp \ package-oni-haml package-oni-html package-oni-nxml package-oni-org \ - package-oni-php package-oni-python package-oni-ruby + package-oni-php package-oni-python package-oni-ruby package-oni-twig package-%: % emacs --batch \ @@ -72,6 +72,12 @@ package-oni-ruby: --funcall package-initialize \ --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-ruby/dist/*.tar\") #'string>)))" +package-oni-twig: + emacs --batch \ + --load oni-package.el \ + --funcall package-initialize \ + --eval "(package-upload-file (car (sort (file-expand-wildcards \"oni-twig/dist/*.tar\") #'string>)))" + install-%: emacs --batch \ --load oni-package.el \ @@ -160,6 +166,14 @@ install-oni-ruby: $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-ruby/dist/*.tar\") #'string>)))" +install-oni-twig: + emacs --batch \ + --load oni-package.el \ + --fluncall package-initialize \ + --eval '(package-refresh-contents)' \ + $(foreach DEP,$(DEPS),--eval "(package-install-file \"$(DEP).el\")") \ + --eval "(package-install-file (car (sort (file-expand-wildcards \"oni-twig/dist/*.tar\") #'string>)))" + test-%: install-% emacs --batch \ --load oni-package.el \ diff --git a/oni-twig/Cask b/oni-twig/Cask new file mode 100644 index 0000000..cf1a2a3 --- /dev/null +++ b/oni-twig/Cask @@ -0,0 +1,11 @@ +(source gnu) +(source melpa) + +(package-file "./oni-twig.el") + +(depends-on "twig-mode") +(depends-on "oni-yasnippet" :git "../" :files ("oni-yasnippet.el")) + +(files + "*.el" + ("snippets" "./snippets/*")) diff --git a/oni-twig/oni-twig.el b/oni-twig/oni-twig.el new file mode 100644 index 0000000..c71b51a --- /dev/null +++ b/oni-twig/oni-twig.el @@ -0,0 +1,54 @@ +;;; oni-twig.el --- Twig configuration -*- lexical-binding: t; -*- + +;; Copyright (C) 2019 Tom Willemse + +;; Author: Tom Willemse +;; Keywords: local +;; Version: 20190828000459 +;; Package-Requires: (twig-mode oni-yasnippet) + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Configuration for ‘twig-mode’. + +;;; Code: + +(require 'yasnippet) + +(defconst oni-twig-root + (file-name-directory + (or load-file-name + (buffer-file-name))) + "The directory where ‘oni-twig’ was loaded from.") + +(defconst oni-twig-snippets-dir + (expand-file-name "snippets" oni-twig-root) + "The directory where ‘oni-twig’ stores its snippets.") + +;;;###autoload +(defun oni-twig-snippets-initialize () + "Initialize the snippets for ‘oni-twig’." + (when (boundp 'yas-snippet-dirs) + (add-to-list 'yas-snippet-dirs oni-twig-snippets-dir)) + (yas-load-directory oni-twig-snippets-dir)) + +;;;###autoload +(with-eval-after-load 'twig-mode + (with-eval-after-load 'yasnippet + (oni-twig-snippets-initialize))) + +(provide 'oni-twig) +;;; oni-twig.el ends here diff --git a/oni-twig/snippets/twig-mode/_self b/oni-twig/snippets/twig-mode/_self new file mode 100644 index 0000000..c441690 --- /dev/null +++ b/oni-twig/snippets/twig-mode/_self @@ -0,0 +1,5 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: _self +# key: _self +# -- +{% import _self as ${1:`(file-name-nondirectory (file-name-sans-extension buffer-file-name))`} %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/blk b/oni-twig/snippets/twig-mode/blk new file mode 100644 index 0000000..bb100a3 --- /dev/null +++ b/oni-twig/snippets/twig-mode/blk @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: block +# key: blk +# -- +{% block $1 %} + $0 +{% endblock %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/def b/oni-twig/snippets/twig-mode/def new file mode 100644 index 0000000..78dead4 --- /dev/null +++ b/oni-twig/snippets/twig-mode/def @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: default value +# key: def +# -- +{% if $1 is not defined %} + {% set $1 = $2 %} +{% endif %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/ext b/oni-twig/snippets/twig-mode/ext new file mode 100644 index 0000000..501cae8 --- /dev/null +++ b/oni-twig/snippets/twig-mode/ext @@ -0,0 +1,5 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: extends +# key: ext +# -- +{% extends "$1" %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/for b/oni-twig/snippets/twig-mode/for new file mode 100644 index 0000000..01c0cc5 --- /dev/null +++ b/oni-twig/snippets/twig-mode/for @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: for +# key: for +# -- +{% for $1 in $2 %} + `yas-selected-text`$0 +{% endfor %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/if b/oni-twig/snippets/twig-mode/if new file mode 100644 index 0000000..a9385d9 --- /dev/null +++ b/oni-twig/snippets/twig-mode/if @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: if +# key: if +# -- +{% if $1 %} + $0 +{% endif %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/ife b/oni-twig/snippets/twig-mode/ife new file mode 100644 index 0000000..a4d18f3 --- /dev/null +++ b/oni-twig/snippets/twig-mode/ife @@ -0,0 +1,9 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: if...else +# key: ife +# -- +{% if $1 %} + $0 +{% else %} + +{% endif %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/iif b/oni-twig/snippets/twig-mode/iif new file mode 100644 index 0000000..df26b61 --- /dev/null +++ b/oni-twig/snippets/twig-mode/iif @@ -0,0 +1,5 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: Inline if +# key: iif +# -- +{% if $1 %}$0{% endif %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/imp b/oni-twig/snippets/twig-mode/imp new file mode 100644 index 0000000..01ceb69 --- /dev/null +++ b/oni-twig/snippets/twig-mode/imp @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: import +# key: imp +# -- +{% import "${1:module}" as ${1:$(if (string-match "/\\\\([^/]*\\\\)$" yas-text) + (match-string 1 yas-text) + yas-text)} %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/mac b/oni-twig/snippets/twig-mode/mac new file mode 100644 index 0000000..d4e480a --- /dev/null +++ b/oni-twig/snippets/twig-mode/mac @@ -0,0 +1,7 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: macro +# key: mac +# -- +{% macro ${1:name}(${2:args}) %} + $0 +{% endmacro %} \ No newline at end of file diff --git a/oni-twig/snippets/twig-mode/set b/oni-twig/snippets/twig-mode/set new file mode 100644 index 0000000..715c828 --- /dev/null +++ b/oni-twig/snippets/twig-mode/set @@ -0,0 +1,5 @@ +# -*- mode: snippet; require-final-newline: nil -*- +# name: set +# key: set +# -- +{% set $1 = $2 %} \ No newline at end of file