Class: Capucine::CompassSass
- Inherits:
-
Object
- Object
- Capucine::CompassSass
- Defined in:
- lib/compass-sass.rb
Instance Attribute Summary collapse
-
#tmp_config ⇒ Object
Returns the value of attribute tmp_config.
Instance Method Summary collapse
- #exec_compass(compass_args, system = true) ⇒ Object
- #import_css ⇒ Object
-
#initialize(capucine) ⇒ CompassSass
constructor
A new instance of CompassSass.
- #run_once ⇒ Object
- #run_watch ⇒ Object
- #update_config ⇒ Object
- #update_plugins(gems) ⇒ Object
Constructor Details
#initialize(capucine) ⇒ CompassSass
Returns a new instance of CompassSass.
5 6 7 |
# File 'lib/compass-sass.rb', line 5 def initialize(capucine) @cap = capucine end |
Instance Attribute Details
#tmp_config ⇒ Object
Returns the value of attribute tmp_config.
3 4 5 |
# File 'lib/compass-sass.rb', line 3 def tmp_config @tmp_config end |
Instance Method Details
#exec_compass(compass_args, system = true) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/compass-sass.rb', line 100 def exec_compass compass_args, system = true if not system require 'compass' require 'compass/exec' return Compass::Exec::SubCommandUI.new(compass_args).run! else return system("compass #{compass_args}") end end |
#import_css ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/compass-sass.rb', line 82 def import_css import_dir = File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_css_dir'] output_dir= File.join @cap.settings.working_dir, @cap.settings.conf['sass_import_output_dir'] Dir.mkdir(import_dir) if not File.directory?(import_dir) Dir.mkdir(output_dir) if not File.directory?(output_dir) formats = @cap.settings.conf['sass_import_formats'].split from_format = formats[0] to_format = formats[2] command = "sass-convert -R --from #{from_format} --to #{to_format} \"#{import_dir}\" \"#{output_dir}\"" system(command) @cap.tools.archive_file import_dir end |
#run_once ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/compass-sass.rb', line 9 def run_once self.update_config self.import_css if @cap.settings.conf['sass_import_css'] command = "compile --quiet --config \"#{@tmp_config}\" \"#{@cap.settings.working_dir}\"" self.exec_compass(command) puts "[compass] - Compiled" end |
#run_watch ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/compass-sass.rb', line 110 def run_watch conf = self.update_config working_dir = @cap.settings.working_dir self.import_css if @cap.settings.conf['sass_import_css'] compass_args = ['watch', '--config', conf, working_dir] compass_args = compass_args.join(' ') proc_watch = Thread.new { self.exec_compass compass_args } return proc_watch end |
#update_config ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 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 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/compass-sass.rb', line 29 def update_config template_file = File.join @cap.settings.content_dir, 'templates', 'compass_config.erb' tmp = File.join @cap.settings.working_dir, '.compass_config.rb' FileUtils.rm tmp if File.exist?(tmp) @tmp_config = tmp @cap.settings.conf['compass_custom'] = {} boolean = %w{disable_warnings line_comments relative_assets sass_options} symbol = %w{output_style} for k, v in @cap.settings.conf['compass'] if boolean.include?(k) v = "#{v}" elsif symbol.include?(k) v = ":#{v}" else v = "\"#{v}\"" end @cap.settings.conf['compass_custom'][k] = v end @cap.settings.conf['compass_plugins_list'] = [] plugins_gems = [] plugins = @cap.settings.conf['compass_plugins'] if plugins.size > 0 plugins.each do |p| p = p.split('|') @cap.settings.conf['compass_plugins_list'].push p[0] if p[1] plugins_gems.push p[1] else plugins_gems.push p[0] end end end result = @cap.tools.render_template template_file, @cap.settings.conf f = File.open(@tmp_config, 'w') f.write(result) f.close self.update_plugins plugins_gems return @tmp_config end |
#update_plugins(gems) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/compass-sass.rb', line 18 def update_plugins gems return if not gems gems.each do |plugin| begin require "#{plugin}" rescue LoadError system("gem install #{plugin} --no-ri --no-rdoc") end end end |