Compass / compass

Compass is no longer actively maintained. Compass is a Stylesheet Authoring Environment that makes your website design simpler to implement and easier to maintain.
http://compass-style.org
Other
6.73k stars 1.18k forks source link

add_configuration_property won't allow directory options #802

Open heygrady opened 12 years ago

heygrady commented 12 years ago

http://compass-style.org/help/tutorials/extending/#adding-configuration-properties

The documentation clearly advises the use of add_configuration_property for creating new configuration properties but it is broken when trying to add a property that is a directory or path.

This code appears to work just fine:

# Require any additional compass plugins here.
Compass::Configuration.add_configuration_property(:foobar, "this is a foobar") do
  if environment == :production
    "foo"
  else
    "bar"
  end
end

This code results in an error:

# Require any additional compass plugins here.
Compass::Configuration.add_configuration_property(:foobar_dir, "this is a foobar") do
  if environment == :production
    "foo"
  else
    "bar"
  end
end

The reason is that any config variable with "dir" or "path" in the name will trigger a call to strip_trailing_seperator but that method appears undefined in that context.

C:\test>compass watch --trace
NoMethodError on line ["77"] of C: undefined method `strip_trailing_separator' for Compass::Configuration:Module
  E:/Projects/Sprockets/test/config.rb:2:in `get_binding'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/serialization.rb:24:in `eval'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/serialization.rb:24:in `parse_string'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/serialization.rb:15:in `block in _parse'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/serialization.rb:14:in `open'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/serialization.rb:14:in `_parse'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/file_data.rb:7:in `block in new_from_file'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/inheritance.rb:204:in `with_defaults'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/file_data.rb:6:in `new_from_file'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/helpers.rb:42:in `configuration_for'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/configuration/helpers.rb:97:in 'add_project_configuration'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/project_base.rb:31:in `add_project_configuration'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/project_base.rb:25:in `configure!'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/project_base.rb:15:in `initialize'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/commands/update_project.rb:37:in `initialize'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:42:in `new'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:42:in `perform!'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/lib/compass/exec/sub_command_ui.rb:15:in `run!'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/bin/compass:29:in `block in <top (required)>'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/bin/compass:43:in `call'
  C:/Ruby193/lib/ruby/gems/1.9.1/gems/compass-0.12.1/bin/compass:43:in `<top (required)>'
  C:/Ruby193/bin/compass:19:in `load'
  C:/Ruby193/bin/compass:19:in `<main>'

The problem can be traced to the Compass Configuration module, on line 77. The function strip_trailing_separator doesn't appear to be able to be called from a class method.

I tested this using a config file identical to this:

# Require any additional compass plugins here.
Compass::Configuration.add_configuration_property(:foobar_dir, "this is a foobar directory") do
  if environment == :production
    "foo"
  else
    "bar"
  end
end

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
foobar_dir = "foobar"
heygrady commented 12 years ago

https://github.com/chriseppstein/compass/blob/stable/lib/compass/configuration.rb#L77

Changing line 77 to Data.strip_trailing_separator(name) seems to work.

#...
      if name.to_s =~ /dir|path/
        Data.strip_trailing_separator(name)
      end
#...
coderanger commented 12 years ago

+1, adding the following to your extension library file will act as a workaround:

module Compass
  module Configuration
    def self.strip_trailing_separator(*args)
      Data.strip_trailing_separator(*args)
    end
  end
end
DylanArnold commented 11 years ago

+1. Just encountered this same problem. The workaround posted by coderanger worked for me.