gpt4 book ai didi

Ruby compass 配置文件覆盖

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

我正在寻找一种通过检查本地文件并包含它来覆盖 compass config.rb 变量/常量的方法。使用这种方法(而不是定义调用 compass 时使用的配置文件的当前选项)意味着我们可以为所有开发人员和构建系统设置一组默认值,并允许开发人员在必要时覆盖这些默认值以进行他们自己的本地设置。不幸的是,我根本不了解 Ruby,对文件进行简单检查并在 config.rb 中要求它似乎不会覆盖原始设置。我当前的编码尝试如下。有人可以向我解释我在这里做错了什么吗?

配置.rb

# Compass configuration file.

# Require any additional compass plugins here.

# Sass / Compass paths
http_path = "/"
css_dir = "../../web/stylesheets"
sass_dir = "sass"
images_dir = "../../web/images"
javascripts_dir = "javascript"
fonts_dir = "fonts"

# Output style environment can be forced on build using -e
output_style = (environment == :production) ? :compressed : :expanded

# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

# Disable the compass cache method - we use our own methods.
asset_cache_buster = :none
line_comments = false
color_output = false

preferred_syntax = :scss

# Define the location of a the compass / sass cache directory.
cache_path = "/tmp/compass-cache"

# Add shared sass path to make it easier to include assets.
add_import_path = "../shared/sass"

# TODO: Check for a local config file - use this to extend/override this config file.
$localConfig = File.join(File.dirname(__FILE__), "config.local.rb")
require $localConfig if File.exist?($localConfig) and File.file?($localConfig)

配置.local.rb

# Additional custom Compass Configuration file.

# Require any additional compass plugins here.

line_comments = true

cache_path = "/Users/jwestbrook/Sites/compass-cache"

sass_options = {
:debug_info => true,
:sourcemap => true
}
enable_sourcemaps = true

最佳答案

所以我不是 Ruby 开发人员,但以下内容应该可行...

我们的想法是我们拥有标准的 config.rb 文件和一个 config.production.rb 文件,其中包含我们所有的标准生产设置作为散列/关联数组。然后我们将这些散列键作为 config.rb 中的 compass 常量。

如果开发人员想要覆盖任何设置,那么他们只需在与 config.rb 和 config.production.rb 相同的位置添加一个 config.development.rb 文件并定义它们的覆盖。

例子

config.rb

require 'compass/import-once/activate'
# Require any additional compass plugins here.

# Define the paths for config files.
productionSettings = File.join(File.dirname(__FILE__), "config.production.rb")
developmentSettings = File.join(File.dirname(__FILE__), "config.development.rb")

# Include the production config
require productionSettings if File.exist?(productionSettings) and File.file?(productionSettings)

# Set the compass settings to productionSettings $configSettings
compassSettings = $configSettings

# If a development config file exists include it and merge it's $configSettings
# with the current compassSettings
if File.exist?(developmentSettings) and File.file?(developmentSettings)
require developmentSettings
compassSettings = compassSettings.merge($configSettings)
end

# Compass settings. If statements to prevent errors if a key doesn't exist.
# Note that any additional settings you add to production or development
# will need to be referenced here else compass won't pick them up.

http_path = compassSettings['http_path'] if compassSettings.key?('http_path')
css_dir = compassSettings['css_dir'] if compassSettings.key?('css_dir')
sass_dir = compassSettings['sass_dir'] if compassSettings.key?('sass_dir')
images_dir = compassSettings['images_dir'] if compassSettings.key?('images_dir')
javascripts_dir = compassSettings['javascripts_dir'] if compassSettings.key?('javascripts_dir')
fonts_dir = compassSettings['fonts_dir'] if compassSettings.key?('fonts_dir')

output_style = compassSettings['output_style'] if compassSettings.key?('output_style')

relative_assets = compassSettings['relative_assets'] if compassSettings.key?('relative_assets')

line_comments = compassSettings['line_comments'] if compassSettings.key?('line_comments')
color_output = compassSettings['color_output'] if compassSettings.key?('color_output')

preferred_syntax = compassSettings['preferred_syntax'] if compassSettings.key?('preferred_syntax')
sourcemap = compassSettings['sourcemap'] if compassSettings.key?('sourcemap')

cache_path = compassSettings['cache_path'] if compassSettings.key?('cache_path')

config.production.rb

$configSettings = {
'http_path' => "/",
'css_dir' => "css",
'sass_dir' => "sass",
'images_dir' => "images",
'javascripts_dir' => "scripts",
'fonts_dir' => "fonts",
'preferred_syntax' => :scss,
'color_output' => false,
'output_style' => :compressed,
'sourcemap' => false,
}

config.development.rb

$configSettings = {
'cache_path' => '/tmp/sass-cache',
'output_style' => :expanded,
'sourcemap' => true,
}

关于Ruby compass 配置文件覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034434/

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