Sha256: 9bbfe1c0c29113fc9c9bd088f74321c33ccf379802a7d650eeeea7ce4476680a

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

# Add a text-field, either specifying everything manually or using a model object on the form
#
# == Basic usage:
#    {%assign airports = "Eindhoven, Schiphol" | split: ', '%}
#    {%options_for_select airports%}
#
# == Advanced usage:
#    {%assign airports = "Eindhoven, Schiphol" | split: ', '%}
#    {%options_for_select airports selected:"Schiphol" disabled:"Eindhoven"%}
#
# == Advanced usage:
#    {%options_for_select airports name value selected:"Schiphol" disabled:"Eindhoven"%}
#
# This last usage requires a model on the form
#
class OptionsForSelectTag < LiquidumTag
  def render(context)
    super

    options = argv1.map(&:to_liquid)

    if sargs.present?
      options = options.map do |option|
        result = sargs.map { |a| option[a.to_s] }
        result = result.first if result.length == 1
        result
      end
    end

    context.registers['controller'].helpers.options_for_select(options, attr_args).to_s
  end
end

Liquid::Template.register_tag('options_for_select', OptionsForSelectTag)

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scribo-1.0.44 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.43 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.42 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.41 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.40 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.39 lib/scribo/liquid/tags/options_for_select.rb
scribo-1.0.38 lib/scribo/liquid/tags/options_for_select.rb