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

Alternative syntax for 'deftemplate' and 'defsnippet' #13

Open
superbobry opened this issue Jun 7, 2012 · 9 comments
Open

Alternative syntax for 'deftemplate' and 'defsnippet' #13

superbobry opened this issue Jun 7, 2012 · 9 comments

Comments

@superbobry
Copy link
Contributor

I was thinking -- maybe we can use metadata notation for defining :compiled templates and snippets? this will allow creating private templates, ex:

(deftemplate ^{:compiled true :private true} 
  my-internal-template 
  ["#content"] ...)
@ckirkendall
Copy link
Owner

Not sure you can use meta like this with a macro but a map instead of key word for options I think is a brilliant idea. It gives us a syntax that is expandable without having to change the basic structure.

@superbobry
Copy link
Contributor Author

Turns out you actually can use metadata in macros calls:

user=> (defmacro deftemplate [name & _] (pr-str (meta name)))
#'user/deftemplate
user=> (macroexpand-1 '(deftemplate ^:private foo))
"{:private true}"

@ckirkendall
Copy link
Owner

Were you doing this in a clojurescript repl? If not can you try it in a clojurescript repl. Not all the information you normally get in clojure is passed by the clojurescript compiler during macro expansion. If we can do this that would be great. If the clojurescript repl does not work, I can work on adding to the clojurescript compiler. I already have to add sending the namespace of symbols.

@superbobry
Copy link
Contributor Author

Nope, that was a Clojure repl, here's a ClojureScript example:

;; macros.clj
(defmacro deftemplate [name & _]
  `(.log js/console (pr-str ~(meta name))))

;; test.cljs
(deftemplate ^:private foo)

When I try this, I see {:private true} in the browser console, so I guess it's possible in the ClojureScript as well.

@ckirkendall
Copy link
Owner

That is great, I like this a lot better than the :compile :remote setup we
had.

CK

On Thu, Jun 7, 2012 at 4:39 PM, Sergei Lebedev <
reply@reply.github.com

wrote:

Nope, that was a Clojure repl, here's a ClojureScript example:

;; macros.clj
(defmacro deftemplate [name & _]
  `(.log js/console (pr-str ~(meta name))))

;; test.cljs
(deftemplate ^:private foo)

When I try this, I see {:private true} in the browser console, so I
guess it's possible in the ClojureScript as well.


Reply to this email directly or view it on GitHub:
#13 (comment)

@ckirkendall
Copy link
Owner

The more I think about this the more I love it! Its clean, doesn't affect the syntax of the macro and can be extended easily. If I get some time this weekend I will take a crack at this, unless you are already implementing something.

@superbobry
Copy link
Contributor Author

One more thing we need to decide on: do we allow passing metadata to the generated functions, or is it enfocus-only? :private is a good example of this.

@superbobry
Copy link
Contributor Author

I've created a feature/metadata branch in my fork.

@ckirkendall
Copy link
Owner

@superbobry I noticed in your branch you have the location as part of the meta data. I would like to keep the syntax as consistent as possible. The location is a required part and should remain as part of the normal syntax where as private and compiled are optional inputs best left in the meta data. What you got so far looks great, I am thinking about moving towards 1.0 release and would love to have this be part the first release. I have finished up quite a bit of the Domina migration and If you want to concentrate on this I can take a look at the event stuff. Thanks again for helping out with Enfocus it is very appreciated!

CK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants