2

ローカルファイルをチェックしてそれを含めることにより、コンパスのconfig.rb変数/定数をオーバーライドする方法を探しています。(コンパスを呼び出すときに使用する構成ファイルを定義する現在のオプションではなく) この方法を使用すると、すべての開発者とビルド システムに対して一連の既定値を設定し、必要に応じて開発者が独自のローカル セットアップでこれらをオーバーライドできるようになります。残念ながら、私は 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 
4

1 に答える 1

0

だから私はRuby開発者ではありませんが、以下はうまくいくはずです...

アイデアは、標準の config.rb ファイルと config.production.rb ファイルがあり、すべての標準のプロダクション設定がハッシュ/連想配列としてあるということです。次に、これらのハッシュ キーを config.rb のコンパス定数として参照します。

開発者が任意の設定をオーバーライドしたい場合は、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,
}
于 2014-11-09T14:20:43.240 に答える