Module: Phlex::Rails::FragmentFinder

Extended by:
FragmentFinder
Included in:
FragmentFinder
Defined in:
lib/phlex/rails/fragment_finder.rb

Constant Summary collapse

Parser =
if defined?(Nokolexbor)
	Nokolexbor
else
	require "nokogiri"
	Nokogiri::HTML
end

Instance Method Summary collapse

Instance Method Details

#extract(html, ids) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/phlex/rails/fragment_finder.rb', line 13

def extract(html, ids)
	parsed = Parser.parse(html)
	selector = ids.map { |id| "##{id}" }.join(", ")

	result = +""

	ids.count.times do
		if (fragment = parsed.at_css(selector))
			result << fragment.to_s
			fragment.remove
		end
	end

	result
end