【发布时间】:2016-11-04 11:55:59
【问题描述】:
我正在尝试在我的 rails 应用程序中安装一个 html 模板,因此我移动了 public 文件夹中的所有资产并重命名了 erb 中的所有 html 文件。
一切正常,除了“sass”不起作用,html 模板的 SASS 文件夹中的任何文件都不起作用。
那么如何在我的 rails 应用上使用 html 模板的 SASS 文件呢?
【问题讨论】:
标签: html ruby-on-rails ruby sass
我正在尝试在我的 rails 应用程序中安装一个 html 模板,因此我移动了 public 文件夹中的所有资产并重命名了 erb 中的所有 html 文件。
一切正常,除了“sass”不起作用,html 模板的 SASS 文件夹中的任何文件都不起作用。
那么如何在我的 rails 应用上使用 html 模板的 SASS 文件呢?
【问题讨论】:
标签: html ruby-on-rails ruby sass
那么我怎样才能使用我的 html 模板的 SASS 文件呢? 轨道应用?
1) 如果您使用的是bundle install,则在您的 Gemfile 中安装 SASS Gem gem 'sass',或者通过命令行:gem install sass
2) 在您的 SASS 文件夹中创建一个名为“manifest.txt”的文件,例如 public/src/sass/manifest.txt
3) 在manifest.txt 中,按照包含顺序列出您希望合并到单个 CSS 文件中的每个文件,例如:
framework.sass
framework_overides.sass
homepage.sass
contact.sass
global.sass
4) 打开你的Rakefile 并创建这个 rake 任务:
require 'sass'
desc "Parse SASS manifest.txt and convert to single CSS file"
task :sass do
# your template directory
src_dir = File.join Rails.root, 'public/src'
# SASS directory
sass_dir = File.join src_dir, "sass"
# name of the single output file
app_css_file = File.join src_dir, "css/application.css"
# parse SASS manifest
sass_manifest = IO.readlines File.join(sass_dir, "manifest.txt")
# clear previous app_css_file, without having to require 'fileutils'
File.open(app_css_file, 'w') {|f| f.write ""}
# write to app_css_file
File.open(app_css_file, 'a+') do |f|
sass_manifest.each do |x|
# remove code comments
next if x.strip =~ /^#/
# parse extension
case syntax = File.extname(x.strip).delete('.').downcase
# convert and append scss
when /scss/ then
f.write Sass::Engine.new(IO.read(File.join(sass_dir, x.strip)), :syntax => :scss, :cache => false).render
# convert and append sass
when /sass/ then
f.write Sass::Engine.new(IO.read(File.join(sass_dir, x.strip)), :cache => false).render
end
end
end
end
5) 使用此命令:rake sass
【讨论】:
.sass 文件中不能有; 分号。
SCSS吗?
.scss 文件
【讨论】:
byebug或pry来找出问题所在。