class Noraneko::ViewProcessor
Public Class Methods
new(registry:, filepath:)
click to toggle source
# File lib/noraneko/view_processor.rb, line 3 def initialize(registry:, filepath:) @registry = registry @filepath = filepath @nview = Noraneko::NView.new(@filepath, :partial) registry.put(@nview) end
Public Instance Methods
process(text)
click to toggle source
# File lib/noraneko/view_processor.rb, line 10 def process(text) text.each_line do |line| process_line(line) end end
Private Instance Methods
has_render?(line)
click to toggle source
# File lib/noraneko/view_processor.rb, line 18 def has_render?(line) line.match?(/render[\s(]/) end
process_line(line)
click to toggle source
# File lib/noraneko/view_processor.rb, line 22 def process_line(line) return unless has_render?(line) matched = line.match(/\srender[\s(]+(['"])(.+)(\1)/) if !matched matched = line.match(/[\s(]partial.+(['"])(.+)(\1)/) end return unless matched name = if matched[2].split('/').size == 1 rel_path_from_view + '/_' + matched[2] else *prefix, name = matched[2].split('/') prefix.join('/') + '/_' + name end @nview.call_view(name) end
rel_path_from_view()
click to toggle source
# File lib/noraneko/view_processor.rb, line 41 def rel_path_from_view @nview.filepath .split('/views/').drop(1).join('') .split('/')[0..-2].join('') end