Class: SlimGruntHelpers::Models::Usemin

Inherits:
Object
  • Object
show all
Defined in:
lib/slim-grunt-helpers/models/usemin.rb

Direct Known Subclasses

UseminCss, UseminJs

Constant Summary collapse

BASE_OPTIONS =
{}.freeze

Instance Method Summary collapse

Constructor Details

#initializeUsemin

Returns a new instance of Usemin.



11
12
13
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 11

def initialize
  @links = []
end

Instance Method Details

#<<(path, options = {}) ⇒ Object Also known as: add, include



15
16
17
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 15

def <<(path, options={})
  @links << { path: path.to_s, options: base_options.merge(options) }
end

#base_optionsObject



29
30
31
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 29

def base_options
  BASE_OPTIONS
end

#each(options = {}) ⇒ Object



25
26
27
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 25

def each(options={})
  @links.each { |link| yield(transform_link(link, options)) }
end

#require(path, options = {}) ⇒ Object



21
22
23
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 21

def require(path, options={})
  self.include(path, options) unless file_already_included? path
end

#require_tree(root_path, pattern, options = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/slim-grunt-helpers/models/usemin.rb', line 33

def require_tree(root_path, pattern, options={})
  unless root_path.respond_to? :join
    root_path = Pathname.new(root_path.to_s)
  end
  
  Dir[root_path.join(pattern).to_s].reject do |file|
    File.directory? file
  end.each do |file|
    file_name      = file.to_s
    real_root_path = "#{ root_path }/"
    file_name[real_root_path] = ''
    
    self.require file_name, options
  end
end