Class: ActionPage::TemplateHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/action_page/template_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, source) ⇒ TemplateHandler

Returns a new instance of TemplateHandler.



7
8
9
10
# File 'lib/action_page/template_handler.rb', line 7

def initialize(template, source)
  @template = template
  @source = source
end

Class Method Details

.call(template, source) ⇒ Object



3
4
5
# File 'lib/action_page/template_handler.rb', line 3

def self.call(template, source)
  new(template, source).call
end

Instance Method Details

#callObject



12
13
14
# File 'lib/action_page/template_handler.rb', line 12

def call
  handler_for_template.call(@template, source_without_yaml)
end

#handler_for_templateObject



16
17
18
19
20
# File 'lib/action_page/template_handler.rb', line 16

def handler_for_template
  ApplicationController.new.view_paths.paths.first
    .extract_handler_and_format_and_variant(path_without_yaml)
    .first
end

#last_lineObject



30
31
32
# File 'lib/action_page/template_handler.rb', line 30

def last_line
  YAML.parse(@source).root.end_line
end

#path_without_yamlObject



26
27
28
# File 'lib/action_page/template_handler.rb', line 26

def path_without_yaml
  @template.short_identifier.sub(/.ya?ml\z/, '')
end

#source_without_yamlObject



22
23
24
# File 'lib/action_page/template_handler.rb', line 22

def source_without_yaml
  @source.lines[last_line+1...].join
end