Class: Requirejs::Config

Inherits:
ActiveSupport::OrderedOptions
  • Object
show all
Defined in:
lib/requirejs/config.rb

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/requirejs/config.rb', line 3

def initialize
  super

  self.gem_root_path = Gem::Specification.find_by_name('ruby-requirejs').gem_dir
  self.runtime_location = File.join(gem_root_path, 'lib', 'requirejs', 'runtime', 'r.js')
  self.cache_location = nil
  self.js_compressor = :none # :uglify

  self.loader = :requirejs # :almond
  self.optimize = false # :almond
  self.digest = false # :almond
end

Instance Method Details

#almond?Boolean

Returns:



50
51
52
# File 'lib/requirejs/config.rb', line 50

def almond?
  self.loader == :almond
end

#cache_assets_locationObject



16
17
18
19
# File 'lib/requirejs/config.rb', line 16

def cache_assets_location
  check_cache_location
  @cache_assets_location ||= File.join(cache_location, 'assets')
end

#cache_build_scripts_locationObject



21
22
23
24
# File 'lib/requirejs/config.rb', line 21

def cache_build_scripts_location
  check_cache_location
  @cache_build_scripts_location ||= File.join(cache_location, 'build_scripts')
end

#cache_builds_locationObject



26
27
28
29
# File 'lib/requirejs/config.rb', line 26

def cache_builds_location
  check_cache_location
  @cache_builds_location ||= File.join(cache_location, 'builds')
end

#check_cache_locationObject



31
32
33
# File 'lib/requirejs/config.rb', line 31

def check_cache_location
  raise 'cache location is not set. Set cache_location. Ex.: Require.config.cache_location  = File.dirname(__FILE__)' if cache_location.blank?
end

#cleanup_cache_dirObject



46
47
48
# File 'lib/requirejs/config.rb', line 46

def cleanup_cache_dir
  FileUtils.remove_entry_secure(self.cache_location) rescue nil
end

#digest?Boolean

Returns:



58
59
60
# File 'lib/requirejs/config.rb', line 58

def digest?
  self.digest
end

#ensure_cache_location_existsObject



40
41
42
43
44
# File 'lib/requirejs/config.rb', line 40

def ensure_cache_location_exists
  [cache_location, cache_assets_location, cache_build_scripts_location, cache_builds_location].each do |path|
    Pathname.new(path).mkpath
  end
end

#optimize?Boolean

Returns:



54
55
56
# File 'lib/requirejs/config.rb', line 54

def optimize?
  almond? || self.optimize
end

#setup_directoriesObject



35
36
37
38
# File 'lib/requirejs/config.rb', line 35

def setup_directories
  cleanup_cache_dir
  ensure_cache_location_exists
end