Class: Docks::Themes::Assets
- Inherits:
-
Object
- Object
- Docks::Themes::Assets
- Defined in:
- lib/docks_theme_base/assets.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#source_root ⇒ Object
readonly
Returns the value of attribute source_root.
Instance Method Summary collapse
- #files_for(*asset_path) ⇒ Object
-
#initialize(options) ⇒ Assets
constructor
A new instance of Assets.
- #path_for(*asset_path) ⇒ Object
- #scripts ⇒ Object
- #styles ⇒ Object
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() @root = Pathname.new(.fetch(:root)) source = .fetch(:source_root, false) @source_root = source && Pathname.new(source) end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/docks_theme_base/assets.rb', line 7 def root @root end |
#source_root ⇒ Object (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 |
#scripts ⇒ Object
35 36 37 |
# File 'lib/docks_theme_base/assets.rb', line 35 def scripts files_for("scripts/*.js") end |
#styles ⇒ Object
39 40 41 |
# File 'lib/docks_theme_base/assets.rb', line 39 def styles files_for("styles/*.css") end |