Skip to content

Instantly share code, notes, and snippets.

@ClassicOldSong
Created March 25, 2023 22:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassicOldSong/12821236b8ade8093d75b566b52e32fb to your computer and use it in GitHub Desktop.
Save ClassicOldSong/12821236b8ade8093d75b566b52e32fb to your computer and use it in GitHub Desktop.
Prompt trying to teach ChatGPT to write EFML

Use only the information mentioned here, do not use anything from Vue.js, React, Svelte etc.

  1. EF.js is a JavaScript library that uses EFML, a logic-free template language, to create dynamic user interfaces.
  2. EFML is a simple and easy-to-use template language that focuses on data binding and event handling.
  3. In EFML, lines not starting with >#%@.|+- are considered comments.
  4. Each EFML tag, attribute, property, event handler, text node, and mount point must start on a new line.
  5. Tags are defined using the > character, and can include class names and reference names. Shorthand for class names can be used by including a . after the tag name.
  6. Reference names for elements are defined using the # character at the end of the tag definition.
  7. Attributes are defined using the # character, and can include any valid HTML attribute. They must be defined on a new line after the tag definition.
  8. Properties are defined using the % character, and can include any valid JavaScript object property. They must be defined on a new line after the attributes.
  9. Event handlers are defined using the @ character, and can include any valid JavaScript function. They must be defined on a new line after the properties.
  10. Text nodes are defined using the . character, and must start on a new line. Multiline text nodes are defined using the | character, and must also start on a new line.
  11. Single node mount points are defined using the - character, and must start on a new line.
  12. Collection mount points are defined using the + character, and must start on a new line. They cannot include a reference name after the mount point definition, nor can they have children templates.
  13. Mustaches are used for binding data and must not contain any logic. They can be used in text nodes, attributes, and properties by wrapping the data with double curly braces ({{}}).
  14. EFML does not support any logical calculations like ternary operators and conditional statements.
  15. Components can only be imported or created inline with t method from ef.js, but not extended from another class.
  16. Attributes cannot be written inline. They must be defined on a new line after the tag definition, using the # character.
  17. Every text node must start with either . or |, depending on whether it's a single-line or multi-line text node.
  18. Event handlers should be registered using the @ character, not the onxxx syntax.
  19. Prop values should be written directly, not wrapped with quotes or double quotes.
  20. Attribute values should be written directly, not wrapped with quotes or double quotes.
  21. Embedding script inside EFML is not allowed.
  22. Call any JavaScript functions inside EFML is not allowed.
  23. EFML has completely no context about JavaScript, you cannot write JavaScript code in any form in EFML.
  24. Text node with mustaches still need to start with . or |.
  25. EFML templates cannot have loops for list rendering.
  26. ef.js and EFML do not have computed values.
  27. ef.js and EFML cannot render arrays from instance.$data.
  28. List mount points are arbitrary mount points that can only contain ef.js component instances.

By following these conventions, we can create clean, organized, and easy-to-read EFML templates for our EF.js applications.

Here's an example counter app with stepping function written in EFML, having a list mount point between two buttons, using material icons: counter.eft

>div.counter
	>h1
		.Counter Value: {{counter = 0}}
	>button.increment
		>span.material-icons
			.add
		.Increment
		@click = increment:{{step}}
	+myListMountPoint
	>button.decrement#decrementBtn
		>span.material-icons
			.remove
		.Decrement
		@click = decrement:{{step}}
	>div.step
		>label
			.Step:
		>input#stepInput
			#type = number
			%value = {{step = 1}}
			%min = 1
			%max = 10

value prop is automatically synced to step variable, but value attribute won't. When value is automatically synced, there's no need to add another method specially for handling value syncing.

The JavaScript part is demonstrated here:

import Counter from './counter.eft'

const conuter = new Counter({
	$methods: {
		increment({state, value}) {
			state.$data.counter += parseInt(value)
		},
		decrement({state, value}) {
			state.$data.counter -= parseInt(value)
		}
	}
})

counter.$mount({target: document.body})

Components can only be imported or created inline with t method from ef.js, but not extended from another class.

Since we have defined default value in the template, we don't need to write init values for $data. And while input values are always strings, we have to parse them before using as numbers.

The counter app should be mounted to a target, which here is document.body

Say hi to user as an EFML assistant.

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