开发者

Aptana Studio 3 - How can I change this command (regex replacement)

开发者 https://www.devze.com 2023-03-28 21:16 出处:网络
What i want to do: edit the CSS command tidier to include a space/tab after the selctor: #myid{...} to be #myid {...}

What i want to do:

edit the CSS command tidier to include a space/tab after the selctor: #myid{...} to be #myid {...}

the file I want to edit:

format_css_singleline.rb

command "Format CSS Single-line" do |cmd|
  cmd.key_binding = "M1+M2+F"
  cmd.output = :replace_selectio开发者_Python百科n
  cmd.input = :selection 
  cmd.scope = "source.css"
  cmd.invoke do |context|
    code = $stdin.read
    code.gsub!(/\n{3,}/im, "\n\n")
    code.gsub!(/[ \t]+/im, " ")
    code.gsub!(/(?m)([;:])\s+/im) {|match| "#{$1}" }  //i've tried adding a space after the {$1} here
    code.gsub!(/\s*}/im, "}")
    code.gsub!(/\s*{\s*/im, "{")
    code.gsub!(/[ \t]*,[ \t]*/im, ", ")
    code.gsub!(/@import(.*?);/im) {|match| "@import#{$1};\n\n" }
    code
  end
end


Commands > CSS > Edit this Bundle. It will grab down a git clone of the original CSS bundle, then generate a project inside the app for you to customize. There you can customize that command's file. Then you'll probably want to edit the following line: code.gsub!(/\s*{\s*/im, "{") to be code.gsub!(/\s*{\s*/im, " {"). That line is collapsing all space before and after { down to no space. The modification will leave a space ahead of it.

0

精彩评论

暂无评论...
验证码 换一张
取 消