Class: ViewAssets::Finder::Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/view_assets/finder/finder.rb

Direct Known Subclasses

CssFinder, JsFinder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFinder

Returns a new instance of Finder.



16
17
18
# File 'lib/view_assets/finder/finder.rb', line 16

def initialize
  empty
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



15
16
17
# File 'lib/view_assets/finder/finder.rb', line 15

def action
  @action
end

#assetsObject (readonly)

Returns the value of attribute assets.



15
16
17
# File 'lib/view_assets/finder/finder.rb', line 15

def assets
  @assets
end

#controllerObject (readonly)

Returns the value of attribute controller.



15
16
17
# File 'lib/view_assets/finder/finder.rb', line 15

def controller
  @controller
end

#parsed_manifestsObject (readonly)

Returns the value of attribute parsed_manifests.



15
16
17
# File 'lib/view_assets/finder/finder.rb', line 15

def parsed_manifests
  @parsed_manifests
end

Instance Method Details

#emptyObject



20
21
22
23
24
25
# File 'lib/view_assets/finder/finder.rb', line 20

def empty
  @controller       = ''
  @action           = ''
  @assets           = []
  @parsed_manifests = []
end

#retrieve(controller = '', action = '', options = {}) ⇒ Object

This method is the ENTRY of assets finder after its initializtion. It returns all asset paths wrapped inside a appropriated html options

:controller => nil
:action => nil
:full => false
:tagged => false

TODO: need to retrive action-less assets



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/view_assets/finder/finder.rb', line 36

def retrieve(controller = '', action = '', options = {})
  # raise ":controller and :action can't be nil" if @controller.nil?

  options[:full]   ||= false
  options[:tagged] ||= false

  @assets           = []
  @parsed_manifests = []
  @controller       = controller
  @action           = action

  retrieve_controller_assets
  retrieve_action_assets if @action != ''
  @assets.uniq!

  @assets.map! { |asset| PathInfo.new(asset).abs } if options[:full]
  @assets.map! { |asset| tag("/#{asset.rel}") }    if options[:tagged]

  @assets
end