Module: Compass::Magick::Configuration

Extended by:
Configuration::Inheritance::ClassMethods, Configuration
Included in:
Configuration
Defined in:
lib/magick/configuration.rb,
lib/plugins/phantom.rb

Overview

Configuration methods to allow plugins to register new configurable properties.

Instance Method Summary collapse

Instance Method Details

#add_property(name) ⇒ Object

Registers a new property in ‘config.rb`.

If you use this method, you should also define two additional methods:

  • comment_for_$name - emits a comment against the properly into the configuration file when serialized

  • default_$name - provides a default value for the property when one isn’t specified in the configuration file

Parameters:

  • name (Symbol)

    The name of the property.



20
21
22
23
# File 'lib/magick/configuration.rb', line 20

def add_property(name)
  Compass::Configuration::ATTRIBUTES.push(name)
  inherited_accessor(name)
end

#comment_for_phantom_executableString

Emits the comment for the ‘phantom_executable` property into the configuration file when serialized – makes it easier to understand for new Users.

Returns:

  • (String)

    The comment for the ‘phantom_executable` property.



23
24
25
# File 'lib/plugins/phantom.rb', line 23

def comment_for_phantom_executable
  "# Path to the PhantomJS binary\n"
end

#comment_for_phantom_scriptString

Emits the comment for the ‘phantom_script` property into the configuration file when serialized – makes it easier to understand for new Users.

Returns:

  • (String)

    The comment for the ‘phantom_script` property.



32
33
34
# File 'lib/plugins/phantom.rb', line 32

def comment_for_phantom_script
  "# Path to magick.js used to render a web page (using PhantomJS, a headless WebKit)\n"
end

#cygwin_path(path) ⇒ String

Converts a Cygwin Unix path to a Windows path, e.g.:

/cygdrive/d/path/to/file
  ==>
D:/path/to/file

Parameters:

  • path (String)

    The Unix path to convert.

Returns:

  • (String)

    The Windows path.



33
34
35
36
37
38
39
# File 'lib/magick/configuration.rb', line 33

def cygwin_path(path)
  if RUBY_PLATFORM.include?('cygwin') && path.index('/') == 0
    IO.popen("cygpath -m #{path.include?(':') ? '-p' : ''} #{path.shellescape}").readline.chomp.gsub(/;/, '\\;')
  else
    path
  end
end

#default_phantom_executableString

Provides the default value for ‘phantom_executable` when one isn’t specified in the configuration file.

Returns:

  • (String)

    The default path to the PhantomJS binary.



40
41
42
# File 'lib/plugins/phantom.rb', line 40

def default_phantom_executable
  ENV['PHANTOM_PATH'] || 'phantomjs'
end

#default_phantom_scriptString

Provides the default value for ‘phantom_script` when one isn’t specified in the configuration file.

Returns:

  • (String)

    The default path to the magick.js script used to render a web page.



49
50
51
# File 'lib/plugins/phantom.rb', line 49

def default_phantom_script
  cygwin_path(ENV['PHANTOM_SCRIPT'] || File.join(EXTRAS_PATH, 'magick.js'))
end