2

宝石文件:

# Component requirements
gem 'bcrypt-ruby', :require => "bcrypt"
gem 'sass'
gem 'haml'
gem 'coffee-script'
gem 'activerecord', :require => "active_record"
gem 'sqlite3'
# Test requirements
# Padrino Stable Gem
gem 'padrino', '0.10.7'

应用程序.haml:

= stylesheet_link_tag 'reset'
= stylesheet_link_tag 'application'

样式表位于 public/stylesheets/application.scss

帕德里诺开始...

当我刷新页面终端时写:

DEBUG -      GET (0.0009ms) /stylesheets/application.css?1340975740 - 404 Not Found
[2012-06-29 17:15:40] WARN  Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

请帮帮我。

4

2 回答 2

4

我的帕德里诺版本是 0.11.2

我使用“-c scss”选项创建一个项目,如

padrino-gen project mainsystem -a mysql -d datamapper -t rspec -s jquery -e haml -c scss -m mocha

我的 Gemfile 中有一行“gem 'sass'”,还有一个文件lib/scss_init.rb这样

module ScssInitializer
  def self.registered(app)
    # Enables support for SCSS template reloading in rack applications.
    # See http://nex-3.com/posts/88-sass-supports-rack for more details.
    # Store SCSS files (by default) within 'app/stylesheets'
    require 'sass/plugin/rack'
    Sass::Plugin.options[:syntax] = :scss
    Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
    Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
    app.use Sass::Plugin::Rack
  end
end

我把app/stylesheets/foo.scss和访问到 localhost:3000/stylesheets/foo.css,生成了public/stylesheets/default.css

于 2013-06-27T23:18:05.183 回答
1

对于 Padrino v. 0.13.1 有点不同

我创建了文件config/initializers/sass.rb就像在 smokycat 的回答中一样。

module ScssInitializer
  def self.registered(app)
    require 'sass/plugin/rack'
    Sass::Plugin.options[:syntax] = :scss
    Sass::Plugin.options[:template_location] = Padrino.root("app/stylesheets")
    Sass::Plugin.options[:css_location] = Padrino.root("public/stylesheets")
    app.use Sass::Plugin::Rack
  end
end

但我仍然遇到了一些问题,例如:

ERROR -  NameError - uninitialized constant YourAppName::App::SassInitializer:
  /Users/user/your_app/join/app/app.rb:3:in `<class:App>'
ERROR -  NameError - uninitialized constant YourAppName::App::SassInitializer:
  /Users/user/your_app/join/app/app.rb:3:in `<class:App>'

我发现您必须添加到 config/boot.rb

Padrino.dependency_paths.unshift Padrino.root('config/initializers/*.rb')

之后 sass 与 padrino 合作

于 2016-07-21T14:46:23.077 回答