如何在sass中忽略多行注释? [英] How to ignore multiline comments in sass?

查看:104
本文介绍了如何在sass中忽略多行注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让sass在生成css文件时忽略多行注释:

Is there a way to make sass ignore multiline comments when generating the css file:

// these comments are ignored

这些不是(仅在压缩模式下被忽略):

These are not (only ignored in compressed mode):

/*
 * multiline comments
 *
 */

我在Github上找到此机票作者说:

I found this ticket on Github where the author says:


如果你真的想要,你可以使用sass来批评/ * * /评论。

If you really want, you can monkeypatch Sass to silence /* */ comments as well.

但是我不知道monkeypatch sass是什么意思,那我该怎么办呢?

But I don't know what he means by monkeypatch sass, so how can I do this ?

推荐答案

Yay!我在学习猴子修补SASS时回答了这个问题:

Yay! I've learned monkey patching SASS while answering this question:

Sass mixin递归; @include loop

现在我也可以帮助你了!

And now i can help you too!

要使此解决方案正常运行,您需要指南针。安装:

For this solution to work, you'll need Compass. Install it with:

gem install compass



2)配置指南针



创建 compass.rb 文件,并且定义保存SASS和CSS代码的目录,e。 g。:

2) Configure Compass

Create a compass.rb file in your project's root and define directories where you keep your SASS and CSS code, e. g.:

css_dir = "stylesheets"
sass_dir = "sass"



3)创建 monkey patch



创建一个名为 remove-all-comments-monkey-patch.rb 在项目的根目录中:

3) Create a monkey patch

Create a file called remove-all-comments-monkey-patch.rb in your project's root:

class Sass::Tree::Visitors::Perform < Sass::Tree::Visitors::Base

  # Removes all comments completely
  def visit_comment(node)
    return []
  end

end



4)需要从 config.rb



config.rb 中,添加:

# Removing all comments by applying a monkey patch to SASS compiler
require "./remove-all-comments-monkey-patch"



5)使用Compass编译您的项目



使用 compass compile 将SASS编译为CSS。您还可以使用指南针观察使Compass命令行工具不断监视您的代码以更改和重新编译您修改的部件。

5) Compile your project with Compass

Use compass compile to compile SASS into CSS. You can also use compass watch to make the Compass command line tool constantly monitor your code for changes and recompile parts that you modify.

这不会删除SASS生成的带有行号的注释。要禁用它们注释掉 config.rb 中的 line_comments = true 行或将其设置为false。

This will not remove comments with line numbers generated by SASS. To disable them comment out the line_comments = true line in config.rb or set it to false.

要重新启用多行注释,只需注释需要猴子补丁的行,并执行 compass clean

To re-enable multiline comments, just comment out the line that requires the monkey patch and do compass clean.

虽然这个解决方案是可移植的,并且适用于所有人,不需要手动修改SASS代码,但是你应该考虑使用允许注释的IDE使用单个键击使用单行注释输出整个段落。对我来说, Ctrl + /

Though this solution is portable and will work for everybody without hacking SASS code manually, you should really consider using an IDE that allows commenting out whole paragraphs with single-line comments using a single keystroke. For me it's Ctrl+/.

我拍摄了一段简短视频,表明使用行评论实际上比使用多行评论更快,更有效: http://www.youtube.com/watch?feature=player_detailpage&v=DTyMAPZrwyc

Here, i've filmed a short video for you to show that using line comments is actually quicker and more effective than using multiline comments: http://www.youtube.com/watch?feature=player_detailpage&v=DTyMAPZrwyc

线条评论也可以让您在不中断的情况下注释评论

Line comments also let you comment out comments without breaking the code.

考虑你有以下代码:

Consider you have the following code:

foo

/* Bla bla */
bar

baz

您需要对其进行评论。如果你用 / * * / ...

And you need to comment it all out. If you wrap it all with /* */...

/*foo

/* Bla bla */
bar

baz*/

...那么你打破了代码!现在你有一个以 / * foo 开头并以 bla * / 结尾的注释,还有一个语法错误 baz * /

...then you broke the code! Now you have a comment that starts with /*foo and ends with bla */, and also a syntax error at baz*/.

只需选择整个代码,然后按 Ctrl + / (如果使用某些IDE或程序员的记事本),它将立即注释掉:

Instead, just select the whole code and hit Ctrl+/ (provided that use some IDE or programmer's notepad), it will all be commented out immediately:

//foo
//
///* Bla bla */
//bar
//
//baz

请使用相同的热键取消注释。

And of course it can later be uncommented with the same hotkey.

这篇关于如何在sass中忽略多行注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆