Module: Jekyll::Compressor

Included in:
Page, Post, StaticFile
Defined in:
lib/jekyll-press.rb

Instance Method Summary collapse

Instance Method Details

#exclude?(dest, dest_path) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jekyll-press.rb', line 9

def exclude?(dest, dest_path)
  res = false
  file_name = dest_path.slice(dest.length+1..dest_path.length)
  exclude = @site.config['jekyll-press'] && @site.config['jekyll-press']['exclude']
  if exclude
    if exclude.is_a? String
      exclude = [exclude]
    end
    exclude.each do |e|
      if e == file_name || File.fnmatch(e, file_name)
        res = true
        break
      end
    end
  end
  res
end

#output_css(path, content) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/jekyll-press.rb', line 46

def output_css(path, content)
  output_file(path, CssPress.press(content))
rescue Racc::ParseError => e
  warn "Warning: parse error in #{path}. Don't panic - copying initial file"
  warn "Details: #{e.message.strip}"
  output_file(path, content)
end

#output_file(dest, content) ⇒ Object



27
28
29
30
31
32
# File 'lib/jekyll-press.rb', line 27

def output_file(dest, content)
  FileUtils.mkdir_p(File.dirname(dest))
  File.open(dest, 'w') do |f|
    f.write(content)
  end
end

#output_html(path, content) ⇒ Object



34
35
36
# File 'lib/jekyll-press.rb', line 34

def output_html(path, content)
  output_file(path, HtmlPress.press(content))
end

#output_js(path, content) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/jekyll-press.rb', line 38

def output_js(path, content)
  output_file(path, Uglifier.new.compile(content))
rescue Uglifier::Error => e
  warn "Warning: parse error in #{path}. Don't panic - copying initial file"
  warn "Details: #{e.message.strip}"
  output_file(path, content)
end