# frozen_string_literal: true module Redcarpet module Form module Extension module Block # A fieldset with radion buttons # # Ex: (){value="html"} HTML (x){value="css"} CSS (){value="js"} JavaScript #
# # # #
class RadioButtons def self.pattern /\((x|\s)?\)([{][^}]*[}])?([^{})()]*)/ end def self.default_attributes { 'type' => 'radio', 'name' => '', 'value' => '' } end # rubocop:disable Metrics/MethodLength # rubocop:disable Metrics/AbcSize def self.html(matches) html = '
' name = Util.random_string matches.each_with_index do |item, index| checked = item[0] label = item[2] attrs = default_attributes.merge!(Util.parse_attributes(item[1])) attrs['name'] = name if attrs['name'].empty? attrs['value'] = "radio_#{index + 1}" if attrs['value'].empty? html += '