Sinatraでsassを使う

なんかちょいうまくできなかったのだけど、ここの回答の方法で一発だった。

ruby - How to link a Sass file in a Sinatra app? - Stack Overflow

Class: Sass::Plugin::Rackを使う方法です。

さっきのページに使い方も書いてあって、概要は、

Rack middleware for compiling Sass code.

とということで、Usageは、

Put your Sass files in public/stylesheets/sass. Your CSS will be generated in public/stylesheets, and regenerated every request if necessary. The locations and frequency can be customized. That’s all there is to it!

とのことです。ということでまぁこれで終わりなのだけど、これじゃあ書くことなくなっちゃうので手順だけ書いておきます...笑

まずgemを追加します。

# Gemfile
gem 'sass'

そしたらpublic/stylesheets/sassを作ってsassファイルを作成します。

$ mkdir -p public/stylesheets/sass
$ echo '                                                                     
◀ .strong
◀   font-weight: bold
◀ ' > public/stylesheets/sass/index.sass

そしてrackでアプリを起動すると、public/stylesheets内にindex.cssが生成されています。

簡単!