=begin
本文档是HTML代码块的编辑文件。注意不要把其他语言的设置放到html里来。
HBuilder可使用ruby脚本来编辑代码块和增强操作命令。
1、编辑代码块
如果要新增一个代码块,复制如下一段代码到空白行,然后设定参数。
'Style'是代码块的显示名字;
s.trigger = 'style' 是设定激活字符,比如输入style均会在代码提示时显示该代码块;
s.expansion = '' 是设定该代码块的输出字符,其中$0、$1是光标的停留和切换位置。
snippet 'Style' do |s|
s.trigger = 'style'
s.expansion = '<style type="text/css" media="screen">
$0
</style>'
end
以上以HTML代码块做示例,js和css代码块类似,使用时注意避免混淆
2、编辑按键命令
如果要新增一个按键操作命令,复制如下一段代码到空白行,然后设定参数。
'Br'是命令名字;
s.key_binding = 'CONTROL+ENTER' 是设定按什么快捷键可以触发这个命令;
s.expansion = '<br/>' 是设定输出字符。
snippet 'Br' do |s|
s.key_binding = 'CONTROL+ENTER'
s.expansion = '<br/>'
end
操作时注意冲突,注意备份,有问题就还原。
多看看已经写的ruby命令,会发现更多强大技巧。
修改完毕,需要重启才能生效。
玩的愉快,别玩坏!
脚本开源地址 https://github.com/dcloudio/HBuilderRubyBundle ,可以把你的配置共享到这里,也可以在这里获取其他网友的版本
=end require 'ruble' with_defaults :scope => 'text.html entity.other.attribute-name.html' do |bundle| snippet 'data-' do |s|
s.trigger = 'data-'
s.expansion='data-${1:type/role/transition/icon/iconpos/*} = "$2"'
s.locationType='HTML_ATTRIBUTE'
end end with_defaults :scope => 'text.html text' do |bundle| snippet t(:html_4_strict) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
'
end snippet t(:xhtml_1_frameset) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
'
end snippet t(:xhtml_1_strict) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
'
end snippet t(:xhtml_1_transitional) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
'
end snippet t(:xhtml_11) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
'
end snippet t(:movie) do |s|
s.trigger = 'movie'
s.expansion = '<object width="${2:320}" height="${3:240}" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="${1:movie.mov}"/>
<param name="controller" value="${4:true}"/>
<param name="autoplay" value="${5:true}"/>
<embed src="${1:movie.mov}"
width="${2:320}" height="${3:240}"
controller="${4:true}" autoplay="${5:true}"
scale="tofit" cache="true"
pluginspage="http://www.apple.com/quicktime/download/"
></embed>
</object>'
end snippet t(:html_4_transitional) do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
'
end snippet 'input with label' do |s|
s.trigger = 'input'
s.expansion = '<label for="$2">$1</label><input type="${3:text/submit/hidden/button}" name="$2" value="$5" id="$2"/>'
end snippet t(:option) do |s|
s.trigger = 'opt'
s.expansion = '<option value="${1:option}">${1:option}</option>'
end snippet 'input' do |s|
s.trigger = 'input'
s.expansion = '<input type="$1" name="$2" id="$2" value="$3" />'
s.needApplyReContentAssist = true
end snippet 'textarea' do |s|
s.trigger = 'textarea'
s.expansion = '<textarea name="$1" rows="$2" cols="$3">$0</textarea>'
end snippet 'canvas' do |s|
s.trigger = 'canvas'
s.expansion = '<canvas id="$1" width="$2" height="$3"></canvas>'
end snippet 'iframe' do |s|
s.trigger = 'iframe'
s.expansion = '<iframe src="$1" width="$2" height="$3"></canvas>'
s.needApplyReContentAssist = true
end snippet t(:nbsp) do |s|
s.key_binding = 'OPTION+Space'
s.expansion = '&nbsp;'
end snippet 'Br' do |s|
s.key_binding = 'CONTROL+ENTER'
s.expansion = '<br/>'
end snippet 'link' do |s|
s.trigger = 'link'
s.expansion = '<link rel="stylesheet" type="text/css" href="$1"/>'
s.needApplyReContentAssist = true
end snippet 'meta' do |s|
s.trigger = 'meta'
s.needApplyReContentAssist = true
s.expansion = '<meta name="$1" content="$2"/>'
end snippet 'meta_UTF8' do |s|
s.trigger = 'metautf'
s.expansion = '<meta charset="UTF-8"/>'
end snippet 'meta_GB2312' do |s|
s.trigger = 'metagb'
s.expansion = '<meta charset="GB2312"/>'
end snippet 'meta_nocache' do |s|
s.trigger = 'metanocache'
s.expansion = '<meta http-equiv="Pragma" content="no-cache" />'
end snippet 'meta_keywords' do |s|
s.trigger = 'metakeywords'
s.expansion = '<meta name="Keywords" content="$1"/>'
end snippet 'meta_description' do |s|
s.trigger = 'metadescription'
s.expansion = '<meta name="Description" content="$1"/>'
end snippet 'meta_viewport' do |s|
s.trigger = 'metaviewport'
s.expansion = '<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />'
end snippet 'script_google_jquery' do |s|
s.trigger = 'scriptjqg'
s.expansion = '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>'
end snippet 'script_baidu_jquery' do |s|
s.trigger = 'scriptjqb'
s.expansion = '<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>'
end snippet '<!--[if IE]>' do |s|
s.trigger = 'ifie'
s.expansion = '<!--[if IE]>
$1
<![endif]-->'
end snippet '<!--[if lte IE 6]>' do |s|
s.trigger = 'ifie6'
s.expansion = '<!--[if lte IE 6]>
$1
<![endif]-->'
end snippet '<select>...</select>' do |s|
s.trigger = 'select'
s.expansion = '<select name="$1">
<option value="$2">$3</option>
</select>'
end snippet 'dl' do |s|
s.trigger = 'dl'
s.expansion = '<dl>
<dt>$1</dt>
<dd>$2</dd>
</dl>'
end snippet 'ul' do |s|
s.trigger = 'ul'
s.expansion = '<ul>
<li>$1</li>
</ul>'
end snippet 'form' do |s|
s.trigger = 'form'
s.expansion = "<form action=\"$1\" method=\"${2:get}\">
$0
<input type=\"submit\" value=\"$3\"/>
</form>"
s.needApplyReContentAssist = true
end snippet 'input_text' do |s|
s.trigger = 'intext'
s.expansion = '<input type="text" id="$1" value="$2" />'
s.needApplyReContentAssist = true
end snippet 'input_button' do |s|
s.trigger = 'inbutton'
s.expansion = '<input type="button" id="$1" value="$2" />'
s.needApplyReContentAssist = true
end snippet 'input_image' do |s|
s.trigger = 'inimage'
s.expansion = '<input type="image" src="$1" />'
s.needApplyReContentAssist = true
end snippet 'input_password' do |s|
s.trigger = 'inpassword'
s.expansion = '<input type="password" name="$1" />'
end snippet 'input_search' do |s|
s.trigger = 'insearch'
s.expansion = '<input type="search" name="$1" required="$2" placeholder="Search" x-webkit-speech="$3" x-webkit-grammar="builtin:search" lang="zh-CN">'
end snippet 'input_submit' do |s|
s.trigger = 'insubmit'
s.expansion = '<input type="submit" id="$1" name="$2" />'
end snippet 'input_reset' do |s|
s.trigger = 'inreset'
s.expansion = '<input type="reset"/>'
end snippet 'img' do |s|
s.trigger = 'img'
s.expansion = '<img src="$1"/>'
s.needApplyReContentAssist = true
end snippet 'a_link' do |s|
s.trigger = 'al'
s.expansion = '<a href="$1"></a>'
s.needApplyReContentAssist = true
end snippet 'a_mailto' do |s|
s.trigger = 'am'
s.expansion = '<a href="mailto:$1"></a>'
end snippet 'video' do |s|
s.trigger = 'video'
s.expansion = '<video width="${1:800}" height="$2">
<source src="${3:myvideo.mp4}" type="video/mp4"></source>
<source src="${4:myvideo.ogv}" type="video/ogg"></source>
<source src="${5:myvideo.webm}" type="video/webm"></source>
<object width="$6" height="$7" type="application/x-shockwave-flash" data="${8:myvideo.swf}">
<param name="movie" value="$8" />
<param name="flashvars" value="autostart=true&amp;file=$8" />
</object>
当前浏览器不支持 video直接播放,点击这里下载视频: <a href="${9:myvideo.webm}">下载视频</a>
</video>'
end snippet t(:script_w_external_source) do |s|
s.trigger = 'scsrc'
s.expansion = '<script src="$1" type="text/javascript" charset="${3:utf-8}"></script>'
s.needApplyReContentAssist = true
end snippet 'Script' do |s|
s.trigger = 'script'
s.expansion = '<script type="text/javascript" charset="utf-8">
$0
</script>'
end snippet 'style' do |s|
s.trigger = 'style'
s.expansion = '<style type="text/css">
$0
</style>'
end snippet '<!DOCTYPE html>' do |s|
s.trigger = 'doctype'
s.expansion = '<!DOCTYPE HTML>'
end snippet 'html' do |s|
s.trigger = 'html'
s.expansion = '<html>
<head>
<title>$0</title>
</head>
<body> </body>
</html>'
end snippet 'h1' do |s|
s.trigger = 'h1'
s.expansion = '<h1>$0</h1>'
end snippet 'h2' do |s|
s.trigger = 'h2'
s.expansion = '<h2>$0</h2>'
end snippet 'h3' do |s|
s.trigger = 'h3'
s.expansion = '<h3>$0</h3>'
end snippet 'h4' do |s|
s.trigger = 'h4'
s.expansion = '<h4>$0</h4>'
end snippet 'h5' do |s|
s.trigger = 'h5'
s.expansion = '<h5>$0</h5>'
end snippet 'h6' do |s|
s.trigger = 'h6'
s.expansion = '<h6>$0</h6>'
end snippet 'table' do |s|
s.trigger = 'table'
s.expansion = '<table border="$1" cellspacing="$2" cellpadding="$3">
<tr><th>${4:Header}</th></tr>
<tr><td>${5:Data}</td></tr>
</table>'
end snippet 'head' do |cmd|
cmd.trigger = 'head'
cmd.expansion = "<head>
<meta charset=\"utf-8\"/>
<title>$1</title> </head>"
end snippet 'body' do |cmd|
cmd.trigger = 'body'
cmd.expansion = "<body>
$0
</body>"
end snippet 'div' do |cmd|
cmd.trigger = 'div'
cmd.needApplyReContentAssist = true
cmd.expansion = "<div class=\"$1\">
$0
</div>"
end snippet 'span' do |cmd|
cmd.trigger = 'span'
cmd.needApplyReContentAssist = true
cmd.expansion = "<span id=\"$1\">
$0
</span>"
end snippet 'fieldset' do |cmd|
cmd.trigger = 'fieldset'
cmd.expansion = "<fieldset id=\"$2\">
<legend>$1</legend> $0
</fieldset>"
end end # End Snippets with scope 'text.html text' # -----------------------------------------------------------------------------------
# Snippets that used env vars and needed to be converted to commands
with_defaults :scope => 'text.html - source', :input => :none, :output => :insert_as_snippet do |bundle| command t(:quick_br) do |cmd|
cmd.key_binding = 'M2+ENTER'
cmd.output = :insert_as_snippet
cmd.input = :none
cmd.invoke { "<br />" }
end command t(:quick_html_space) do |cmd|
cmd.key_binding = 'M2+SPACE'
cmd.output = :insert_as_snippet
cmd.input = :none
cmd.invoke { "&nbsp;" }
end command t(:emphasize) do |cmd|
cmd.key_binding = 'M1+M2+I'
cmd.input = :selection
cmd.invoke do |context|
selection = ENV['TM_SELECTED_TEXT'] || ''
if selection.length > 0
"<em>${1:#{selection}}</em>"
else
"<em>$0</em>"
end
end
end command t(:strong) do |cmd|
cmd.key_binding = 'M1+M2+B'
cmd.input = :selection
cmd.invoke do |context|
selection = ENV['TM_SELECTED_TEXT'] || ''
if selection.length > 0
"<strong>${1:#{selection}}</strong>"
else
"<strong>$0</strong>"
end
end
end command t(:wrap_selection_in_tag_pair) do |cmd|
cmd.key_binding = "CONTROL+9"
cmd.input = :selection
cmd.invoke do |context|
selection = ENV['TM_SELECTED_TEXT'] || ''
if selection.length > 0
"<${1:p}>#{selection.gsub('/', '\/')}</${1:p}>"
else
"<${1:p}>$0</${1:p}>"
end
end
end
end #end of 'text.html - source' with_defaults :scope => 'text.html text', :input => :none, :output => :insert_as_snippet do |bundle|
command t(:ie_6_and_below) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer 6 and below '
"<!--[if lte IE 6]>${1:#{value}}<![endif]-->$0"
end
end command t(:ie_6) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer 6 only '
"<!--[if IE 6]>${1:#{value}}<![endif]-->$0"
end
end command t(:ie_7_and_above) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer 7 and above '
"<!--[if gte IE 7]>${1:#{value}}<![endif]-->$0"
end
end command t(:ie_8_and_above) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer 8 and above '
"<!--[if gte IE 8]>${1:#{value}}<![endif]-->$0"
end
end command t(:ie_9_and_above) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer 9 and above '
"<!--[if gte IE 9]>${1:#{value}}<![endif]-->$0"
end
end command t(:ie) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: Internet Explorer '
"<!--[if IE]>${1:#{value}}<![endif]-->$0"
end
end command t(:not_ie) do |cmd|
cmd.trigger = '!'
cmd.invoke do |context|
value = (ENV['TM_SELECTED_TEXT'] || '').length > 0 ? ENV['TM_SELECTED_TEXT'] : ' IE Conditional Comment: NOT Internet Explorer '
"<!--[if !IE]><!-->${1:#{value}}<!-- <![endif]-->$0"
end
end command t(:wrap_in_jsp_tag) do |cmd|
cmd.scope = 'text.html string'
cmd.invoke {|context| "<?= #{ENV['TM_SELECTED_TEXT']} ?>" }
end
end

HBuilder HTML 自定义代码块的更多相关文章

  1. Hbuilder jQuery 自定义代码块

    =begin 本文档是jquery代码块的编辑文件.修改其他的代码块,请在对应的激活代码助手点右下角的修改图标. HBuilder可使用ruby脚本来编辑代码块和增强操作命令. 1.编辑代码块 如果要 ...

  2. HBuilder js 自定义代码块

    =begin 本文档是HBuilder预置的js代码块的文件.注意不要把其他语言的设置放到js里来. 如果用户修改此文档,HBuilder升级后会覆盖用户的修改,建议进入菜单 工具→扩展代码块 扩展相 ...

  3. HBuilder CSS 自定义代码块

    =begin 本文档是CSS代码块的编辑文件.注意不要把其他语言的设置放到css里来. HBuilder可使用ruby脚本来编辑代码块和增强操作命令. 1.编辑代码块 如果要新增一个代码块,复制如下一 ...

  4. Xcode自定义代码块

    到现在才发现原来Xcode有自定义代码块这么神奇的功能,能简化很多无聊的敲重复代码的工作,真是感叹我怎么才知道!!! 具体的设置流程见:http://nshipster.cn/xcode-snippe ...

  5. webstrom自定义代码块的设置方法

    webstrom里面的自定义代码块叫做活动模版 在文件 -> 设置 -> 编辑器 -> 活动模版可以打开 里面的$var$ 代表一个变量  两个相同的$var$在不全后可以同时修改, ...

  6. IDE MAC下的快捷键,自定义代码块。

    快捷键 参考博客:http://blog.csdn.net/iguiyi/article/details/51853728 alt+f7查找在哪里使用 相当于eclipse的ctrl+shift+G ...

  7. vscode自定义代码块

    vscode中设置自定义代码块打开首选项,选择用户代码片段,打开后选择编程语言选中后打开文件,按照格式编辑内容 "Print to console log": { "pr ...

  8. vs2015常用代码块与自定义代码块

    常用代码块 代码段名 描    述 #if 该代码段用#if和#endif命令围绕代码 #region 该代码段用#region和#endregion命令围绕代码 ~ 该代码段插入一个析构函数 att ...

  9. IDEA 自定义代码块

    使用快捷键(ctrl+alt+s)找到:从idea的菜单File->Settings->Editor->Live Templates 先添加Template Group,然后添加Li ...

随机推荐

  1. 小丁带你走进git的世界三-撤销修改(转)

    一.撤销指令 git checkout还原工作区的功能 git reset  还原暂存区的功能 git clean  还没有被添加进暂存区的文件也就是git还没有跟踪的文件可以使用这个命令清除他们 g ...

  2. MKMapView移动事件地图

    MKMapView移动事件地图 by 吴雪莹 -(void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { ...

  3. vs2010中文简体版下载链接(含中文msdn)

    昨天朋友说vs2010中文版能够下载了,自己開始还不相信,正好周末,于是就下载了试一下 安装了果然是中文版,本来是msdn订阅用户才干够下载的,感谢上传的网友. 文件名称 cn_visual_stud ...

  4. Cordic 算法之 反正切

    在通信的算法中,常采用Cordic算法之一,知道角度产生正交的的正弦余弦, 或者知道正弦和余弦求角度,求反正切. 1. 求正弦和余弦值. 方法:旋转角度,得到正弦余弦值: 再旋转角度,到达下一个正弦余 ...

  5. ubuntu下安装myeclipse

    一.下载myeclipse 官网下载:http://www.myeclipseide.com/ 我使用的是myeclipse pro 2014.run,重命名为myeclipse.run 示例路径:/ ...

  6. JavaScript中五种常见运算符

    一. in运算符 in运算符希望它的左操作数是一个字符串或可以转换为字符串,希望它的右操作数是一个对象.如果右侧的对象拥有一个名为左操作数值的属性名,那么表达式返回true.例如: var point ...

  7. 【Java】【jquery】ajax垃圾问题

    1.暗示HTML.JSP文件本身使用UTF-8格公式 2.HTML的head加: <META http-equiv="Content-Type" content=" ...

  8. Git常用命令(转)

    目前开发的新项目使用的版本控制工具基本用的都是Git,老项目用的还是Svn,网上Git资源也很多,多而杂.我整理了一份关于Git的学习资料,希望能帮助到正在学习Git的同学. 一. Git 命令初识 ...

  9. Lichee (六) 优化配置的微内核

    我们的分析<Lichee(二) 在sun4i_crane平台下的编译 >的时候.竟然没有一个步骤是在配置内核 make ARCH=arm menuconfig 细致的读过的代码的会发现,在 ...

  10. C#后台利用正则表达式查找匹配字符

    /// <summary>        /// 发送短信 系统固化短信        /// </summary>        /// <param name=&qu ...