Class: Capucine::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/settings.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSettings

Returns a new instance of Settings.



16
17
18
19
20
21
22
23
24
25
# File 'lib/settings.rb', line 16

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

Instance Attribute Details

#confObject

Returns the value of attribute conf.



14
15
16
# File 'lib/settings.rb', line 14

def conf
  @conf
end

#content_dirObject

Returns the value of attribute content_dir.



12
13
14
# File 'lib/settings.rb', line 12

def content_dir
  @content_dir
end

#external_configObject

Returns the value of attribute external_config.



9
10
11
# File 'lib/settings.rb', line 9

def external_config
  @external_config
end

#project_nameObject

Returns the value of attribute project_name.



10
11
12
# File 'lib/settings.rb', line 10

def project_name
  @project_name
end

#root_dirObject

Returns the value of attribute root_dir.



11
12
13
# File 'lib/settings.rb', line 11

def root_dir
  @root_dir
end

#user_config_fileObject

Returns the value of attribute user_config_file.



13
14
15
# File 'lib/settings.rb', line 13

def user_config_file
  @user_config_file
end

#working_dirObject

Returns the value of attribute working_dir.



8
9
10
# File 'lib/settings.rb', line 8

def working_dir
  @working_dir
end

Instance Method Details

#check_validObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/settings.rb', line 69

def check_valid
  # puts self.conf['use_compass']

  # 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['compass']
  # expand_sass_in = File.join self.working_dir, self.conf['compass']

  # 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

#get_confObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/settings.rb', line 41

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
    blocs = %w{compass}

    additional.each do |k, v|

      if blocs.include?(k)
        for k2, v2 in v
          self.conf[k][k2] = v2
        end
      else
        self.conf[k] = v
      end
    end
  end

  check_valid
  return self
end

#set_user_config_file(file = nil, silent = false) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/settings.rb', line 27

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