Class: Compass::Installers::Base
- Inherits:
-
Object
- Object
- Compass::Installers::Base
- Includes:
- Actions
- Defined in:
- lib/compass/installers/base.rb,
lib/compass/app_integration/stand_alone/installer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#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
-
#finalize(options = {}) ⇒ Object
The default finalize method – it is a no-op.
-
#initialize(template_path, target_path, options = {}) ⇒ Base
constructor
A new instance of Base.
-
#install ⇒ Object
The install method override this to install.
- #install_directory(from, to, options) ⇒ Object
- #install_html(from, to, options) ⇒ Object
- #install_html_without_haml ⇒ Object
- #install_stylesheet(from, to, options) ⇒ Object
- #pattern_name_as_dir ⇒ Object
-
#prepare ⇒ Object
The default prepare method – it is a no-op.
-
#run(run_options = {}) ⇒ Object
Runs the installer.
-
#stylesheet_links ⇒ Object
Emits an HTML fragment that can be used to link to the compiled css files.
-
#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, #copy, #directory, #log_action, #process_erb, #relativize, #remove, #separate, #strip_trailing_separator, #write_file
Constructor Details
#initialize(template_path, target_path, options = {}) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 |
# File 'lib/compass/installers/base.rb', line 11 def initialize(template_path, target_path, = {}) @template_path = template_path @target_path = target_path @working_path = Dir.getwd @options = self.logger = [:logger] end |
Instance Attribute Details
#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
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/compass/installers/base.rb', line 60 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, )) is_binary = installer_opts[:binary] || [:binary] if is_binary copy from, to, nil, is_binary else contents = File.new(from).read if .delete(:erb) ctx = TemplateContext.ctx(:to => to, :options => ) contents = process_erb(contents, ctx) end write_file to, contents end end end |
Instance Method Details
#compilation_required? ⇒ Boolean
52 53 54 |
# File 'lib/compass/installers/base.rb', line 52 def compilation_required? false end |
#finalize(options = {}) ⇒ Object
The default finalize method – it is a no-op. This could print out a message or something.
49 50 |
# File 'lib/compass/installers/base.rb', line 49 def finalize( = {}) end |
#install ⇒ Object
The install method override this to install
43 44 45 |
# File 'lib/compass/installers/base.rb', line 43 def install raise "Not Yet Implemented" end |
#install_directory(from, to, options) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/compass/installers/base.rb', line 133 def install_directory(from, to, ) d = if within = [:within] if respond_to?(within) targetize("#{send(within)}/#{to}") else raise Compass::Error, "Unrecognized location: #{within}" end else targetize(to) end directory d end |
#install_html(from, to, options) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/compass/installers/base.rb', line 147 def install_html(from, to, ) if to =~ /\.haml$/ require 'haml' to = to[0..-(".haml".length+1)] if respond_to?(:install_location_for_html) to = install_location_for_html(to, ) end contents = File.read(templatize(from)) if .delete(:erb) ctx = TemplateContext.ctx(:to => to, :options => ) contents = process_erb(contents, ctx) end Compass.configure_sass_plugin! html = Haml::Engine.new(contents, :filename => templatize(from)).render write_file(targetize(to), html, ) else install_html_without_haml(from, to, ) end end |
#install_html_without_haml ⇒ Object
146 |
# File 'lib/compass/installers/base.rb', line 146 alias install_html_without_haml install_html |
#install_stylesheet(from, to, options) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/compass/installers/base.rb', line 92 def install_stylesheet(from, to, ) from = templatize(from) to = targetize(install_location_for_stylesheet(to, )) contents = File.new(from).read if .delete(:erb) ctx = TemplateContext.ctx(:to => to, :options => ) contents = process_erb(contents, ctx) end if preferred_syntax.to_s != from[-4..-1] # logger.record :convert, basename(from) tree = Sass::Engine.new(contents, Compass..merge(:syntax => from[-4..-1].intern)).to_tree contents = tree.send("to_#{preferred_syntax}") to[-4..-1] = preferred_syntax.to_s end write_file to, contents end |
#pattern_name_as_dir ⇒ Object
56 57 58 |
# File 'lib/compass/installers/base.rb', line 56 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.
39 40 |
# File 'lib/compass/installers/base.rb', line 39 def prepare end |
#run(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.
31 32 33 34 35 |
# File 'lib/compass/installers/base.rb', line 31 def run( = {}) prepare unless [:skip_preparation] install unless [:prepare] finalize(.merge()) unless [:prepare] || [:skip_finalization] end |
#stylesheet_links ⇒ Object
Emits an HTML fragment that can be used to link to the compiled css files
180 181 182 |
# File 'lib/compass/installers/base.rb', line 180 def stylesheet_links "" 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.
169 170 171 |
# File 'lib/compass/installers/base.rb', line 169 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.
175 176 177 |
# File 'lib/compass/installers/base.rb', line 175 def templatize(path) strip_trailing_separator File.join(template_path, separate(path)) end |