ckirkendall / enfocus

DOM manipulation and templating library for ClojureScript inspired by Enlive.
http://ckirkendall.github.com/enfocus-site/
371 stars 41 forks source link

Allow 'internable' templates #3

Closed superbobry closed 12 years ago

superbobry commented 12 years ago

It would be nice if enfocus allowed interning local templates during compilation (similar to what one does in its sample application), instead of loading them via XHR, what do you think?

(deftemplate "path/to/local/template" [...]
    ;; the usual transformation stuff
    )
ckirkendall commented 12 years ago

I completely agree. I been thinking about this for a while now. Part of the thing I have been struggling with is how to integrate this type of template into the existing structure without introducing complexity to the syntax of deftemplate and defsnippet. I have a few ideas:

(defsnippet :compiled "...uri..." [...enlive syntax...] [..args..] ;;normal enfocus transform )

or

(defcsnippet "..uri.." [...enlive syntax...] ;; normal transform stuff )

What do you think?

superbobry commented 12 years ago

I like the first option better -- it's more straightforward than the 'c' in 'def_c_snippet' which is hard to spot (at least for me :)

Also, going offtopic, have you considered using domina for DOM manipulations? some of the things defined in core.cljs are already provided by domina -- for example 'style-set'. I think delegating this functionality to another lib will make enfocus both easier to maintain and use.

ckirkendall commented 12 years ago

Thanks on the feedback and yes I am planning on using Domina as the base layer eventually. I have been working Luke on adding features to Domina so I can do that very thing. Now that Luke finished up the new event model I should be able to remove a bunch of code and replace it with Domina underpinnings.

si14 commented 12 years ago

+1 here to @superbobry and thanks for the great lib!

ckirkendall commented 12 years ago

I am going to add another issue for the move to domina as a base layer for enfocus.

superbobry commented 12 years ago

Mind if I'll try to implement this myself and then submit a PR?

ckirkendall commented 12 years ago

That would be great! On May 16, 2012 7:20 AM, "Sergei Lebedev" < reply@reply.github.com> wrote:

Mind if I try to implement this myself and then submit a PR?


Reply to this email directly or view it on GitHub: https://github.com/ckirkendall/enfocus/issues/3#issuecomment-5738528

superbobry commented 12 years ago

Okay, I got it working, but it looks like we can't make this change without breaking backward compatibility. The current implementation is:

(defmacro deftemplate [sym mode uri args & forms]
  `(do
     ~@(case mode
         :remote   `(enfocus.core/load-remote-dom ~uri)
         :compiled (load-local-dom uri))
     (enfocus.macros/create-dom-action
      ~sym
      #(enfocus.core/get-cached-dom ~uri)
      true ~args ~@forms)))

So old deftemplate behavior can be achieved with :remote tag. Is there a way to have both old and new versions for a single name?

ckirkendall commented 12 years ago

How about something more like this. It keeps backwards compatibility. Note: I just scetch this out and have not run it.

(defmacro deftemplate [sym & body]
  (let [[mode [uri args & forms]] (if (= (first body) :compiled) 
                                     [:compiled (rest body)] 
                                     [:remote body])]
    `(do
      ~@(case mode
          :remote   `(enfocus.core/load-remote-dom ~uri)
          :compiled (load-local-dom uri))
      (enfocus.macros/create-dom-action
       ~sym
       #(enfocus.core/get-cached-dom ~uri)
       true ~args ~@forms)))
superbobry commented 12 years ago

Yup, this looks good, thanks :)