Sassã¨Compassã使ã£ã¦ã¿ã
å®å
¨ã«é
ãã¦ãæããããã©ãä»æ´ãªããã«Sassã¨Compassã®ç°å¢ãæ´ãã¦ã¿ãã
åç½®ãã¨ãã©ãã§ããã人ã¯ãã¤ã³ã¹ãã¼ã«ãã¨ããã®è¾ºã®è¦åºãã ãèªãã§ãã ããã
ã¶ã£ã¡ããgem installã¨compileã¨ãwatchãã¡ããã£ã¨ãã£ã¦ãã ããªã®ã§ãæ¢ã«ä½¿ãããªãã¦ã人ã¯ãã£ã¨ã¿ããéããã¨æéãç¯ç´ã§ãã¾ãã
Sass
Sass - Syntactically Awesome Stylesheets
http://sass-lang.com/
Sassã¯CSSããã£ã¨ä¾¿å©ã§å¹ççã«ã³ã¼ãã£ã³ã°ããããã®æè¡ãCSSã¡ã¿è¨èªã
競åãããã®ã¨ãã¦LESSãStylusããããã©ãæè¿ã¯Compassã¨ã®ã»ããã§Sassãæµè¡ã£ã¦ãæ§åã
Sassã使ãã¨CSSããããªé¢¨ã«æ¸ããããã«ãªãã
/* sass */ $item_color: #3bbfce #navbar width: 80% height: 23px ul list-style-type: none li float: left a color: darken($item_color, 9%)
ãããã³ã³ãã¤ã«ããã¨ä¸ã®ãããªCSSãçæãããã
/* css */ #navbar { width: 80%; height: 23px; } #navbar ul { list-style-type: none; } #navbar ul li { float: left; } #navbar ul li a { color: #2ca2af; }
Sassã¯HamlãSlimã®ãããªã¤ã³ãã³ãã§ãã¹ãã表ç¾ããã
ãã®ä»ã«ãå¤æ°ãé¢æ°ãç¶æ¿ã¨ãã£ãããã°ã©ãã³ã°çãªãã¨ãã§ããã
ããã¨Sassã«ã¯SCSS(Sassy CSS)ã¨ããæ®éã®CSSãæ¡å¼µãããããªè¨æ³ãç¨æããã¦ããã
ã¨ãããSCSSã¯CSS3ã®ã¹ã¼ãã¼ã»ããçãªææ³ã«ãªã£ã¦ãã¦ãæ®éã®CSSã¯SCSSã¨ãã¦ãæ±ãããã®ã§ãã¨ããããæ®éã«CSSã§æ¸ãã¦ãå°ããã¤æ
£ãã¦ããããå ´åã¯SCSSã§æ¸ãã¨è¯ããããããªãã
ã¡ãªã¿ã«ä¸è¨ã®ä¾ãSCSSã§æ¸ãã¨ãããªæãã«ãªãã
$item_color: #3bbfce; #navbar { width: 80%; height: 23px; ul { list-style-type: none; li { float: left; a { color: darken($item_color, 9%) } } } }
ç´°ããæ©è½ã«ã¤ãã¦ã¯å
¬å¼ããã¥ã¢ã«ãè²ã
ãªè§£èª¬ãµã¤ããè¦ã¦ãããã¨ãã¦ãæ©é使ã£ã¦ã¿ãã
ã¤ã³ã¹ãã¼ã«
Sassã¯Rubyã§ã§ãã¦ãã®ã§Rubyãå
¥ã£ã¦ãããã¨ãåæã¨ãªãã
Macãªãæ¨æºã§å
¥ã£ã¦ãããã®ãWindowsãªãå¥éRubyInstallerãªã©ã§å
¥ãããã®ã使ãããã¡ããrbenvã§å
¥ãããã®ã§ãããã
Sassã¯gemã«ãªã£ã¦ãã®ã§æ®éã«gemã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã§ããã
sudo gem install sass
ããã§sassã³ãã³ãã使ããããã«ãªãã
sass -v Sass 3.2.10 (Media Mark)
sass -h Usage: sass [options] [INPUT] [OUTPUT] Description: Converts SCSS or Sass files to CSS. Options: : :
ã³ã³ãã¤ã«
sass/scssãã¡ã¤ã«ã®ã³ã³ãã¤ã«ã¯ãããªæãã
sass example.sass example.css
åºåãã¡ã¤ã«ãçç¥ããã¨ç»é¢ã«è¡¨ç¤ºãããã
ä»ã«--style
ã§åºåãããCSSã®å½¢å¼ãå¶å¾¡ã§ããã
ããã©ã«ãã¯nestedã§ãã¤ã³ãã³ããããæãã§åºåãããcompressedã«ããã¨ä¸è¡ã§åºåãããã
ã¡ãªã¿ã«ä¸ã®ä¾ã¯expandedã§åºåããã
ãã¡ã¤ã«ãç·¨éãããèªåçã«ã³ã³ãã¤ã«ãã
--watch
ã¨ãããªãã·ã§ã³ã使ç¨ããã¨ããã¡ã¤ã«ã®å¤æ´ããã£ããèªåçã«ã³ã³ãã¤ã«ãã¦ãããã¢ã¼ãã§èµ·åãã§ããã
å
¥åã¨åºåã¯ã³ãã³ã§åºåã£ã¦æå®ããã®ã§æ³¨æã
# ãã¡ã¤ã«ãæå®ããä¾ sass --watch example.sass:example.css # ãã£ã¬ã¯ããªãæå®ããä¾ sass --watch sass:css
ãã¡ãã¯ãã¡ã¤ã«ã ãã§ãªããã£ã¬ã¯ããªãæå®ã§ããã®ã§ãsass:cssã¨ãæå®ãã¦èµ·åãã¦ããã¨ä¾¿å©ã
ãããèµ·åããç¶æ
ã§sass/example.sassãç·¨éããã¨ãèªåçã«ã³ã³ãã¤ã«ããããã®ãcss/example.cssã«çæãããã
ã¨ããããç°¡åãªä½¿ãæ¹ã¯ãããªã¨ããã
ãã¨ã¯-hãçºããã¨ãããã¥ã¢ã«ãçºããã¨ãã°ã°ãã¨ããã¦æ°ããçºè¦ããããã
Compass
Compass Home | Compass Documentation
http://compass-style.org/
Compassã¯Sassãå©ç¨ããCSSãã¬ã¼ã ã¯ã¼ã¯é(?)ã§ãè²ã ãªmixinéã¨ãã¹ãã©ã¤ãã®èªåçæã¨ã便å©ãªæ©è½ãæã£ããã®ã
ä¾ãã°ãããªæãã«æ¸ãã¨â¦
@import "compass"; .sample { @include border-radius(2px); }
ãããªæãã®CSSã«ãã¦ãããã
/* line 3, ../sass/example.scss */ .sample { -webkit-border-radius: 2px; -moz-border-radius: 2px; -ms-border-radius: 2px; -o-border-radius: 2px; border-radius: 2px; }
ä»ã«ãCSSãªã»ããã¨ãbox-shadowã¨ãè²ã
ãã£ã¦ããããããã³ãã¼ãã¬ãã£ã¯ã¹ã ãã§ãªãã¯ãã¹ãã©ã¦ã¶ãèæ
®ãã¦èªåçã«å¤æãã¦ãããã
ã¹ãã©ã¤ã
ããã«Compassã使ãã¨ã¹ãã©ã¤ãç¨ç»åã¨ããã使ãããã®CSSãèªåçã«çæãã¦ãããã
ãã¨ãã°ãããªæãã«ã¢ã¤ã³ã³ãã¡ã¤ã«ããã£ãã¨ãã¦ã
images/my-icons/new.png images/my-icons/edit.png images/my-icons/save.png images/my-icons/delete.png
ãããªscssãæ¸ãã¨â¦
@import "my-icons/*.png"; @include all-my-icons-sprites;
ãããªç»åãã¡ã¤ã«ã¨cssãçæãããã
images/my-icons-s5dcefb3c8d.png
/* line 66, my-icons/*.png */ .my-icons-sprite, .my-icons-delete, .my-icons-edit, .my-icons-new, .my-icons-save { background: url('/images/my-icons-s5dcefb3c8d.png') no-repeat; } .my-icons-delete { background-position: 0 -32px; } .my-icons-edit { background-position: 0 -64px; } .my-icons-new { background-position: 0 -96px; } .my-icons-save { background-position: 0 0; }
ããé å¼µã£ã¦åãè²¼ããããã¹ãã©ã¤ãçæãµã¤ãã使ããªãã¦ãããï¼
ã»ãã«ããã£ã±ããã£ã±ãæ©è½ããããã©ããããã«ã¤ãã¦ã¯å
¬å¼ããã¥ã¢ã«ãè²ã
ãªè§£èª¬ãµã¤ããè¦ã¦ãããã¨ãã¦ãæ©é使ã£ã¦ã¿ãã
ã¤ã³ã¹ãã¼ã«
CompassãRubyã§ã§ãã¦ãã®ã§Rubyãå
¥ã£ã¦ãããã¨ãåæã¨ãªããã¨ãããSassã使ã£ã¦ãã®ã§å¿
ç¶çã«Rubyã«ãªãã
Macãªãæ¨æºã§å
¥ã£ã¦ãããã®ãWindowsãªãå¥éRubyInstallerï¼ï½ï½
Compassãgemã«ãªã£ã¦ãã®ã§æ®éã«gemã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã§ããã
sudo gem install compass
ããã§compassã³ãã³ãã使ããããã«ãªãã
compass -v Compass 0.12.2 (Alnilam) Copyright (c) 2008-2013 Chris Eppstein Released under the MIT License. Compass is charityware. Please make a tax deductable donation for a worthy cause: http://umdf.org/compass
compass -h Usage: compass help [command] Description: The Compass Stylesheet Authoring Framework helps you build and maintain your stylesheets and makes it easy for you to use stylesheet libraries provided by others. : :
ããã¸ã§ã¯ãã®ä½æ
Compassã¯CSSãç»åãªã©ã®ä»ã«ãã¼ã¹URLãã³ã³ãã¤ã«ã®ä»æ¹ãªã©ãè¨å®ãããã¡ã¤ã«ãã»ããã«ãªã£ãããã¸ã§ã¯ããã£ã¬ã¯ããªã§ä½æ¥ãããã¨ã«ãªãã
compass create example1
ããã¨example1ãã£ã¬ã¯ããªã«åæãã¡ã¤ã«ãä½æããã¦ãç°¡åãªä½¿ãæ¹ãªã©ã表示ãããã
directory example1/ directory example1/sass/ directory example1/stylesheets/ create example1/config.rb create example1/sass/screen.scss create example1/sass/print.scss create example1/sass/ie.scss create example1/stylesheets/ie.css create example1/stylesheets/print.css create example1/stylesheets/screen.css ********************************************************************* Congratulations! Your compass project has been created. You may now add and edit sass stylesheets in the sass subdirectory of your project. Sass files beginning with an underscore are called partials and won't be compiled to CSS, but they can be imported into other sass stylesheets. You can configure your project by editing the config.rb configuration file. You must compile your sass stylesheets into CSS when they change. This can be done in one of the following ways: 1. To compile on demand: compass compile [path/to/project] 2. To monitor your project for changes and automatically recompile: compass watch [path/to/project] : :
ã¡ãªã¿ã«--css-dir
ãªã©ã®ãªãã·ã§ã³ã§åºæ¥ä¸ãããã£ã¬ã¯ããªã®ååãªã©ãæå®ããããã§ããã
compass help create
ãã¦ã¿ãã¨è²ã
ãªãªãã·ã§ã³ã®èª¬æãåºã¦ããã
ã¾ãconfig.rbã®ä¸ã«css_dir
ãªã©ã®é
ç®ãæ¸ããã¦ããã®ã§ããããå¤æ´ãã¦ãããã
ã³ã³ãã¤ã«
sassãã£ã¬ã¯ããªã®ä¸ã®ãã¡ã¤ã«ãç·¨éãã¦ãããã¸ã§ã¯ããã£ã¬ã¯ããªã§compile
ãå®è¡ããã¨å
¨ã¦ã®ãã¡ã¤ã«ãã³ã³ãã¤ã«ãã¦cssãã¡ã¤ã«ãä½æãã¦ãããã
sassã³ãã³ãã®æã¿ããã«ãã¡ã¤ã«ããã£ã¬ã¯ããªãæå®ããå¿
è¦ã¯ãªãã
compass compile
ãã¡ã¤ã«ãç·¨éãããèªåçã«ã³ã³ãã¤ã«ãã
Compassãwatch
ã¨ããã³ãã³ãã使ç¨ããã¨ããã¡ã¤ã«ã®å¤æ´ããã£ããèªåçã«ã³ã³ãã¤ã«ãã¦ãããã¢ã¼ãã§èµ·åãã§ããã
compass watch
ãã¡ãããã¡ã¤ã«ããã£ã¬ã¯ããªãæå®ããå¿ è¦ã¯ãªãã
ã¨ããããç°¡åãªä½¿ãæ¹ã¯ãããªã¨ããã
ãã¨ã¯helpãçºããã¨ãããã¥ã¢ã«ãçºããã¨ãã°ã°ãã¨ããã¦æ°ããçºè¦ããããã
ã¡ãªã¿ã«ã³ãã³ãã®ãã«ãã¯help
ã§è¡¨ç¤ºã§ããã
compass help ã³ãã³ã(watchã¨ã)
compass statsã§CSSã®é ç®ãæå¹ã«ãã(2013-09-30追è¨)
stats
ã³ãã³ãã使ãã¨ãããªæ
å ±ã確èªã§ããããcss_parserãå
¥ã£ã¦ãªãå ´åã¯CSSã®é
ç®ãDISABLEDã«ãªã£ã¦ãã¾ãã
ããããå ´åã¯ä¸çªæå¾ã«æ¸ããã¦ããããã«css_parser gemãå
¥ãã¦ãããã¨å¯¾å¿ãããã
compass stats unchanged sass/ie.scss unchanged sass/print.scss unchanged sass/screen.sass unchanged sass/screen.scss | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | Filename | Rules | Properties | Mixins Defs | Mixins Used | Filesize | CSS Selectors | CSS Properties | CSS Filesize | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | sass/ie.scss | 0 | 0 | 0 | 0 | 271 B | DISABLED | DISABLED | | sass/print.scss | 0 | 0 | 0 | 0 | 213 B | DISABLED | DISABLED | | sass/screen.sass | 4 | 4 | 0 | 0 | 121 B | DISABLED | DISABLED | | sass/screen.scss | 2 | 1 | 0 | 0 | 341 B | DISABLED | DISABLED | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | Total (4 files): | 6 | 5 | 0 | 0 | 946 B | 0 | 0 | 0 B | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | Install css_parser to enable stats on your css files: gem install css_parser
css_parserãå ¥ããã
sudo gem install css_parser
compass stats unchanged sass/ie.scss unchanged sass/print.scss unchanged sass/screen.sass unchanged sass/screen.scss | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | Filename | Rules | Properties | Mixins Defs | Mixins Used | Filesize | CSS Selectors | CSS Properties | CSS Filesize | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | sass/ie.scss | 0 | 0 | 0 | 0 | 271 B | 0 | 0 | 271 B | | sass/print.scss | 0 | 0 | 0 | 0 | 213 B | 0 | 0 | 213 B | | sass/screen.sass | 4 | 4 | 0 | 0 | 121 B | 2 | 4 | 185 B | | sass/screen.scss | 2 | 1 | 0 | 0 | 341 B | 2 | 4 | 185 B | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- | | Total (4 files): | 6 | 5 | 0 | 0 | 946 B | 4 | 8 | 854 B | | ---------------- | ----- | ---------- | -------------- | ----------- | ------------- | ------------- | -------------- | -------------- |