Class: Redcarpet::Form::Extension::Block::RadioButtons
- Inherits:
-
Object
- Object
- Redcarpet::Form::Extension::Block::RadioButtons
- Defined in:
- lib/redcarpet/form/extension/block/radio_buttons.rb
Overview
A fieldset with radion buttons
Ex: ()value=“html” HTML (x)value=“css” CSS ()value=“js” JavaScript <fieldset>
<label><input type="radio" name="123456" value="html" /><span>HTML</span></label>
<label><input type="radio" name="123456" value="css" checked /><span>CSS</span></label>
<label><input type="radio" name="123456" value="js" /><span>JavaScript</span></label>
</fieldset>
Class Method Summary collapse
- .default_attributes ⇒ Object
-
.html(matches) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize.
- .pattern ⇒ Object
Class Method Details
.default_attributes ⇒ Object
20 21 22 |
# File 'lib/redcarpet/form/extension/block/radio_buttons.rb', line 20 def self.default_attributes { 'type' => 'radio', 'name' => '', 'value' => '' } end |
.html(matches) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/redcarpet/form/extension/block/radio_buttons.rb', line 26 def self.html(matches) html = '<fieldset>' 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 += '<label>' unless label.empty? html += "<input #{Util.attributes_to_s(attrs)}" html += ' checked' if checked == 'x' html += ' />' html += "<span>#{label}</span></label>" unless label.empty? end html += '</fieldset>' end |
.pattern ⇒ Object
16 17 18 |
# File 'lib/redcarpet/form/extension/block/radio_buttons.rb', line 16 def self.pattern /\((x|\s)?\)([{][^}]*[}])?([^{})()]*)/ end |