aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsmihica <smihica@gmail.com>2014-06-11 18:54:31 +0900
committersmihica <smihica@gmail.com>2014-06-11 18:54:31 +0900
commit949d3d07b1d120be003369d1fc97f78e1a590062 (patch)
treef252e759fd9f78ae3b6737afeb9bcbb837d1306b
parent8fe79a5ffdff3846b8ae94622762acf935177595 (diff)
downloademmet-mode-949d3d07b1d120be003369d1fc97f78e1a590062.tar.lz
emmet-mode-949d3d07b1d120be003369d1fc97f78e1a590062.tar.xz
emmet-mode-949d3d07b1d120be003369d1fc97f78e1a590062.zip
Added Lorem Ipsum codes
-rw-r--r--emmet-mode.el33
-rw-r--r--src/html-abbrev.el32
-rw-r--r--src/lorem.el1
-rw-r--r--src/test.el50
4 files changed, 106 insertions, 10 deletions
diff --git a/emmet-mode.el b/emmet-mode.el
index afb1fcd..fa866ae 100644
--- a/emmet-mode.el
+++ b/emmet-mode.el
@@ -2543,7 +2543,9 @@ tbl))
(let ((expr (car it)) (input (cdr it)))
(destructuring-bind (expr . input)
(emmet-tag-text expr input)
- (emmet-expand-tag-alias expr input)))))))
+ (or
+ (emmet-expand-lorem expr input)
+ (emmet-expand-tag-alias expr input))))))))
(emmet-default-tag input)))
(defun emmet-get-first-tag (expr)
@@ -2555,6 +2557,21 @@ tbl))
(emmet-get-first-tag (cdr expr))))
nil))
+(defun emmet-lorem (input)
+ (emmet-aif
+ (and (stringp input) (emmet-regex "\\(?:lorem\\|ipsum\\)\\([0-9]*\\)" input '(0 1)))
+ (let ((w (elt it 1)))
+ (let ((word-num (if (string-equal w "") 30 (read w))))
+ word-num))))
+
+(defun emmet-expand-lorem (tag input)
+ (let ((tag-data (cadr tag)))
+ (let ((tag-name (car tag-data)))
+ (emmet-aif (emmet-lorem tag-name)
+ (if (equalp (cdr tag-data) '(t nil nil nil nil))
+ `((text (lorem ,it)) . ,input)
+ `((tag ("div" ,@(subseq tag-data 1 -1) (lorem ,it))) . ,input))))))
+
(defun emmet-expand-tag-alias (tag input)
(let ((tag-data (cadr tag)))
(let ((tag-name (car tag-data)))
@@ -2792,11 +2809,22 @@ tbl))
"hic" (emmet-primary-filter emmet-make-hiccup-tag)
"e" (emmet-escape-xml)))
+(defun emmet-instantiate-lorem-expression (input)
+ (if input
+ (if (consp input)
+ (if (and (eql (car input) 'lorem) (numberp (cadr input)))
+ (emmet-lorem-generate (cadr input))
+ (cons (emmet-instantiate-lorem-expression (car input))
+ (emmet-instantiate-lorem-expression (cdr input))))
+ input)))
+
(defun emmet-primary-filter (input proc)
"Process filter that needs to be executed first, ie. not given output from other filter."
(if (listp input)
(let ((tag-maker (cadr proc)))
- (emmet-transform-ast input tag-maker))
+ (emmet-transform-ast
+ (emmet-instantiate-lorem-expression input)
+ tag-maker))
nil))
(defun emmet-process-filter (filters input)
@@ -3161,6 +3189,7 @@ tbl))
(let ((next (emmet-lorem-generate (- count sl))))
(if (string-equal next "") ""
(concat " " next))))))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; CSS abbrev:
diff --git a/src/html-abbrev.el b/src/html-abbrev.el
index 4427850..2c4a0b5 100644
--- a/src/html-abbrev.el
+++ b/src/html-abbrev.el
@@ -161,7 +161,9 @@
(let ((expr (car it)) (input (cdr it)))
(destructuring-bind (expr . input)
(emmet-tag-text expr input)
- (emmet-expand-tag-alias expr input)))))))
+ (or
+ (emmet-expand-lorem expr input)
+ (emmet-expand-tag-alias expr input))))))))
(emmet-default-tag input)))
(defun emmet-get-first-tag (expr)
@@ -173,6 +175,21 @@
(emmet-get-first-tag (cdr expr))))
nil))
+(defun emmet-lorem (input)
+ (emmet-aif
+ (and (stringp input) (emmet-regex "\\(?:lorem\\|ipsum\\)\\([0-9]*\\)" input '(0 1)))
+ (let ((w (elt it 1)))
+ (let ((word-num (if (string-equal w "") 30 (read w))))
+ word-num))))
+
+(defun emmet-expand-lorem (tag input)
+ (let ((tag-data (cadr tag)))
+ (let ((tag-name (car tag-data)))
+ (emmet-aif (emmet-lorem tag-name)
+ (if (equalp (cdr tag-data) '(t nil nil nil nil))
+ `((text (lorem ,it)) . ,input)
+ `((tag ("div" ,@(subseq tag-data 1 -1) (lorem ,it))) . ,input))))))
+
(defun emmet-expand-tag-alias (tag input)
(let ((tag-data (cadr tag)))
(let ((tag-name (car tag-data)))
@@ -410,11 +427,22 @@
"hic" (emmet-primary-filter emmet-make-hiccup-tag)
"e" (emmet-escape-xml)))
+(defun emmet-instantiate-lorem-expression (input)
+ (if input
+ (if (consp input)
+ (if (and (eql (car input) 'lorem) (numberp (cadr input)))
+ (emmet-lorem-generate (cadr input))
+ (cons (emmet-instantiate-lorem-expression (car input))
+ (emmet-instantiate-lorem-expression (cdr input))))
+ input)))
+
(defun emmet-primary-filter (input proc)
"Process filter that needs to be executed first, ie. not given output from other filter."
(if (listp input)
(let ((tag-maker (cadr proc)))
- (emmet-transform-ast input tag-maker))
+ (emmet-transform-ast
+ (emmet-instantiate-lorem-expression input)
+ tag-maker))
nil))
(defun emmet-process-filter (filters input)
diff --git a/src/lorem.el b/src/lorem.el
index 77f01f3..e65cad7 100644
--- a/src/lorem.el
+++ b/src/lorem.el
@@ -114,3 +114,4 @@
(let ((next (emmet-lorem-generate (- count sl))))
(if (string-equal next "") ""
(concat " " next))))))))
+
diff --git a/src/test.el b/src/test.el
index 73c17b8..3477192 100644
--- a/src/test.el
+++ b/src/test.el
@@ -52,6 +52,12 @@
'emmet-html-transform
,@tests))
+(defmacro define-emmet-unit-test-case (name fn &rest tests)
+ `(emmet-test-cases 'assign ',name
+ ,fn
+ ',(loop for x on tests by #'cddr collect
+ (cons (car x) (cadr x)))))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; XML-abbrev tests
@@ -344,6 +350,44 @@
"xxx#id.cls p=1{txt}"
("<xxx id=\"id\" class=\"cls\" p=\"1\">txt</xxx>"))
+(define-emmet-unit-test-case Lorem-ipsum
+ #'emmet-expr
+ "lorem"
+ ((filter ("html") (text (lorem 30))) . "")
+
+ "ipsum"
+ ((filter ("html") (text (lorem 30))) . "")
+
+ "p*3>lorem10"
+ ((filter
+ ("html")
+ (list ((parent-child (tag ("p" t nil nil nil nil)) (text (lorem 10)))
+ (parent-child (tag ("p" t nil nil nil nil)) (text (lorem 10)))
+ (parent-child (tag ("p" t nil nil nil nil)) (text (lorem 10)))))) . "")
+
+ "ul.generic-list>ipsum3*3"
+ ((filter
+ ("html")
+ (parent-child
+ (tag ("ul" t nil ("generic-list") nil nil))
+ (list ((text (lorem 3))
+ (text (lorem 3))
+ (text (lorem 3)))))) . "")
+
+ "ul.generic-list>(li>lorem1000)*3"
+ ((filter
+ ("html")
+ (parent-child
+ (tag ("ul" t nil ("generic-list") nil nil))
+ (list ((parent-child
+ (tag ("li" t nil nil nil nil))
+ (text (lorem 1000)))
+ (parent-child
+ (tag ("li" t nil nil nil nil))
+ (text (lorem 1000)))
+ (parent-child
+ (tag ("li" t nil nil nil nil))
+ (text (lorem 1000))))))) . ""))
(define-emmet-transform-html-test-case Filter-comment
"a.b|c" ("<!-- .b -->"
@@ -396,12 +440,6 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CSS-abbrev tests
-(defmacro define-emmet-unit-test-case (name fn &rest tests)
- `(emmet-test-cases 'assign ',name
- ,fn
- ',(loop for x on tests by #'cddr collect
- (cons (car x) (cadr x)))))
-
(define-emmet-unit-test-case CSS-toknize
#'emmet-css-toknize
"" ("")