Class: Mint::CSSTemplate

Inherits:
Tilt::Template
  • Object
show all
Defined in:
lib/mint/css_template.rb

Instance Method Summary collapse

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



11
12
13
# File 'lib/mint/css_template.rb', line 11

def evaluate(scope, locals, &block)
  process_imports(@data, File.dirname(file))
end

#prepareObject



7
8
9
# File 'lib/mint/css_template.rb', line 7

def prepare
  @data = data
end

#process_imports(css_content, base_dir) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/mint/css_template.rb', line 15

def process_imports(css_content, base_dir)
  css_content.gsub(/@import\s+["']([^"']+)["'];?/) do |match|
    import_path = $1
    
    # If we find a relative path, resolve it
    if import_path.start_with?('../', './')
      full_path = File.expand_path(import_path, base_dir)
    else
      full_path = File.join(base_dir, import_path)
    end

    full_path += '.css' unless full_path.end_with?('.css')

    if File.exist?(full_path)
      imported_content = File.read(full_path)
      process_imports(imported_content, File.dirname(full_path))
    else
      match
    end
  end
end