gpt4 book ai didi

css - 在 Rails 3.1 Assets 管道中使用来自 ExtJS4 的 sass

转载 作者:太空宇宙 更新时间:2023-11-04 16:21:27 25 4
gpt4 key购买 nike

我最近开始在 Rails 3.1 中使用 ExtJS 4。我一直在使用 ExtJS 4 捆绑的预构建主题 (ext-all.css),但我一直在争论是否要引入 sass Angular 。总的来说,我对 sass 很陌生,但我真的很喜欢它背后的想法,如果能够只编辑几个变量来重新设置整个网站的主题,那就太好了。

我想知道是否有人做过,将它合并到样式表 Assets 管道中有多难?特别是因为它似乎需要一些返工,因为使用指南针作为基础。

最佳答案

我有一个运行 Ext JS 4 前端的 Rails 3(不是 3.1)应用程序,它直接从默认主题 SASS 生成样式表。我正在使用 Jammit对于 Assets 管道,但与 Sprockets 几乎没有区别, 因为这两种情况下的工作都是由 Compass 完成的.

首先将 Compass 放入您的 Gemfile 中,确保您安装了 Compass :

gem 'compass'

Compass 已宣布 sass gem 作为依赖,所以不需要声明它。现在您需要捆绑 Gem 并初始化 Compass:

$ bundle
$ compass init rails

然后我创建了一个文件夹public/resources/scss ,我把所有 SCSS 文件放在那里。在这个文件夹中,我有我的主要应用程序 SCSS 文件 application.scss ,包括所有必要的 Compass 模块和更多部分:

$theme-name: 'default';
@import 'compass/css3';
@import 'partials/ext4';
@import 'partials/sprites';
@import 'partials/fonts';

接下来我将所有 Ext 4 SASS 主题文件复制到 public/resources/scss/ext4/default并创建了另一个文件夹 public/resources/scss/partials我将所有自定义 SCSS 部分和 Ext 4 初始化文件放在哪里 _ext4.scss :

$include-default: true;   
@import 'ext4/default/all';

这是设置 Ext 4 使用的一些 Compass 变量的正确位置。这里是一些主题样式的示例,直接从 Ext 4 SASS 文件复制:

/**
* @var {string} $font-family
* The default font-family to be used throughout the theme.
*
* @var {string} $base-gradient
* The base gradient to be used throughout the theme.
*
* @var {color} $base-color
* The base color to be used throughout the theme.
*
* @var {color} $css-shadow-background-color
* The base color for CSS shadows
*/

现在你基本上已经准备好了一切:

  • 全局应用SASS文件
  • Ext JS 4 主题
  • 自定义部分

但是还缺少最后一点:Ext 4 有一些需要到位的自定义 Compass 函数。此文件放在 Ext JS 4 框架中 resources/themes/lib/utils.rb 下.因为原始文件不能按照我组织文件的方式开箱即用,所以我根据需要简单地修改了它并将其直接放在 Compass 初始化文件中 config/compass.rb :

project_type = :rails
project_path = Compass::AppIntegration::Rails.root
environment = Compass::AppIntegration::Rails.env
http_path = "/"
http_images_path = "/resources/images"
sass_dir = "public/resources/scss"
css_dir = "public/resources/css"
images_dir = "public/resources/images"

# File copied from ext-4.0.2a/resources/themes/lib/utils.rb
#
module ExtJS4
module SassExtensions
module Functions
module Utils
def parsebox(list, n)
assert_type n, :Number
if !n.int?
raise ArgumentError.new("List index #{n} must be an integer")
elsif n.to_i < 1
raise ArgumentError.new("List index #{n} must be greater than or equal to 1")
elsif n.to_i > 4
raise ArgumentError.new("A box string can't contain more then 4")
end

new_list = list.clone.to_a
size = new_list.size

if n.to_i >= size
if size == 1
new_list[1] = new_list[0]
new_list[2] = new_list[0]
new_list[3] = new_list[0]
elsif size == 2
new_list[2] = new_list[0]
new_list[3] = new_list[1]
elsif size == 3
new_list[3] = new_list[1]
end
end

new_list.to_a[n.to_i - 1]
end

def parseint(value)
Sass::Script::Number.new(value.to_i)
end

# Returns a background-image property for a specified images for the theme
def theme_image(theme, path, without_url = false, relative = false)
without_url = (without_url.class == FalseClass) ? without_url : without_url.value

if !without_url
url = "url('/resources/images/ext4/#{ theme.value }/#{ path.value }')"
else
url = "/resources/images/ext4/#{ theme.value }/#{ path.value }"
end

Sass::Script::String.new(url)
end

def theme_image_exists(path)
result = false

where_to_look = File.join(Rails.root, 'public') + path.value.gsub('../../resources', 'resources')

if where_to_look && FileTest.exists?("#{where_to_look}")
result = true
end

Sass::Script::Bool.new(result)
end
end
end
end
end

module Sass::Script::Functions
include ExtJS4::SassExtensions::Functions::Utils
end

现在您可以在您的部分中设置 Ext 4 变量,您的自定义设置的所有 CSS 都是动态生成的,而且只有所有不错的 Compass 功能,如 Sprites .

关于css - 在 Rails 3.1 Assets 管道中使用来自 ExtJS4 的 sass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6495216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com