Module: AssetPackager

Defined in:
lib/rails_ext/asset_packager/asset_packager.rb

Class Method Summary collapse

Class Method Details

.add(yaml_file_path, asset_path) ⇒ Object



3
4
5
6
7
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 3

def add yaml_file_path, asset_path
  definition = YAML.load File.read(yaml_file_path)
  definition.should! :be_a, Hash
  self.definitions[asset_path] = definition
end

.build_allObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 9

def build_all
  definitions.each do |path, package_types|
    package_types.each do |type, package|
      package.each do |name, files|
        build = self.send "build_#{type}", path, name, files
        dir = "#{public_root}/#{type}"
        FileUtils.mkdir_p dir unless File.exist? dir
        fname = public_root + filename_for_builded_package(type, name)
        File.open(fname, "w"){|f| f.write(build)}
      end
    end
  end
end

.definitionsObject



39
40
41
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 39

def definitions
  @definitions ||= {}
end

.delete_allObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 23

def delete_all
  definitions.each do |path, package_types|
    package_types.each do |type, package|
      package.each do |name, files|
        fname = public_root + filename_for_builded_package(type, name)
        File.delete fname if File.exist? fname
      end
    end
  end
end

.filename_for_builded_package(type, package) ⇒ Object



34
35
36
37
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 34

def filename_for_builded_package type, package
  type = type.to_s
  "/#{type}/#{package}_packaged.#{AssetPackager.resources_extensions[type]}"
end

.merge_environmentsObject



43
44
45
# File 'lib/rails_ext/asset_packager/asset_packager.rb', line 43

def merge_environments
  @merge_environments ||= ["production"]
end