Scss / Sass没有使用sinatra-assetpack

时间:2012-05-02 16:01:50

标签: sinatra sass sinatra-assetpack

我正在编写classic style sinatra app,并尝试使用sinatra-assetpack打包我的scss文件,但它无效。

这是我的主要网络文件:

require 'rubygems'
require 'sinatra'
require 'haml'
require 'sass'
require 'compass'
require 'sinatra/assetpack'

set :root, File.dirname(__FILE__)
set :environment, ENV["RACK_ENV"] || "development"

configure do
  Compass.configuration do |config|
    config.project_path = File.dirname(__FILE__)
    config.sass_dir = 'views/stylesheets'
  end

  set :haml, { :format => :html5 }
  set :scss, Compass.sass_engine_options

  assets {
    serve '/javascripts', from: 'public/javascripts'
    serve '/stylesheets', from: '/stylesheets'

    # The second parameter defines where the compressed version will be served.
    # (Note: that parameter is optional, AssetPack will figure it out.)
    js :lib, '/javascripts/script.js', [
      '/javascripts/lib/modernizr-2.5.3.js',
      '/javascripts/lib/underscore-min.js',
      '/javascripts/lib/slides.min.jquery.js',
      '/javascripts/lib/jquery.scrollTo-1.4.2-min.js'
    ]

    css :app, '/stylesheets/screen.css', [
      '/stylesheets/screen.css',
      '/fonts/meta.css'
    ]

    js_compression  :jsmin
    css_compression :sass
  }
end

我在我的布局文件中使用它:

= css :app, :media => 'screen'

screen.scss文件存储在/views/stylesheets/screen.scss中,meta.css存储在/public/fonts/meta.css中。 screen.css的引用是否不正确?它们应该从不同的目录提供吗?

我也在主网页

中有这个
get '/stylesheets/screen.css' do
  content_type 'text/css', :charset => 'utf-8'
  scss :'stylesheets/screen'
end

将它放入或移除它并没有解决任何问题 - 这条路线是否必要?

1 个答案:

答案 0 :(得分:0)

您不应再保留get '/stylesheets/screen.css'路线了。

我还注意到你的Gemfile / app文件中有罗盘。 Sinatra AssetPack指出它与指南针不兼容。您可以包含sinatra/support来使用它,例如他们的示例应用程序here

将您的serve '/stylesheets', from: '/stylesheets'语句更改为serve '/stylesheets', from: '/views/stylesheets',以反映您希望从中提供sass文件的位置。

毕竟,你应该能够像下面那样提供你的javascript和scss:

= css :app, :media => 'screen'
= js :lib
相关问题