Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Anonymous helper functions AKA Inline JavaScript expressions #176

Closed
wants to merge 45 commits into from

Conversation

xiphias
Copy link

@xiphias xiphias commented Oct 8, 2015

I spent some time having fun implementing this feature, which creates anonymous helper functions.
It works well enough, although better and more unit tests are needed that can test the created functions.
It works with templates and files as well, and works with #{} and !{} syntax and if markups.
The next logical step would be anonymous events (and inlne coffeescript support), but that doesn't belong to this CL.

@xiphias
Copy link
Author

xiphias commented Oct 8, 2015

This is what simple-todos looks like for me while still working:

simple-todos.jade:

 head
  title Todo List

 body
  .container
    header
      h1 Todo List (#{Tasks.find({checked: {$ne: true}}).count()})
      label.hide-completed
        input(type="checkbox" checked="#{Session.get('hideCompleted')}")
        | Hide Completed Tasks

      +loginButtons
      if currentUser
        form.new-task
          input(type="text" name="text" placeholder="Type to add new tasks!")
    ul
      each tasks
        +task

task.tpl.jade:

li(class="{{#if checked}}checked{{/if}} {{#if private}}private{{/if}}")
    button.delete ×
    input.toggle-checked(type="checkbox" checked=checked)
    if this.owner==Meteor.userId()
      button.toggle-private
        if private
          | Private
        else
          | Public
    span.text <strong>#{username}</strong> - #{text}

@mquandalle
Copy link
Owner

Hey @xiphias, thank you for this PR, we finally get a chance to fix issue n° #1 :-) I will have to do a careful review of the code before merging. Could you please add a few comments in the code before I dig in?

Also as you noticed, this feature definitely needs more tests, but we can do that in parallel.

@xiphias
Copy link
Author

xiphias commented Oct 8, 2015

Sure, I'll write some comments.

@@ -30,3 +30,49 @@ Tinytest.add("JadeCompiler - compile templates", function(test) {
test.equal(JadeCompiler.compile(template),
"(function() {\n return HTML.P(\"hello world\");\n})");
});

var template3 = wrapInTemplate("hello",
["if helper arg1 arg2",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use ES6 template string here, just add the meteor ecmascript package and replace " by `.

@xiphias
Copy link
Author

xiphias commented Oct 8, 2015

I added the comments, switched to ES6 and fixed Travis build.

@xiphias
Copy link
Author

xiphias commented Oct 9, 2015

A limitation that I found is that the mixins can't have too complex JavaScript..I guess Jade Lexer needs to be modified for that.

@darrynten
Copy link
Contributor

This is excellent! +1

@xiphias
Copy link
Author

xiphias commented Oct 14, 2015

Hey @mquandalle, I added some bug fixes and better tests, could you please take another look at the pull request?

@mquandalle
Copy link
Owner

Sure! Also @dalgard, I haven’t reviewed your fork yet but did you implement something similar? Do you have an opinion on this?

@dalgard
Copy link

dalgard commented Oct 14, 2015

Oh, hi @mquandalle – welcome back! :)

I haven't implemented inline JavaScript expressions – I think it's a really bad idea. As I've written elsewhere, the templating paradigm that Blaze builds upon is a logicless one – it is not in my opinion desirable to embed JavaScript in Blaze templates, quite the contrary.

The only thing I would recommend is for @xiphias to create another package that extends this one.

@xiphias
Copy link
Author

xiphias commented Oct 14, 2015

I have no problem with having a separate package if you don't like the direction. I don't really like the MVC separation that most systems use, and prefer to write logic and UI at the same place, but I also acknowledge that it's not the mainstream software design philosophy. Reactivity in Meteor partly makes the separation of controller and view unnecessary, and in my view having view and event logic in the jade templates make the code easier to maintain, for a non-designer programmer. It also makes it harder for non-programmer designers, but I don't generally work with designers who modify my templates. So it's up to you to make the decision.

@dalgard
Copy link

dalgard commented Oct 14, 2015

@xiphias: I totally agree with you in the sense that React is a nice addition to Meteor, and that I hope that Blaze 2 will embrace some kind of JSX style. But I don't think these concepts should be brought into Jade/Spacebars.

@xiphias
Copy link
Author

xiphias commented Oct 14, 2015

I'm not really talking about React/JSX, which has it's own disadvantages. Anyways, if the decision by @mquandalle is not having this patch either and other people are not interested, I'll probably just create some new features for myself without going through commenting & preparing for submission again.

@xiphias
Copy link
Author

xiphias commented Oct 14, 2015

@mquandalle I added anonymous events as well, please check it if you like it. I think it simplifies Meteor development a lot. You can check the simple-todos implementation with the new features here in the README:
https://github.com/xiphias/meteor-jade

@xiphias
Copy link
Author

xiphias commented Oct 23, 2015

Thanks very much, I'll do that and update here.
2015. okt. 23. 4:26 ezt írta ("Damon Blais" notifications@github.com):

@xiphias https://github.com/xiphias Please use a Meteor Build Server to
configure your package for architectures.

shadow@localhost$ meteor admin get-machine os.linux.x86_64 --minutes 5
user@buildserver# ... build
user@buildserver# meteor publish-for-arch ...

That's the recommended way of packaging, as it's a stable configuration
that's maintained by them. You can read more with the command meteor help
admin or meteor help admin get-machine

You need only be logged in to your meteor account to use this command, not
be a Meteor Administrator as the name would suggest (I think they mean
"Maintainer", but I guess they failed a bit on the nomer.)


Reply to this email directly or view it on GitHub
#176 (comment)
.

@AlbinoGeek AlbinoGeek mentioned this pull request Oct 24, 2015
@xiphias
Copy link
Author

xiphias commented Oct 25, 2015

Thanks for the help, I found the problem with the build machines: I needed to add the right coffee-script npm dependency (it's interesting that after that I added it, it seems that the build machine is not necessary). Could you please try the newest version? (xiphy:jade-coffee@0.1.4)

@AlbinoGeek
Copy link

Hello @xiphias ,

The point of the build machines (that we get access to for free, which is a pretty good deal; as 5 minutes of AWS time every few days can add up to $10 or so, it's not a small cost for the end developers without servers to test on) is explained pretty well in the Build Machines page.

And specifically this following section is important in this case: Why is it important to use pre-configured build-machines. Why shouldn't I just publish from my laptop?

@xiphias
Copy link
Author

xiphias commented Oct 26, 2015

Hey, @AlbinoGeek,
I tried to do that, but I get this error message on the Linux build machine:
=> Errors while publishing build:
While publishing package build for xiphy:jade-coffee:
error: Cannot override existing build

Also I think that as I have a windows machine, and I haven't downloaded 4 cross-compilers on it, maybe meteor publish already does this. The only problem was that the error messages on the build machines weren't displayed when I was using meteor publish, so I didn't know what's the problem.
Also I couldn't find any detailed documentation on publishing packages using publish-with-arch.
I'm happy to give you maintainer rights to the packages and to my git repository if you give me your Meteor login though. I already added @mquandalle to the package maintainers just in case.

@AlbinoGeek
Copy link

Hi @xiphias ,

It turns out this is intentional (or at least known behaviour) as of posts such as This particular closed issue on Meteor's GitHub that explains that if a platform agnostic package already exists (i.e: Meteor detected no platform-specific code), then you may have an "all platforms" package published already (IsoPack)

Nothing wrong with that, and your builds work now on my projects :). Good one.

(If your package has no platform-specific code, no additional work is required to build the package other than compiling it on a single target machine, and Meteor will automatically create the required IsoPack for all platforms from this file.) Only if Meteor detects that your package (or dependency chain) contains platform-specific code, then the build servers may be required again.

@xiphias
Copy link
Author

xiphias commented Oct 26, 2015

Thanks!
I just released a bug fix for the bug that I found today, feel free to
upgrade.
I think that the system is quite fun to work in, what is mostly missing for
me in my development is nice with/let support and multi-line quotes (as I
prefer having 0 helpers and as much code in my template as possible).

If you have experience in Meteor development and like the extension (but
don't want to get into the codebase), it would be nice if you could help
with writing about your experience and suggestions for people who are
starting to develop with jade-coffee, we could add it to the main page as
well. Anyways, have fun like me :)

On Mon, Oct 26, 2015 at 4:53 PM, Damon Blais notifications@github.com
wrote:

Hi @xiphias https://github.com/xiphias ,

It turns out this is intentional (or at least known behaviour) as of posts
such as This particular closed issue on Meteor's GitHub
meteor/meteor#4477 (comment)
that explains that if a platform agnostic package already exists (i.e:
Meteor detected no platform-specific code), then you may have an "all
platforms" package published already (IsoPack)

Nothing wrong with that, and your builds work now on my projects :). Good
one.


Reply to this email directly or view it on GitHub
#176 (comment)
.

@AlbinoGeek
Copy link

@xiphias Sure, any means we can communicate other than this thread? I don't want other to be notified on our conversation about jade-coffee :). mail via: (my github username) (at) gmail (dot) com , would work.

@AlbinoGeek
Copy link

@mquandalle We're merging in all changes from mquandalle:master branch back into xiphias:master , this PR might have many less differences soon.

@AlbinoGeek
Copy link

Right, I'll work towards fixing some of those 162 linter errors, heh.

@mquandalle
Copy link
Owner

If you have a modern version of eslint, eslint --fix will help you ;-)

@AlbinoGeek
Copy link

This still can't be merged, handler.js changes in 1.2 have not been implemented yet. See: Commit 215a966 And thanks for the heads up on eslint.

@mquandalle
Copy link
Owner

Closing, because this is too old and can’t be merged.

@mquandalle mquandalle closed this Jul 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants