Class: Compass::Installers::Base
- Inherits:
-
Object
- Object
- Compass::Installers::Base
- Includes:
- Actions
- Defined in:
- lib/compass/installers/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#manifest ⇒ Object
Returns the value of attribute manifest.
-
#options ⇒ Object
Returns the value of attribute options.
-
#target_path ⇒ Object
Returns the value of attribute target_path.
-
#template_path ⇒ Object
Returns the value of attribute template_path.
-
#working_path ⇒ Object
Returns the value of attribute working_path.
Attributes included from Actions
Class Method Summary collapse
Instance Method Summary collapse
- #compilation_required? ⇒ Boolean
- #configure_option_with_default(opt) ⇒ Object
-
#finalize ⇒ Object
The default finalize method – it is a no-op.
-
#init ⇒ Object
Initializes the project to work with compass.
-
#initialize(template_path, target_path, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#install ⇒ Object
The default install method.
- #manifest_file ⇒ Object
- #pattern_name_as_dir ⇒ Object
-
#prepare ⇒ Object
The default prepare method – it is a no-op.
-
#run(options = {}) ⇒ Object
Runs the installer.
- #stylesheet_links ⇒ Object
-
#targetize(path) ⇒ Object
returns an absolute path given a path relative to the current installation target.
-
#templatize(path) ⇒ Object
returns an absolute path given a path relative to the current template.
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, = {}) @template_path = template_path @target_path = target_path @working_path = Dir.getwd @options = @manifest = Manifest.new(manifest_file) if template_path self.logger = [:logger] end |
Instance Attribute Details
#manifest ⇒ Object
Returns the value of attribute manifest.
10 11 12 |
# File 'lib/compass/installers/base.rb', line 10 def manifest @manifest end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/compass/installers/base.rb', line 9 def @options end |
#target_path ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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, | if [:like] && [:like] != type send("install_location_for_#{[:like]}", to, ) else send("simple_#{loc_method}", to) end end define_method "install_#{type}" do |from, to, | from = templatize(from) to = targetize(send(loc_method, to, )) copy from, to, nil, (installer_opts[:binary] || [:binary]) end end |
Instance Method Details
#compilation_required? ⇒ 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 = [opt] value ||= begin default_method = "default_#{opt}".to_sym send(default_method) if respond_to?(default_method) end send("#{opt}=", value) end |
#finalize ⇒ Object
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 |
#init ⇒ Object
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.)) end if manifest.has_stylesheet? dirs << sass_dir dirs << css_dir end dirs.uniq.sort.each do |dir| directory targetize(dir) end end |
#install ⇒ Object
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.) end end |
#manifest_file ⇒ Object
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_dir ⇒ Object
86 87 88 |
# File 'lib/compass/installers/base.rb', line 86 def pattern_name_as_dir "#{[:pattern_name]}/" if [:pattern_name] end |
#prepare ⇒ Object
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( = {}) prepare install finalize unless [:skip_finalization] end |
#stylesheet_links ⇒ Object
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.[:media] %Q{ media="#{stylesheet.[:media]}"} end ss_line = %Q{ <link href="/stylesheets/#{stylesheet.to.sub(/\.sass$/,'.css')}"#{media} rel="stylesheet" type="text/css" />} if stylesheet.[:condition] ss_line = " <!--[if #{stylesheet.[: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 |