require 'ruble' =begin HBuilder可使用ruby脚本来扩展代码块和增强操作命令。这是极客的神奇玩具。 本文档用于用户自定义HTML扩展命令,并非HBuilder预置命令的文档,预置的代码块不可改。查阅预置代码块,请在弹出预置代码块界面时点右下角的编辑按钮,比如div代码块。 本文档修改完毕,保存即可生效。 玩的愉快,别玩坏! 脚本开源地址 https://github.com/dcloudio/HBuilderRubyBundle 可以把你的配置共享到这里,也可以在这里获取其他网友的版本 注:如果1.9版本之前的用户修改过HTML代码块,请点右键打开本文档所在目录,找之前的snippets.rb.bak文件,把修改过的内容放置进来。 =end with_defaults :scope => 'text.html text' do |bundle| #=====HTML标签代码块================================================================================ #如下是一个示例代码块,可以复制后再添加新代码块 snippet 'div_class' do |cmd| #div_class是显示名称,代码助手提示列表显示时可见 cmd.trigger = 'divc' #divc是激活字符,即按下divc后会触发该代码块 cmd.expansion = "
$0
" #expansion是代码块的输出内容,其中$0、$1是光标的停留和切换位置。$1是第一个停留光标,$0是最后回车时停留的光标。 #如果输出涉及到换行和tab,也需严格在这里使用换行和tab。 #输出双引号在前面加\来转义,输出$使用\$(单引号中)或\\$(双引号中)转义 cmd.needApplyReContentAssist = true #这句话的意思是输出后同时激活代码助手,即在$1的位置直接拉出样式列表 end #div_class代码块结束 snippet 'ng-pluralize' do |cmd| cmd.trigger = 'ngp' cmd.expansion = "$1" end end with_defaults :scope => 'text.html entity.other.attribute-name.html' do |bundle| #=====HTML属性代码块==================================================== #如下是一个示例代码块,可以复制后再添加新代码块 snippet 'ng-' do |s| #ng-是显示名称,代码助手提示列表显示时可见 s.trigger = 'ng-' #ng-是激活字符,即按下ng-后会触发该代码块 s.expansion='ng-${1:app/bind/bind-html/bind-template/blur/change/checked/class/class-even/class-odd/click/cloak/controller/copy/csp/cut/dblclick/disabled/focus/hide/href/if/include/init/keydown/keypress/keyup/list/model/mousedown/mouseenter/mouseleave/mousemove/mouseover/mouseup/ng-non-bindable/open/options/paste/readonly/repeat-start/repeat-end/selected/show/src/srcset/style/submit/swipe-left/swipe-right/switch/switch-default/switch-when/view}="$2"' #expansion是代码块的输出内容,其中$0、$1是光标的停留和切换位置。 #$1是第一个停留光标,$0是最后回车时停留的光标。 #使用{}包围的内容,是提示值域。 #如果输出涉及到换行和tab,也需严格在这里使用换行和tab。 #输出双引号在前面加\来转义,输出$使用\$(单引号中)或\\$(双引号中)转义 s.locationType='HTML_ATTRIBUTE' end #ng代码块结束 end with_defaults :scope => 'text.html - source', :input => :none, :output => :insert_as_snippet do |bundle| #=====无显示名称的快捷命令======================= =begin 如下示例均为系统已经预置的命令,无需重复制作 示例1 Ctrl+Enter输出
command t(:quick_br) do |cmd| cmd.key_binding = 'M2+ENTER' cmd.output = :insert_as_snippet cmd.input = :none cmd.invoke { "
" } end 示例2 Ctrl+9为选中文字添加包围标签 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('/', '\/')}" else "<${1:p}>$0" end end end =end #可复制一段命令,在下面开始制作新命令 snippet 'mBody(主体)' do |cmd| cmd.trigger = 'mbody' cmd.expansion = '
$0
' end snippet 'mCheckbox(复选框)' do |cmd| cmd.trigger = 'mcheckbox' cmd.expansion = "
$0" end snippet 'mCheckbox(复选框居左)' do |cmd| cmd.trigger = 'mcheckbox' cmd.expansion = "
$0" end snippet 'mCheckbox(复选框禁用选项)' do |cmd| cmd.trigger = 'mcheckbox' cmd.expansion = "
$0" end snippet 'mHeader(标题栏)' do |cmd| cmd.trigger = 'mheader' cmd.expansion = '

${1:标题}

$0' end snippet 'mHeader(带返回箭头的标题栏)' do |cmd| cmd.trigger = 'mheaderwithBack' cmd.expansion = '
<\/a>

${1:标题}

$0' end snippet 'mText(文本框)' do |cmd| cmd.trigger = 'minputtext' cmd.needApplyReContentAssist = true cmd.expansion = "
$0" end snippet 'mText_Search(搜索框)' do |cmd| cmd.trigger = 'minputsearch' cmd.expansion = "
$0" end snippet 'mText_Clear(带清除按钮的文本框)' do |cmd| cmd.trigger = 'minputclear' cmd.expansion = "
$0" end snippet 'mText_Speech(语音输入)' do |cmd| cmd.trigger = 'minputspeech' cmd.expansion = "
$0" end snippet 'mForm(表单)' do |cmd| cmd.trigger = 'mform' cmd.needApplyReContentAssist = true cmd.expansion = "
$0" end snippet 'mRadio(单选框)' do |cmd| cmd.trigger = 'mradio' cmd.expansion = "
$0" end snippet 'mPopover(弹出菜单)' do |cmd| cmd.trigger = 'mpopover' cmd.expansion = '
$0' end snippet 'mPopover(H5模式弹出菜单)' do |cmd| cmd.trigger = 'mactionsheet' cmd.expansion = '
$0' end snippet 'mRange(label+输入框+滑块)' do |cmd| cmd.trigger = 'mrangeinput' cmd.expansion = "
label+输入框+滑块:
$0" end snippet 'mRange(Label+滑块)' do |cmd| cmd.trigger = 'mrangelabel' cmd.expansion = "
label+滑块:${1:20}
$0" end snippet 'mRange(整行滑块)' do |cmd| cmd.trigger = 'mrangeline' cmd.expansion = "
${4:整行滑块:}${1:50}
$0" end snippet 'mSwitch(开关)' do |cmd| cmd.trigger = 'mswitch' cmd.expansion = "
$0" end snippet 'mSwitch(开关Mini)' do |cmd| cmd.trigger = 'mswitchmini' cmd.expansion = "
" end snippet 'mbadge(数字角标)' do |cmd| cmd.trigger = 'mbadge' cmd.expansion = "${2:1}$0" end snippet 'mbadge(数字角标无底色)' do |cmd| cmd.trigger = 'mbadge_inverted' cmd.expansion = "${2:1}$0" end snippet 'mTab(底部选项卡)' do |cmd| cmd.trigger = 'mtab' cmd.expansion = "$0" end snippet 'mTabSegmented(div选项卡)' do |cmd| cmd.trigger = 'mtabsegmented' cmd.expansion = "
${1:选项卡1} ${1:选项卡2}
$0" end snippet 'mTabSegmented(可左右拖动的选项卡)' do |cmd| cmd.trigger = 'mtabviewpage' cmd.expansion = '
${1:选项卡1} ${2:选项卡2}
  • ${3:第1个选项卡子项}
  • ${4:第1个选项卡子项}
  • ${5:第2个选项卡子项}
  • ${6:第2个选项卡子项}
$0' end snippet 'mPagination(分页)' do |cmd| cmd.trigger = 'mpagination' cmd.expansion = "$0" end snippet 'mList(列表)' do |cmd| cmd.trigger = 'mlist' cmd.expansion = "
$0" end snippet 'mListMedia(图文列表图片居左)' do |cmd| cmd.trigger = 'mlist_Media_left' cmd.needApplyReContentAssist = true cmd.expansion = "$0" end snippet 'mListMedia(图文列表图片居右)' do |cmd| cmd.trigger = 'mlist_Media_right' cmd.needApplyReContentAssist = true cmd.expansion = "$0" end snippet 'mGrid(九宫格)' do |cmd| cmd.trigger = 'mgrid' cmd.expansion = "
$0" end snippet 'mGallery-Table(图文表格)' do |cmd| cmd.needApplyReContentAssist = true cmd.trigger = 'mgallerytable' cmd.expansion = "$0" end snippet 'mGallery图片轮播' do |cmd| cmd.needApplyReContentAssist = true cmd.trigger = 'mgallery' cmd.expansion = "
$0" end snippet 'mactionsheet(操作表)' do |cmd| cmd.trigger = 'actionsheet' cmd.expansion = "
$0" end snippet 'maccordion(折叠面板)' do |cmd| cmd.trigger = 'maccordion' cmd.expansion = '$0' end snippet 'mnumbox(数字输入框)' do |cmd| cmd.trigger = 'mnumbox' cmd.expansion = "
$0" end snippet 'mrefreshContainer(刷新容器)' do |cmd| cmd.trigger = 'mrefresh' cmd.expansion = "
" end snippet 'mButton(按钮)' do |cmd| cmd.trigger = 'mbutton' cmd.expansion = "$0" end snippet 'mButton(按钮无底色,有边框)' do |cmd| cmd.trigger = 'mbutton_outline' cmd.expansion = "$0" end end