Skip to content

Commit f27b111

Browse files
committed
Use org-element instead for inserting.
1 parent a97232b commit f27b111

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

org-chef.el

+35-24
Original file line numberDiff line numberDiff line change
@@ -75,43 +75,54 @@ for more information.")
7575
(defcustom org-chef-prefer-json-ld nil
7676
"Prefer JSON-LD extractor over custom extractor. This is for testing the JSON-LD functionality."
7777
:type 'boolean)
78-
78+
79+
(defun org-chef-to-unordered-list (list)
80+
"Convert a LIST of strings into an org-element plain list"
81+
(if (null list)
82+
nil
83+
`(plain-list nil ,(mapcar #'(lambda (x) `(item (:bullet "-" :pre-blank 0) ,x)) list))))
84+
85+
(defun org-chef-to-ordered-list (list)
86+
"Convert a LIST of strings into an ordered org-element plain list"
87+
(if (null list)
88+
nil
89+
`(plain-list nil ,(mapcar #'(lambda (x) `(item (:bullet "1. " :pre-blank 0) ,x)) list))))
90+
91+
(org-element-interpret-data (org-chef-to-unordered-list '("")))
92+
93+
(defun org-chef-recipe-to-org-element (recipe)
94+
"Convert a RECIPE into an `org-element` AST."
95+
`(headline (:title ,(cdr (assoc 'name recipe)) :level 1)
96+
(property-drawer nil
97+
((node-property (:key "source-url" :value ,(cdr (assoc 'source-url recipe))))
98+
(node-property (:key "servings" :value ,(cdr (assoc 'servings recipe))))
99+
(node-property (:key "prep-time" :value ,(format "%s" (cdr (assoc 'prep-time recipe)))))
100+
(node-property (:key "cook-time" :value ,(format "%s" (cdr (assoc 'cook-time recipe)))))
101+
(node-property (:key "ready-in" :value ,(format "%s" (cdr (assoc 'ready-in recipe)))))))
102+
(headline (:title "Ingredients" :level 2 :pre-blank 1)
103+
,(org-chef-to-unordered-list (cdr (assoc 'ingredients recipe))))
104+
(headline (:title "Directions" :level 2 :pre-blank 1)
105+
,(org-chef-to-ordered-list (cdr (assoc 'directions recipe))))))
106+
107+
(defun org-chef-recipe-to-org (recipe)
108+
"Convert a RECIPE into `org-mode` test."
109+
(org-element-interpret-data (org-chef-recipe-to-org-element recipe)))
110+
79111
(defun org-chef-recipe-insert-org (recipe)
80112
"Insert a RECIPE as an ‘org-mode’ heading."
81-
(org-insert-heading)
82-
(insert (cdr (assoc 'name recipe)))
83-
(org-return)
84-
(org-set-property "source-url" (cdr (assoc 'source-url recipe)))
85-
(org-set-property "servings" (cdr (assoc 'servings recipe)))
86-
(org-set-property "prep-time" (format "%s" (cdr (assoc 'prep-time recipe))))
87-
(org-set-property "cook-time" (format "%s" (cdr (assoc 'cook-time recipe))))
88-
(org-set-property "ready-in" (format "%s" (cdr (assoc 'ready-in recipe))))
89-
(org-insert-subheading t)
90-
(insert "Ingredients")
91-
(org-return)
92-
(org-return)
93-
(org-chef-insert-org-list (cdr (assoc 'ingredients recipe)))
94-
(org-return)
95-
(org-return)
96-
(org-insert-heading)
97-
(insert "Directions")
98-
(org-return)
99-
(org-return)
100-
(org-chef-insert-org-list (cdr (assoc 'directions recipe)) "1."))
101-
113+
(insert
114+
(org-chef-recipe-to-org (recipe))))
102115

103116
(defun org-chef-recipe-org-string (recipe)
104117
"Get an ‘org-mode’ heading string for a RECIPE."
105118
(with-temp-buffer (org-mode)
106119
(org-chef-recipe-insert-org recipe)
107120
(buffer-string)))
108121

109-
110122
(defun org-chef-match-url (BASE URL)
111123
"Match URL against a BASE url."
112124
(not (null (string-match-p (regexp-quote BASE) URL))))
113125

114-
115126
(defun org-chef-fetch-recipe-specific-url (URL)
116127
"Look up a recipe based on a specific URL."
117128
(cond

0 commit comments

Comments
 (0)