Class: Middleman::CompassExtension

Inherits:
Extension
  • Object
show all
Defined in:
lib/middleman-compass/extension.rb

Defined Under Namespace

Classes: CompassSassTemplate, CompassScssTemplate

Instance Method Summary collapse

Constructor Details

#initialize(app, options_hash = {}, &block) ⇒ CompassExtension

Returns a new instance of CompassExtension.



38
39
40
41
42
43
# File 'lib/middleman-compass/extension.rb', line 38

def initialize(app, options_hash={}, &block)
  require 'compass'
  @compass_config_callbacks = []

  super
end

Instance Method Details

#after_configurationObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/middleman-compass/extension.rb', line 55

def after_configuration
  ::Compass.configuration do |compass|
    compass.project_path    = app.config[:source]
    compass.environment     = :development
    compass.cache           = false
    compass.sass_dir        = app.config[:css_dir]
    compass.css_dir         = app.config[:css_dir]
    compass.javascripts_dir = app.config[:js_dir]
    compass.fonts_dir       = app.config[:fonts_dir]
    compass.images_dir      = app.config[:images_dir]
    compass.http_path       = app.config[:http_prefix]

    # Disable this initially, the cache_buster extension will
    # re-enable it if requested.
    compass.asset_cache_buster { |_| nil }

    # Disable this initially, the relative_assets extension will

    compass.relative_assets = false

    # Default output style
    compass.output_style = :nested
  end

  # Call hook
  execute_compass_config_callbacks(::Compass.configuration)

  # Tell Tilt to use it as well (for inline sass blocks)
  ::Tilt.register 'sass', CompassSassTemplate
  ::Tilt.prefer(CompassSassTemplate)

  # Tell Tilt to use it as well (for inline scss blocks)
  ::Tilt.register 'scss', CompassScssTemplate
  ::Tilt.prefer(CompassScssTemplate)

  ::Compass::ImportOnce.activate!
end

#compass_config(&block) ⇒ Object



45
46
47
# File 'lib/middleman-compass/extension.rb', line 45

def compass_config(&block)
  @compass_config_callbacks << block
end

#execute_compass_config_callbacks(config) ⇒ Object



49
50
51
52
53
# File 'lib/middleman-compass/extension.rb', line 49

def execute_compass_config_callbacks(config)
  @compass_config_callbacks.each do |b|
    instance_exec(config, &b)
  end
end