2013-09-26 2 views
2

로컬 파일을 검사하고 포함하여 compass config.rb 변수/상수를 재정의 할 방법을 찾고 있습니다. compass를 호출 할 때 사용할 config 파일을 정의하는 현재 옵션이 아니라이 방법을 사용하면 모든 개발자와 시스템을위한 기본값 집합을 가질 수 있고 devs가 자신의 로컬 설정에 필요한 경우이를 무시할 수 있습니다. 불행히도 루비에 대해 전혀 알지 못하고 파일에 대한 간단한 점검과 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 
+0

당신은 이것을위한 해결책을 찾았습니까? – ojrask

+0

@ojrask 지연에 대해 죄송합니다. 나는 직장에서 개발자와 함께 해결책을 찾아 냈다. 그러나이 코드는 프로젝트와 밀접하게 묶여 있기 때문에 골라 낼 수 있습니다. 그러나 저는 여러분에게 우리가 한 방향을 보여주기 위해 간단한 예를 모으려고 노력할 것입니다. – jwestbrook

답변

0

그래서 나는 더 루비 개발자를 해요하지만 다음과 같은 작업을해야합니다 표준 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, 
}