Class: Zwite::StaticFiles

Inherits:
Plugin show all
Defined in:
lib/zwite/plugins/staticfiles.rb

Instance Attribute Summary

Attributes inherited from Plugin

#app, #enabled

Instance Method Summary collapse

Methods inherited from Plugin

inherited, #initialize, #preprocess, subclasses

Constructor Details

This class inherits a constructor from Zwite::Plugin

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/zwite/plugins/staticfiles.rb', line 13

def enabled?
  return (self.app.path + "source").exist?
end

#generateObject

Actions



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zwite/plugins/staticfiles.rb', line 21

def generate
  super
  src_path = self.app.path + "source"
  renderables = [".html", ".htm", ".xml"]
  
  Dir[self.app.path + "source/**/*"].each do |p|
    path = Pathname.new(p)
    if path.directory?
      next
    end
    
    rel_path = path.relative_path_from(src_path)
    output_path = self.app.output_path + rel_path
    output_dir_path = output_path.parent
    
    output_dir_path.mkpath
    
    if renderables.include?(path.extname)
      contents = self.app.render_file(path)
      output_path.open("w+") do |h|
        h.write(contents)
      end
    else
      FileUtils.copy_file(path, output_path)
    end
    
  end
  
end

#nameObject

Properties



9
10
11
# File 'lib/zwite/plugins/staticfiles.rb', line 9

def name
  return "staticfiles"
end