https://github.com/gadicc/meteor-snippets
Code snippets with highlighting and lang conversion
https://github.com/gadicc/meteor-snippets
Last synced: about 1 year ago
JSON representation
Code snippets with highlighting and lang conversion
- Host: GitHub
- URL: https://github.com/gadicc/meteor-snippets
- Owner: gadicc
- Created: 2014-10-06T10:06:32.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-12-12T10:12:16.000Z (over 11 years ago)
- Last Synced: 2025-02-17T21:19:13.496Z (over 1 year ago)
- Language: JavaScript
- Size: 320 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
Awesome Lists containing this project
README
## gadicohen:snippets
This is a work in progress for the
[famous-views website](http://famous-views.meteor.com/).
I wouldn't suggest using this yet but don't let me stop you :>
```handlebars
{{#snippet lang="spacebars"}}
<template name="famousInit">
{{dstache}}#Surface size="[undefined,undefined]"}}
I am a full size Surface
{{dstache}}/Surface}}
</template>
{{/snippet}}
```
This will wrap your code with prism highlighting, add buttons for other
languages in that code group, and automatically convert your snippet into
the target language. Current code groups are JavaScript/CoffeeScript and
Spacebars/Jade.
Sometimes code looks much better by hand, so you can also include
hand-crafted conversions in the `else` section of your snippet block.
```handlebars
{{#snippet lang="spacebars"}}
<template name="famousInit">
{{dstache}}#Surface size="[undefined,undefined]"}}
I am a full size Surface
{{dstache}}/Surface}}
</template>
{{else}}
{{!-- optional section to include by-hand conversions --}}
{{#if currentLang "jade"}}
template(name="famousInit")
+Surface size="[undefined,undefined]"
| I am a full size Surface
{{/if}}
{{/snippet}}
```
If the right language exists in the else block, it will be shown instead, otherwise
conversion happens like usual.
> Note: If you're coding in spacebars, and want to give a **spacebars example in
spacebars**, you need to escape your moustache tags (like with a 'dstache' helper
like the one used in Meteor docs).
```js
Template.registerHelper('dstache', function() { return '{{'; });
```
> Note: we automatically de-indent the "initial indent" of your code blocks,
so you can still indent them inside the `{{#snippet}}` tags.
## API
* `snippets.hasMapping(source, dest)` - boolean, can we do this conversion?
* `snippets.convert(code, source, dest, returnNull)` - if returnNull, returns null if
no mapping exists. Otherwise a message (in English).