Class: Tres::AssetManager

Inherits:
Object
  • Object
show all
Includes:
FileMethods
Defined in:
lib/tres/asset_manager.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 = {}) ⇒ AssetManager

Returns a new instance of AssetManager.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tres/asset_manager.rb', line 12

def initialize options = {}
  @root = options[:root]
  @assets = @root/'assets'
  @logger = options[:logger]
  @sprockets = Sprockets::Environment.new Pathname(@assets) do |env|
    env.logger = @logger
    Compass.sass_engine_options[:load_paths].each do |path|
      env.append_path path.to_s
    end
    env.append_path Tres.styles_dir
    env.append_path Tres.scripts_dir
    env.append_path @assets/'javascripts'
    env.append_path @assets/'stylesheets'
    env.append_path @assets
    env.context_class.class_eval do
      def asset_path path, options = {}; path end
    end
  end
end

Instance Attribute Details

#sprocketsObject (readonly)

Returns the value of attribute sprockets.



8
9
10
# File 'lib/tres/asset_manager.rb', line 8

def sprockets
  @sprockets
end

Instance Method Details

#compile_to_build(path) ⇒ Object



32
33
34
35
# File 'lib/tres/asset_manager.rb', line 32

def compile_to_build path
  asset = @sprockets[path]
  asset.write_to(@root/'build'/path) if asset
end

#new_script(path, contents = "") ⇒ Object



37
38
39
40
41
42
# File 'lib/tres/asset_manager.rb', line 37

def new_script path, contents = ""
  mkdir_p @assets/'javascripts'/dirname(path)
  path = path + '.coffee' if extname(path).blank?
  raise Tres::ScriptExistsError if file?(@assets/'javascripts'/path)
  create_file @assets/'javascripts'/path, contents
end