Class: Tres::Packager

Inherits:
Object
  • Object
show all
Includes:
FileMethods
Defined in:
lib/tres/packager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileMethods

#append_to_file, #basename, #change_dir, #copy, #create_file, #delete!, #dir?, #dirname, #erb, #expand, #extname, #file?, #json, #mkdir_p, #move, #name_and_extension, #new_dir, #new_file, #read_file, #readlines, #relativize

Constructor Details

#initialize(options = {}) ⇒ Packager

Returns a new instance of Packager.



9
10
11
12
# File 'lib/tres/packager.rb', line 9

def initialize options = {}
  @root = options[:root]
  @asset_manager = options[:asset_manager]
end

Instance Attribute Details

#asset_managerObject

Returns the value of attribute asset_manager.



7
8
9
# File 'lib/tres/packager.rb', line 7

def asset_manager
  @asset_manager
end

#rootObject

Returns the value of attribute root.



7
8
9
# File 'lib/tres/packager.rb', line 7

def root
  @root
end

Instance Method Details

#write(path) ⇒ Object



14
15
16
# File 'lib/tres/packager.rb', line 14

def write path
  @asset_manager.compile_to_build path
end

#write_allObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tres/packager.rb', line 18

def write_all
  index = Nokogiri::HTML(read_file(@root/'build'/'index.html'))
  scripts = index.css('script[src]')
  scripts.each do |script|
    write relativize(script['src'], '.')
  end
  styles = index.css('link[rel="stylesheet"][href]')
  styles.each do |style|
    write relativize(style['href'], '.') rescue nil
  end
end