简体   繁体   English

如何在Github的Atom编辑器中包含更多JavaScript?

[英]How to include more JavaScript inside Atom editor by Github?

I've been playing with snippets for Atom editor, and see that I've learned I can include JavaScript inside of a snippet, as my example shows. 我一直在使用Atom编辑器的代码段,并且看到我已经知道可以在代码段中包含JavaScript,如我的示例所示。

(It inserts a TODO Comment with date) (它插入带有日期的待办事项注释)

TODO: (RAM) Fix this  -  2014-11-23 20:55
HELLO

How can I include MORE JavaScript.? 如何包含更多JavaScript。

For example 例如

inside the snippet to set 在代码段内进行设置

var= to something

or 要么

call a JS library

or 要么

ask for input from user i.e. confirm();

and proceed on basis of confirm() function. 并在confirm()函数的基础上进行。

Any help would be appreciated, I looked for a long time, but not much documentation on this. 任何帮助将不胜感激,我花了很长时间寻找,但是关于它的文档并不多。 Submlime Text's snippets allowed lots of code to be inserted via Python. Submlime Text的代码片段允许通过Python插入大量代码。

Thanks ~Rob 谢谢〜罗布

Inside file snippets.cson 内部文件snippets.cson

'.source.js':

'Date TODO: insert':
'prefix': 'datetd'
'body': """
TODO: (RAM) $1  -  #{datetime = new Date(); datetime.getFullYear()}-#{(datetime.getMonth()+1)}-#{datetime.getDate()} #{datetime.getHours()}:#{datetime.getMinutes()}
 #{"hello".toUpperCase(); }
 $2
"""

Update: With the merge of atom/atom#4791 , the capability of putting CoffeeScript code in CSON configuration files has been removed from Atom. 更新:通过atom / atom#4791的合并,从Atom中删除了将CoffeeScript代码放入CSON配置文件中的功能。 The rest of the answer has been left intact for historic reference. 其余答案将保留完整以供历史参考。

Actually, the syntax of the file is CoffeeScript (hence .cson as in CoffeeScript Object Notation), not JavaScript. 实际上,文件的语法是CoffeeScript(因此,如CoffeeScript对象表示法中的.cson ),而不是JavaScript。 It just so happens that you typed in JavaScript that is allowed as CoffeeScript. 碰巧您输入了允许作为CoffeeScript的JavaScript。 CoffeeScript doesn't use the var keyword, so you can assign variables like you did in your example: CoffeeScript不使用var关键字,因此您可以像在示例中那样分配变量:

datetime = new Date()

The other items, you'll probably have to get a little creative. 其他项目,您可能必须要有一点创意。 I don't believe that the snippets package was intended to be used in this manner, which is why the lack of documentation on the "feature". 我不认为摘要程序包打算以这种方式使用,这就是为什么缺少有关“功能”的文档的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM