Method: Montage::Project#initialize

Defined in:
lib/montage/project.rb

#initialize(config_path) ⇒ Project

Creates a new Project instance.

Note that new does no validation of the given paths: it expects them to be correct. If you’re not sure of the exact paths, use Project.find instead.

Parameters:

  • config_path (String, Pathname)

    Path to the config file.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/montage/project.rb', line 45

def initialize(config_path)
  config_path = Pathname.new(config_path)
  config      = YAML.load_file(config_path)
  root_path   = determine_project_root(config_path, config)

  # Sass path may be a string representing a path, or `false`.
  sass_path = config.delete("config.sass") { DEFAULTS[:sass] }
  sass_path = sass_path.is_a?(String) ? root_path + sass_path : sass_path

  @paths = Paths.new(
    root_path, config_path, sass_path,
    config.delete('config.url') { DEFAULTS[:url] }
  )

  @padding = (config.delete('config.padding') || 20).to_i

  # All remaining config keys are sprite defintions.
  @sprites = config.map do |path, opts|
    Montage::SpriteDefinition.new(self, path, opts).to_sprites
  end.flatten
end