mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
These all seem to require html_safe/raw, so we'll permit it. Some of the spree code is a bit strange and could probably be improved, but I think it's ok for now.
31 lines
907 B
Ruby
31 lines
907 B
Ruby
# frozen_string_literal: true
|
|
|
|
module AngularFormHelper
|
|
def ng_options_for_select(container, _angular_field = nil)
|
|
return container if container.is_a?(String)
|
|
|
|
container.map do |element|
|
|
html_attributes = option_html_attributes(element)
|
|
text, value = option_text_and_value(element).map(&:to_s)
|
|
%(<option value="#{ERB::Util.html_escape(value)}"\
|
|
#{html_attributes}>#{ERB::Util.html_escape(text)}</option>)
|
|
end.join("\n").html_safe # rubocop:disable Rails/OutputSafety
|
|
end
|
|
|
|
def ng_options_from_collection_for_select(collection, value_method, text_method, angular_field)
|
|
options = collection.map do |element|
|
|
[element.public_send(text_method), element.public_send(value_method)]
|
|
end
|
|
|
|
ng_options_for_select(options, angular_field)
|
|
end
|
|
end
|
|
|
|
module ActionView
|
|
module Helpers
|
|
class InstanceTag
|
|
include AngularFormHelper
|
|
end
|
|
end
|
|
end
|