Discussion:
[Lift] Snippet composition (in the sense of "and then") for plugins
Francois
2018-07-24 10:05:50 UTC
Permalink
Hello,

I have a use case where I want to compose (in the function meaning)
snippet to allows to build plugins.

Basically, I would like to be able to extends / prepend / append other
snippet to the one in the core app.

Let say I have that code:

class CoreAppSnippet extends DispatchSnippet {

  def dispatch = {
    case "appOnly" => appOnly
    case "main"    => appMain
  }
  ...
}


I would like to be able to have an other snippet being able to
contribute that:


class PluginSnippet extends DispatchSnippet {

  def predispatch = {
    case "main" => plugin1
  }
  def postdispatch = {
    case "main" => plugin2
    case "pluginOnly" => pluginOnly
  }

  ...
}


So that the resulting snippet dispatch is logically:

mergedDispatch = {
  case "main" => plugin2(appMain(plugin1)
  case "appOnly" => appOnly
  case "pluginOnly" => pluginOnly

         }


I can do it today by having a special trait for "extendable snippet"
with that logic in place (and with a side pool of "extension snippet"
object, and some key identifier like the class FQN - it's actually
something we do since ~8 years), but I was wondering if there wasn't
something built-in for that ?

Thanks !
--
Francois ARMAND - @fanf42
https://github.com/Normation/rudder
http://www.normation.com
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Francois
2018-07-24 10:09:43 UTC
Permalink
Post by Francois
Hello,
I have a use case where I want to compose (in the function meaning)
snippet to allows to build plugins.
Basically, I would like to be able to extends / prepend / append other
snippet to the one in the core app.
class CoreAppSnippet extends DispatchSnippet {
  def dispatch = {
    case "appOnly" => appOnly
    case "main"    => appMain
  }
  ...
}
I would like to be able to have an other snippet being able to
class PluginSnippet extends DispatchSnippet {
  def predispatch = {
    case "main" => plugin1
  }
  def postdispatch = {
    case "main" => plugin2
    case "pluginOnly" => pluginOnly
  }
  ...
}
mergedDispatch = {
  case "main" => plugin2(appMain(plugin1)
  case "appOnly" => appOnly
  case "pluginOnly" => pluginOnly
         }
I can do it today by having a special trait for "extendable snippet"
with that logic in place (and with a side pool of "extension snippet"
object, and some key identifier like the class FQN - it's actually
something we do since ~8 years), but I was wondering if there wasn't
something built-in for that ?
Thanks !
Oh ! If there is several snippet extending an other one, the idea is to
have a the composition done in the order (or reverse order, I don't
care) of the plugin addition/registration/loading/whatever cause the
corresponding snippet to be known by lift.

Thanks
--
Francois ARMAND - @fanf42
https://github.com/Normation/rudder
http://www.normation.com
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Matt Farmer
2018-07-29 15:08:22 UTC
Permalink
Hi Francois,

Have you considered just wrapping the "plugin" snippet around the markup
for the original snippet? With eager_eval you could achieve this same
effect with a small markup change. For example:

<div data-lift="SnippetTwo?eager_eval=true">
<div data-lift="SnippetOne"> ... </div>
</div>

This logically behaves like:

SnippetTwo(SnippetOne(x))

Matt
Post by Francois
Hello,
I have a use case where I want to compose (in the function meaning)
snippet to allows to build plugins.
Basically, I would like to be able to extends / prepend / append other
snippet to the one in the core app.
class CoreAppSnippet extends DispatchSnippet {
def dispatch = {
case "appOnly" => appOnly
case "main" => appMain
}
...
}
I would like to be able to have an other snippet being able to contribute
class PluginSnippet extends DispatchSnippet {
def predispatch = {
case "main" => plugin1
}
def postdispatch = {
case "main" => plugin2
case "pluginOnly" => pluginOnly
}
...
}
mergedDispatch = {
case "main" => plugin2(appMain(plugin1)
case "appOnly" => appOnly
case "pluginOnly" => pluginOnly
}
I can do it today by having a special trait for "extendable snippet" with
that logic in place (and with a side pool of "extension snippet" object,
and some key identifier like the class FQN - it's actually something we do
since ~8 years), but I was wondering if there wasn't something built-in for
that ?
Thanks !
Oh ! If there is several snippet extending an other one, the idea is to
have a the composition done in the order (or reverse order, I don't care)
of the plugin addition/registration/loading/whatever cause the
corresponding snippet to be known by lift.
Thanks
--
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
https://www.assembla.com/wiki/show/liftweb/Posting_example_code
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...