Class: Benoit::Utils::FindsLayoutsForTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/benoit/utils/finds_layouts_for_template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options) ⇒ FindsLayoutsForTemplate

Returns a new instance of FindsLayoutsForTemplate.



25
26
27
28
29
30
31
32
33
34
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 25

def initialize(input, options)
  if input.respond_to? :path
    @input = input
    @template_path = input
  else
    @content = input
  end
  @load_paths = options.delete(:load_paths) || [""]
  @root = options.delete(:root)
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



19
20
21
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 19

def input
  @input
end

#load_pathsObject (readonly)

Returns the value of attribute load_paths.



19
20
21
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 19

def load_paths
  @load_paths
end

#rootObject (readonly)

Returns the value of attribute root.



19
20
21
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 19

def root
  @root
end

#template_pathObject (readonly)

Returns the value of attribute template_path.



19
20
21
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 19

def template_path
  @template_path
end

Class Method Details

.first_layout(content, options = {}) ⇒ Object



21
22
23
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 21

def self.first_layout(content, options={})
  FindsLayoutsForTemplate.new(content, options).lookup_layout
end

Instance Method Details

#lookup_layoutObject



43
44
45
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 43

def lookup_layout
  match_extends_line(@content)
end

#lookup_layoutsObject



47
48
49
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 47

def lookup_layouts
    recursively_lookup_layouts_for_file(input)
end

#match_extends_line(content) ⇒ Object



36
37
38
39
40
41
# File 'lib/benoit/utils/finds_layouts_for_template.rb', line 36

def match_extends_line(content)
  extends_pattern = /\{% extends "([\.\w-]+)" %\}/
  match_data = content.match(extends_pattern)
  return unless match_data
  match_data.captures[0]
end