Sha256: 950c04b0d4d37dec0d461f325a4f1f601029779c93ae8c24c0ec675a162a235b

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

module Capucine

  class Settings
  require 'rubygems'
  require 'yaml'

    attr_accessor :working_dir
    attr_accessor :external_config
    attr_accessor :project_name
    attr_accessor :root_dir
    attr_accessor :content_dir
    attr_accessor :user_config_file
    attr_accessor :conf

    def initialize

      self.working_dir = File.expand_path(Dir.getwd)
      self.project_name = 'capucine'
      self.root_dir = File.expand_path('../..', __FILE__)
      self.content_dir = File.expand_path('../../content', __FILE__)

      self.set_user_config_file
      return self
    end

    def set_user_config_file(file = nil, silent = false)
      if not file
        file = File.join self.working_dir, 'capucine.yaml'
      end

      if File.exist?(file)
        self.user_config_file = File.expand_path(file)
      end

      self.get_conf

      return self
    end

    def get_conf

      default = File.join self.content_dir, "default.yaml"
      self.conf = YAML::load_file(default)

      if self.user_config_file
        additional = YAML::load_file(self.user_config_file)
      end


      if additional
        additional.each do |k, v|
          self.conf[k] = v
        end
      end

      check_valid
      return self
    end

    def check_valid

      expand_coffee_out = File.join self.working_dir, self.conf['coffeescript_output_dir']
      expand_coffee_in = File.join self.working_dir, self.conf['coffeescript_files_dir']

      expand_sass_out = File.join self.working_dir, self.conf['sass_output_dir']
      expand_sass_in = File.join self.working_dir, self.conf['sass_files_dir']

      if expand_coffee_out == self.working_dir or expand_coffee_in == self.working_dir or expand_coffee_in == expand_coffee_out
        puts 'Illegal path for CoffeeScript'
        Process.exit
      end


      if expand_sass_out == self.working_dir or expand_sass_in == self.working_dir or expand_sass_in == expand_sass_out
        puts 'Illegal path for Sass'
        Process.exit
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capucine-0.2.5 lib/settings.rb