Module: Compass::Configuration::Serialization

Included in:
Data
Defined in:
lib/compass/configuration/serialization.rb

Overview

The serialization module manages reading and writing the configuration file(s).

Instance Method Summary (collapse)

Instance Method Details

- (Object) _parse(config_file)

parses a configuration file which is a ruby script



10
11
12
13
14
15
16
17
# File 'lib/compass/configuration/serialization.rb', line 10

def _parse(config_file)
  unless File.readable?(config_file)
    raise Compass::Error, "Configuration file, #{config_file}, not found or not readable."
  end
  open(config_file) do |f|
    parse_string(f.read, config_file)
  end
end

- (Object) get_binding



19
20
21
# File 'lib/compass/configuration/serialization.rb', line 19

def get_binding
  binding
end

- (Object) issue_deprecation_warnings



80
81
82
83
84
# File 'lib/compass/configuration/serialization.rb', line 80

def issue_deprecation_warnings
  if http_images_path == :relative
    $stderr.puts "DEPRECATION WARNING: Please set relative_assets = true to enable relative paths."
  end
end

- (Object) parse(config_file)

Raises:



5
6
7
# File 'lib/compass/configuration/serialization.rb', line 5

def parse(config_file)
  raise Compass::Error, "Compass.configuration.parse(filename) has been removed. Please call Compass.add_project_configuration(filename) instead."
end

- (Object) parse_string(contents, filename)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/compass/configuration/serialization.rb', line 22

def parse_string(contents, filename)
  bind = get_binding
  eval(contents, bind, filename)
  local_vars_set = eval("local_variables", bind)
  local_vars_set.each do |local_var|
    if (ATTRIBUTES+ARRAY_ATTRIBUTES).include?(local_var.to_sym)
      value = eval(local_var.to_s, bind)
      value = value.to_s if value.is_a?(Pathname)
      self.send("#{local_var}=", value)
    end
  end
  if @added_import_paths
    self.additional_import_paths ||= []
    self.additional_import_paths += @added_import_paths
    self.additional_import_paths.uniq!
  end
  issue_deprecation_warnings
end

- (Object) serialize



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
68
69
70
# File 'lib/compass/configuration/serialization.rb', line 41

def serialize
  contents = ""
  (required_libraries || []).each do |lib|
    contents << %Q{require '#{lib}'\n}
  end
  (loaded_frameworks || []).each do |lib|
    contents << %Q{load '#{lib}'\n}
  end
  (framework_path || []).each do |lib|
    contents << %Q{discover '#{lib}'\n}
  end
  contents << "# Require any additional compass plugins here.\n"
  contents << "\n" if (required_libraries || []).any?
  (ATTRIBUTES + ARRAY_ATTRIBUTES).each do |prop|
    value = send("#{prop}_without_default")
    if value.is_a?(Proc)
      $stderr.puts "WARNING: #{prop} is code and cannot be written to a file. You'll need to copy it yourself."
    end
    if respond_to?("comment_for_#{prop}")
      contents << "\n"
      contents << send("comment_for_#{prop}")
    end
    if block_given? && (to_emit = yield(prop, value))
      contents << to_emit
    else
      contents << serialize_property(prop, value) unless value.nil?
    end
  end
  contents
end

- (Object) serialize_property(prop, value)



72
73
74
75
76
77
78
# File 'lib/compass/configuration/serialization.rb', line 72

def serialize_property(prop, value)
  if value.respond_to?(:serialize_to_config)
    value.serialize_to_config(prop) + "\n"
  else
    %Q(#{prop} = #{value.inspect}\n)
  end
end