Class: Docks::Themes::Assets

Inherits:
Object
  • Object
show all
Defined in:
lib/docks_theme_base/assets.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Assets

Returns a new instance of Assets.



9
10
11
12
13
14
# File 'lib/docks_theme_base/assets.rb', line 9

def initialize(options)
  @root = Pathname.new(options.fetch(:root))

  source = options.fetch(:source_root, false)
  @source_root = source && Pathname.new(source)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



7
8
9
# File 'lib/docks_theme_base/assets.rb', line 7

def root
  @root
end

#source_rootObject (readonly)

Returns the value of attribute source_root.



7
8
9
# File 'lib/docks_theme_base/assets.rb', line 7

def source_root
  @source_root
end

Instance Method Details

#files_for(*asset_path) ⇒ Object



31
32
33
# File 'lib/docks_theme_base/assets.rb', line 31

def files_for(*asset_path)
  Dir[root + File.join(asset_path)]
end

#path_for(*asset_path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/docks_theme_base/assets.rb', line 16

def path_for(*asset_path)
  asset_path = File.join(*asset_path)
  path = root + asset_path
  source_path = source_root && source_root + asset_path

  if path.exist?
    path
  elsif source_path && source_path.exist?
    source_path
  else
    fail Docks::NoAssetError,
         "No asset matching '#{asset_path}' was found in the asset folders."
  end
end

#scriptsObject



35
36
37
# File 'lib/docks_theme_base/assets.rb', line 35

def scripts
  files_for("scripts/*.js")
end

#stylesObject



39
40
41
# File 'lib/docks_theme_base/assets.rb', line 39

def styles
  files_for("styles/*.css")
end