[英]How to use 'SASS' from html template on a rails app?
我正在尝试在Rails应用程序中安装html模板,因此我将所有资产移到了公共文件夹中,并重命名了erb中的所有html文件。
一切正常,除了'sass'不起作用,html模板的SASS文件夹中的任何文件都不起作用。
那么,如何在Rails应用程序中使用html模板的SASS文件?
那么,如何在Rails应用程序中使用html模板的SASS文件?
1)如果使用bundle install
或通过命令行,请在Gemfile中安装SASS Gem gem'sass 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.