Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby compass配置文件覆盖_Ruby_Compass Sass - Fatal编程技术网

Ruby compass配置文件覆盖

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

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

config.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)
config.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')
$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,
}
$configSettings = {
    'cache_path' => '/tmp/sass-cache',
    'output_style' => :expanded,
    'sourcemap' => true,
}
config.production.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')
$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,
}
$configSettings = {
    'cache_path' => '/tmp/sass-cache',
    'output_style' => :expanded,
    'sourcemap' => true,
}
config.development.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')
$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,
}
$configSettings = {
    'cache_path' => '/tmp/sass-cache',
    'output_style' => :expanded,
    'sourcemap' => true,
}

你找到解决办法了吗?抱歉耽搁了@ojrask。最后,我确实与一位正在工作的开发人员一起想出了一个解决方案。然而,这些代码与一个项目的联系如此紧密,以至于要将它们分开是很痛苦的。然而,我将尝试把一个简单的例子放在一起,向您展示我们所采取的方向。