Class: Compass::Installers::Base

Inherits:
Object
  • Object
show all
Includes:
Actions
Defined in:
lib/compass/installers/base.rb

Direct Known Subclasses

RailsInstaller, StandAloneInstaller

Instance Attribute Summary collapse

Attributes included from Actions

#logger

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Actions

#basename, #compile, #copy, #directory, #relativize, #remove, #separate, #strip_trailing_separator, #write_file

Constructor Details

#initialize(template_path, target_path, options = {}) ⇒ Base

Returns a new instance of Base.



12
13
14
15
16
17
18
19
# File 'lib/compass/installers/base.rb', line 12

def initialize(template_path, target_path, options = {})
  @template_path = template_path
  @target_path = target_path
  @working_path = Dir.getwd
  @options = options
  @manifest = Manifest.new(manifest_file) if template_path
  self.logger = options[:logger]
end

Instance Attribute Details

#manifestObject

Returns the value of attribute manifest.



10
11
12
# File 'lib/compass/installers/base.rb', line 10

def manifest
  @manifest
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/compass/installers/base.rb', line 9

def options
  @options
end

#target_pathObject

Returns the value of attribute target_path.



8
9
10
# File 'lib/compass/installers/base.rb', line 8

def target_path
  @target_path
end

#template_pathObject

Returns the value of attribute template_path.



8
9
10
# File 'lib/compass/installers/base.rb', line 8

def template_path
  @template_path
end

#working_pathObject

Returns the value of attribute working_path.



8
9
10
# File 'lib/compass/installers/base.rb', line 8

def working_path
  @working_path
end

Class Method Details

.installer(type, installer_opts = {}, &locator) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/compass/installers/base.rb', line 90

def self.installer(type, installer_opts = {}, &locator)
  locator ||= lambda{|to| to}
  loc_method = "install_location_for_#{type}".to_sym
  define_method("simple_#{loc_method}", locator)
  define_method(loc_method) do |to, options|
    if options[:like] && options[:like] != type
      send("install_location_for_#{options[:like]}", to, options)
    else
      send("simple_#{loc_method}", to)
    end
  end
  define_method "install_#{type}" do |from, to, options|
    from = templatize(from)
    to = targetize(send(loc_method, to, options))
    copy from, to, nil, (installer_opts[:binary] || options[:binary])
  end
end

Instance Method Details

#compilation_required?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/compass/installers/base.rb', line 82

def compilation_required?
  false
end

#configure_option_with_default(opt) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/compass/installers/base.rb', line 61

def configure_option_with_default(opt)
  value = options[opt]
  value ||= begin
    default_method = "default_#{opt}".to_sym
    send(default_method) if respond_to?(default_method)
  end
  send("#{opt}=", value)
end

#finalizeObject

The default finalize method – it is a no-op. This could print out a message or something.



79
80
# File 'lib/compass/installers/base.rb', line 79

def finalize
end

#initObject

Initializes the project to work with compass



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/compass/installers/base.rb', line 32

def init
  dirs = manifest.map do |entry|
    File.dirname(send("install_location_for_#{entry.type}", entry.to, entry.options))
  end

  if manifest.has_stylesheet?
    dirs << sass_dir
    dirs << css_dir
  end

  dirs.uniq.sort.each do |dir|
    directory targetize(dir)
  end
end

#installObject

The default install method. Calls install_<type> methods in the order specified by the manifest.



71
72
73
74
75
# File 'lib/compass/installers/base.rb', line 71

def install
  manifest.each do |entry|
    send("install_#{entry.type}", entry.from, entry.to, entry.options)
  end
end

#manifest_fileObject



21
22
23
# File 'lib/compass/installers/base.rb', line 21

def manifest_file
  @manifest_file ||= File.join(template_path, "manifest.rb")
end

#pattern_name_as_dirObject



86
87
88
# File 'lib/compass/installers/base.rb', line 86

def pattern_name_as_dir
  "#{options[:pattern_name]}/" if options[:pattern_name]
end

#prepareObject

The default prepare method – it is a no-op. Generally you would create required directories, etc.



58
59
# File 'lib/compass/installers/base.rb', line 58

def prepare
end

#run(options = {}) ⇒ Object

Runs the installer. Every installer must conform to the installation strategy of prepare, install, and then finalize. A default implementation is provided for each step.



50
51
52
53
54
# File 'lib/compass/installers/base.rb', line 50

def run(options = {})
  prepare
  install
  finalize unless options[:skip_finalization]
end


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/compass/installers/base.rb', line 140

def stylesheet_links
  html = "<head>\n"
  manifest.each_stylesheet do |stylesheet|
    # Skip partials.
    next if File.basename(stylesheet.from)[0..0] == "_"
    media = if stylesheet.options[:media]
      %Q{ media="#{stylesheet.options[:media]}"}
    end
    ss_line = %Q{  <link href="/stylesheets/#{stylesheet.to.sub(/\.sass$/,'.css')}"#{media} rel="stylesheet" type="text/css" />}
    if stylesheet.options[:condition]
      ss_line = "  <!--[if #{stylesheet.options[:condition]}]>\n    #{ss_line}\n  <![endif]-->"
    end
    html << ss_line + "\n"
  end
  html << "</head>"
end

#targetize(path) ⇒ Object

returns an absolute path given a path relative to the current installation target. Paths can use unix style “/” and will be corrected for the current platform.



130
131
132
# File 'lib/compass/installers/base.rb', line 130

def targetize(path)
  strip_trailing_separator File.join(target_path, separate(path))
end

#templatize(path) ⇒ Object

returns an absolute path given a path relative to the current template. Paths can use unix style “/” and will be corrected for the current platform.



136
137
138
# File 'lib/compass/installers/base.rb', line 136

def templatize(path)
  strip_trailing_separator File.join(template_path, separate(path))
end