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, #separate, #strip_trailing_separator, #write_file

Constructor Details

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

Returns a new instance of Base.

[View source]

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

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)
  self.logger = options[:logger]
  configure
end

Instance Attribute Details

#css_dirObject

Returns the value of attribute css_dir.


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

def css_dir
  @css_dir
end

#images_dirObject

Returns the value of attribute images_dir.


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

def images_dir
  @images_dir
end

#javascripts_dirObject

Returns the value of attribute javascripts_dir.


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

def javascripts_dir
  @javascripts_dir
end

#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

#sass_dirObject

Returns the value of attribute sass_dir.


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

def sass_dir
  @sass_dir
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, &locator) ⇒ Object

[View source]

84
85
86
87
88
89
90
91
# File 'lib/compass/installers/base.rb', line 84

def self.installer(type, &locator)
  locator ||= lambda{|to| to}
  loc_method = "install_location_for_#{type}".to_sym
  define_method loc_method, locator
  define_method "install_#{type}" do |from, to, options|
    copy templatize(from), targetize(send(loc_method, to))
  end
end

Instance Method Details

#compilation_required?Boolean

Returns:

  • (Boolean)
[View source]

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

def compilation_required?
  false
end

#configureObject

The default configure method – it sets up directories from the options and corresponding default_* methods for those not found in the options hash. It can be overridden it or augmented for reading config files, prompting the user for more information, etc.

[View source]

44
45
46
47
48
49
50
51
52
# File 'lib/compass/installers/base.rb', line 44

def configure
  unless @configured
    [:css_dir, :sass_dir, :images_dir, :javascripts_dir].each do |opt|
      configure_option_with_default opt
    end
  end
ensure
  @configured = true
end

#configure_option_with_default(opt) ⇒ Object

[View source]

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

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.

[View source]

77
78
# File 'lib/compass/installers/base.rb', line 77

def finalize
end

#initObject

Initializes the project to work with compass

[View source]

28
29
# File 'lib/compass/installers/base.rb', line 28

def init
end

#installObject

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

[View source]

69
70
71
72
73
# File 'lib/compass/installers/base.rb', line 69

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

#manifest_fileObject

[View source]

23
24
25
# File 'lib/compass/installers/base.rb', line 23

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

#prepareObject

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

[View source]

56
57
# File 'lib/compass/installers/base.rb', line 56

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.

[View source]

34
35
36
37
38
# File 'lib/compass/installers/base.rb', line 34

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

119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/compass/installers/base.rb', line 119

def stylesheet_links
  html = "<head>\n"
  manifest.each_stylesheet do |stylesheet|
    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[:ie]
      ss_line = "  <!--[if IE]>\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.

[View source]

109
110
111
# File 'lib/compass/installers/base.rb', line 109

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.

[View source]

115
116
117
# File 'lib/compass/installers/base.rb', line 115

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