Class: Mint::Renderers::Css

Inherits:
Object
  • Object
show all
Defined in:
lib/mint/renderers/css_renderer.rb

Class Method Summary collapse

Class Method Details

.process(css_content, base_dir) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mint/renderers/css_renderer.rb', line 8

def self.process(css_content, base_dir)
  css_content.gsub(/@import\s+["']([^"']+)["'];?/) do |match|
    import_path = Pathname.new $1
    
    if import_path.relative?
      full_path = import_path.expand_path base_dir
    else
      full_path = base_dir + import_path
    end
  
    if full_path.extname != '.css'
      full_path.rename(full_path.to_s + '.css') 
    end
  
    if full_path.exist?
      imported_content = full_path.read
      self.process(imported_content, full_path.dirname)
    else
      match
    end
  end
end

.render_file(css_file) ⇒ Object



4
5
6
# File 'lib/mint/renderers/css_renderer.rb', line 4

def self.render_file(css_file)
  self.process(css_file.read, css_file.dirname)
end