{"id":16482467,"url":"https://github.com/f/macaron","last_synced_at":"2025-03-21T07:30:42.778Z","repository":{"id":19019254,"uuid":"22242416","full_name":"f/macaron","owner":"f","description":"Macros for CoffeeScript","archived":false,"fork":false,"pushed_at":"2020-07-09T23:11:50.000Z","size":723,"stargazers_count":24,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T22:27:03.157Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://f.github.io/macaron","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-25T02:40:09.000Z","updated_at":"2022-11-11T10:08:07.000Z","dependencies_parsed_at":"2022-08-28T14:40:42.238Z","dependency_job_id":null,"html_url":"https://github.com/f/macaron","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fmacaron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fmacaron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fmacaron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fmacaron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f","download_url":"https://codeload.github.com/f/macaron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244757237,"owners_count":20505357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T13:10:53.006Z","updated_at":"2025-03-21T07:30:42.482Z","avatar_url":"https://github.com/f.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Macaron\n\nMacros for CoffeeScript. Try online: [http://f.github.io/macaron/](http://f.github.io/macaron/)\n\n## Installation\n\n```bash\nnpm install macaron\n```\n\n### Using Macaron Grunt Task\n\nMacaron has a [Grunt plugin](http://github.com/ahmet/grunt-macaron) written by [Ahmet Aygün](http://github.com/ahmet).\n\n```bash\nnpm install grunt-macaron --save-dev\n```\n\nPlease read the [README file of grunt-macaron](https://github.com/ahmet/grunt-macaron/blob/master/README.md) for installation instructions.\n\n## Overview\n\nCreate a Macro library:\n```coffeescript\n# macros.coffee\nmacro.swap = (x, y)-\u003e\n  $tmp = y\n  y = x\n  x = $tmp\n```\n\nWrite your Coffee using macros like functions:\n```coffeescript\n# main.coffee\nx = 1\ny = 2\nconsole.log \"before: x is #{x}, y is #{y}\"\nswap x, y\nconsole.log \"after: x is #{x}, y is #{y}\"\n```\n\nCompile them on Terminal ..:\n```bash\n$ macaron macros.coffee main.coffee\nbefore: x is 1, y is 2\nafter: x is 2, y is 1\n```\n\n.. Or in your CoffeeScript Code:\n```coffeescript\n# mycoffee.coffee\nMacaron = require 'macaron'\nmacros = new Macaron\ncompiledJS = macros.compileFile 'macros.coffee', 'main.coffee', bare: no\n\nconsole.log compiledJS\n```\n\n```bash\ncoffee mycoffee.coffee\n```\n\n## Usage\n\n```bash\nmacaron [MACROS FILE] [SOURCE FILES...] [COFFEE OPTIONS]\n```\n\n### Basic Compilation\n\nIt basically replaces the code with the macro code.\n\n```javascript\n// $ macaron examples/macros.coffee examples/source.coffee\nvar x, y, _tmp$1;\nx = 1;\ny = 2;\nconsole.log(\"before swap, x is \" + x + \", y is \" + y);\n\n// swap x, y macro starts here\n_tmp$1 = y;\ny = x;\nx = _tmp$1;\n// ends here\n\nconsole.log(\"after swap, x is \" + x + \", y is \" + y);\n```\n\n### Using Code Blocks\n\nYou can also use code blocks to use efficiently. To do this, just use splats\nof CoffeeScript (`...`)\n\n```coffeescript\n# Create a macro named do_something which accepts a code block\nmacro.do_something = (block...)-\u003e\n  hello = \"world\"\n  do -\u003e\n    block\n```\n\nThen you can simply call like a callback\n\n```coffeescript\n# Call the macro with a code block\ndo_something -\u003e\n  console.log hello\n```\n\nIt will generate that code:\n\n```javascript\nvar hello;\n\nhello = \"world\";\n(function() {\n  return console.log(hello);\n})();\n```\n\n### Composing\n\nYou can compose macros.\n\n```coffeescript\nmacro.sayHello = (world)-\u003e\n  hello = \"world\"\n  world = \"hello\"\n  swap hello, world # Calling Scope Macro\n  console.log hello, world\n```\n\n### Replace Macros\n\nReplace macros are so stupid ones, you can just pass the code to *replace*.\nThe code won't be parsed by Macaron. To define replace macros, use `do` keyword.\nThis macro type doesn't take any parameters since there are no parse process.\n\n```coffeescript\nmacro.strict = do -\u003e\n  \"use strict\"\n```\n\nYou can use `do` keyword to call these macros:\n\n```coffeescript\ndo strict\n```\n\nIt will generate the output:\n\n```coffeescript\n\"use strict\";\n```\n\n### Hygiene\n\nYou can keep your variables safe using `$` prefix on your variables.\n\n```coffeescript\n# macros.coffee\nmacro.swap = (x, y)-\u003e\n  $tmp = y\n  y = x\n  x = $tmp\n```\n\n```coffeescript\n# main.coffee\nx = 2\ny = 3\nswap x, y\nconsole.log $tmp\n```\n\nWhen you run it, it will generate an error:\n```\nReferenceError: $tmp is not defined\n```\n\n#### Escape Hygiene\n\nYou can always disable hygiene using **fat-arrow** (`=\u003e`) or just don't use `$` prefix.\n\n```coffeescript\nmacro.swap = (x, y)=\u003e # disabling hygienic variables\n  $tmp = y\n  y = x\n  x = $tmp\n```\n\n### Literal Macros\n\nYou can use Literal macros using `literal` definition keyword. It takes two arguments,\none is a **regular expression**, another is the function.\n\n```coffeescript\nliteral /(\\w+) is (\\w+) plus (\\w+)/, (variable, first, second)-\u003e\n  variable = first + second\n    \nliteral /tell (.*) the (\\w+)/, (channel, parameter)-\u003e\n  channel parameters\n```\n\nWith these **literal macros** you can now write some talkative declarations:\n\n```coffeescript\n\"a is 3 plus 4\"\n\"tell console.log the a\"\n```\n\nIt will generate the output:\n\n```javascript\nvar a;\na = 3 + 4;\nconsole.log(a);\n```\n\nYou can wrap matches into quotes using `@` (`this`) prefix on parameters.\n\n```coffeescript\nliteral /tell my (\\w+) is (.*)/, (@key, @value)-\u003e\n  user[key] = value\n```\n\nYou can now use the macros easily:\n\n```coffeescript\n\"tell my name is fka\" #=\u003e It will be compiled to `user[\"name\"] = \"fka\"`\n```\n\n\n## Examples\n\n```coffeescript\n# macros.coffee\nmacro.each = (variable, name, eachBlock...)-\u003e\n  value = variable\n  value.forEach -\u003e\n    $item = arguments[0]\n    name = $item\n    eachBlock\n```\n\nUsing this macro:\n\n```coffeescript\neach [1, 2, 3], item, -\u003e\n  console.log item\n```\n\nAnd it'll generate that code:\n\n```javascript\nvalue = [1, 2];\nvalue.forEach(function() {\n  var item, _item$2;\n  _item$2 = arguments[0];\n  item = _item$2;\n  return console.log(item);\n});\n```\n\n### Reading from STDIN\n\nYou can simply use standard input to run macaron:\n\n```bash\necho \"x = 1; y = 2; swap x, y; console.log x, y\" | macaron -scb examples/macros.coffee | node\n```\n\n## Command Line Usage\n\n```\nUsage: coffee ./bin/macaron [MACRO FILE] [SOURCE FILES...] [OPTIONS]\n\nOptions:\n  -b, --bare     [default: true]\n  -c, --compile  [default: false]\n  --concat       [string]  [default: true]\n```\n\n## TODO\n\n  - Browserify Transform\n\n## License\n\nMIT: [f.mit-license.org][3]\n\n### The Idea\n\n\u003e A fork of [davidpadbury/stirred-coffee][1], based on the [blog post][2] about it.\n\n[1]: http://github.com/davidpadbury/stirred-coffee\n[2]: http://blog.davidpadbury.com/2010/12/09/making-macros-in-coffeescript/\n[3]: http://f.mit-license.org\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fmacaron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff%2Fmacaron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fmacaron/lists"}